Browse Source

* Added detection of gdb-version to fpmake

git-svn-id: trunk@18095 -
joost 14 years ago
parent
commit
8c03cf38c7
1 changed files with 122 additions and 5 deletions
  1. 122 5
      packages/gdbint/fpmake.pp

+ 122 - 5
packages/gdbint/fpmake.pp

@@ -2,7 +2,118 @@
 {$mode objfpc}{$H+}
 {$mode objfpc}{$H+}
 program fpmake;
 program fpmake;
 
 
-uses fpmkunit;
+uses fpmkunit, classes, sysutils;
+
+{$endif ALLPACKAGES}
+
+const
+  GdbLibName = 'libgdb.a';
+  MinGWGdbLibName = 'libmingw32.a';
+
+procedure BeforeCompile_gdbint(Sender: TObject);
+var
+  L : TStrings;
+  P : TPackage;
+  GdbLibDir, GdbLibFile: string;
+  GdbLibFound: boolean;
+  GdbVerTarget: TTarget;
+  HostOS: TOS;
+  HostCPU: TCpu;
+begin
+  P := Sender as TPackage;
+  HostOS:=StringToOS({$I %FPCTARGETOS%});
+  HostCPU:=StringToCPU({$I %FPCTARGETCPU%});
+  // Search for a libgdb file.
+  GdbLibFound:=false;
+
+  // First try the environment setting GDBLIBDIR
+  GdbLibDir := GetEnvironmentVariable('GDBLIBDIR');
+  if (GdbLibDir<>'') and DirectoryExists(GdbLibDir) then
+    begin
+      GdbLibFile:=IncludeTrailingPathDelimiter(GdbLibDir)+GdbLibName;
+      if not FileExists(GdbLibFile) then
+        Installer.BuildEngine.Log(vlCommand,'GDBLIBDIR environment variable set, but libgdb not found. ('+GdbLibFile+')')
+      else
+        GdbLibFound:=true;
+    end;
+
+  // Try the default locations
+  if not GdbLibFound then
+    begin
+      GdbLibDir:='..'+PathDelim+'..'+PathDelim+'libgdb';
+      if DirectoryExists(GdbLibDir) then
+        begin
+          GdbLibDir:=GdbLibDir+PathDelim+OSToString(Defaults.OS);
+          GdbLibFile:=GdbLibDir+PathDelim+GdbLibName;
+          if FileExists(GdbLibFile) then
+            GdbLibFound:=true
+          else
+            begin
+              GdbLibDir:=GdbLibDir+PathDelim+CPUToString(Defaults.CPU);
+              GdbLibFile:=GdbLibDir+PathDelim+GdbLibName;
+              GdbLibFound:=FileExists(GdbLibFile);
+            end;
+        end;
+    end;
+
+  // When we're cross-compiling, running the gdbver executable to detect the
+  // gdb-version is not possible, unless a i386-win32 to i386-go32v2 compilation
+  // is performed.
+  if GdbLibFound and
+     (((Defaults.CPU=HostCPU) and (Defaults.OS=HostOS))
+       or ((Defaults.CPU=i386) and (Defaults.OS=go32v2) and (HostOS=win32) and (HostCPU=i386))) then
+    begin
+      P.Options.Add('-Fl'+GdbLibDir);
+      GdbVerTarget:=p.Targets.AddUnit('src'+PathDelim+'gdbver.pp');
+      Installer.BuildEngine.ResolveFileNames(p,HostCPU,HostOS,false);
+      Installer.BuildEngine.Log(vlCommand,'GDB-lib found, compiling and running gdbver to obtain GDB-version');
+      Installer.BuildEngine.Compile(P,GdbVerTarget);
+      p.Targets.Delete(GdbVerTarget.Index);
+      Installer.BuildEngine.ExecuteCommand('src/gdbver','-o src/gdbver.inc');
+
+      // Pass -dUSE_MINGW_GDB to the compiler when a MinGW gdb is used
+      if FileExists(GdbLibDir+PathDelim+MinGWGdbLibName) then
+        begin
+          P.Options.Add('-dUSE_MINGW_GDB');
+          Installer.BuildEngine.Log(vlCommand,'Using GDB (MinGW)')
+        end
+      else
+        begin
+          Installer.BuildEngine.Log(vlCommand,'Using GDB')
+        end;
+    end
+  else
+    begin
+      // No suitable gdb found, use gdb_nogdb.inc
+      L := TStringList.Create;
+      try
+        if P.Directory<>'' then
+          L.values['src'+DirectorySeparator+'gdbver_nogdb.inc'] := IncludeTrailingPathDelimiter(P.Directory) +'src'+DirectorySeparator+'gdbver.inc'
+        else
+          L.values['src'+DirectorySeparator+'gdbver_nogdb.inc'] := 'src'+DirectorySeparator+'gdbver.inc';
+        Installer.BuildEngine.cmdcopyfiles(L, Installer.BuildEngine.StartDir);
+      finally
+        L.Free;
+      end;
+
+    end;
+end;
+
+procedure AfterCompile_gdbint(Sender: TObject);
+var
+  L : TStrings;
+begin
+  // Remove the generated gdbver.inc
+  L := TStringList.Create;
+  try
+    L.add(IncludeTrailingPathDelimiter(Installer.BuildEngine.StartDir)+'src/gdbver.inc');
+    Installer.BuildEngine.CmdDeleteFiles(L);
+  finally
+    L.Free;
+  end;
+end;
+
+procedure add_gdbint;
 
 
 Var
 Var
   P : TPackage;
   P : TPackage;
@@ -10,8 +121,6 @@ Var
 begin
 begin
   With Installer do
   With Installer do
     begin
     begin
-{$endif ALLPACKAGES}
-
     P:=AddPackage('gdbint');
     P:=AddPackage('gdbint');
 {$ifdef ALLPACKAGES}
 {$ifdef ALLPACKAGES}
     P.Directory:='gdbint';
     P.Directory:='gdbint';
@@ -26,6 +135,10 @@ begin
 
 
     P.SourcePath.Add('src');
     P.SourcePath.Add('src');
     P.IncludePath.Add('src');
     P.IncludePath.Add('src');
+
+    P.BeforeCompileProc:=@BeforeCompile_gdbint;
+    P.AfterCompileProc:=@AfterCompile_gdbint;
+
     //
     //
     // NOTE: the gdbver.inc dependancies gives warnings because the makefile.fpc
     // NOTE: the gdbver.inc dependancies gives warnings because the makefile.fpc
     // does a "cp src/gdbver_nogdb.inc src/gdbver.inc" to create it
     // does a "cp src/gdbver_nogdb.inc src/gdbver.inc" to create it
@@ -40,9 +153,13 @@ begin
         begin
         begin
           AddInclude('gdbver.inc');
           AddInclude('gdbver.inc');
         end;
         end;
+    end;
+end;
 
 
 {$ifndef ALLPACKAGES}
 {$ifndef ALLPACKAGES}
-    Run;
-    end;
+begin
+  add_gdbint;
+  Installer.Run;
 end.
 end.
 {$endif ALLPACKAGES}
 {$endif ALLPACKAGES}
+