fpmake.pp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. {$ifndef ALLPACKAGES}
  2. {$mode objfpc}{$H+}
  3. program fpmake;
  4. uses fpmkunit, classes, sysutils;
  5. {$endif ALLPACKAGES}
  6. const
  7. GdbLibName = 'libgdb.a';
  8. MinGWGdbLibName = 'libmingw32.a';
  9. procedure BeforeCompile_gdbint(Sender: TObject);
  10. var
  11. L : TStrings;
  12. P : TPackage;
  13. GdbLibDir, GdbLibFile: string;
  14. GdbLibFound: boolean;
  15. GdbVerTarget: TTarget;
  16. begin
  17. P := Sender as TPackage;
  18. // Search for a libgdb file.
  19. GdbLibFound:=false;
  20. // First try the environment setting GDBLIBDIR
  21. GdbLibDir := GetEnvironmentVariable('GDBLIBDIR');
  22. if (GdbLibDir<>'') and DirectoryExists(GdbLibDir) then
  23. begin
  24. GdbLibFile:=IncludeTrailingPathDelimiter(GdbLibDir)+GdbLibName;
  25. if not FileExists(GdbLibFile) then
  26. Installer.BuildEngine.Log(vlCommand,'GDBLIBDIR environment variable set, but libgdb not found. ('+GdbLibFile+')')
  27. else
  28. GdbLibFound:=true;
  29. end;
  30. // Try the default locations
  31. if not GdbLibFound then
  32. begin
  33. GdbLibDir:=Installer.BuildEngine.AddPathPrefix(p,'..'+PathDelim+'..'+PathDelim+'libgdb');
  34. if DirectoryExists(GdbLibDir) then
  35. begin
  36. GdbLibDir:=GdbLibDir+PathDelim+OSToString(Defaults.OS);
  37. GdbLibFile:=GdbLibDir+PathDelim+GdbLibName;
  38. if FileExists(GdbLibFile) then
  39. GdbLibFound:=true
  40. else
  41. begin
  42. GdbLibDir:=GdbLibDir+PathDelim+CPUToString(Defaults.CPU);
  43. GdbLibFile:=GdbLibDir+PathDelim+GdbLibName;
  44. GdbLibFound:=FileExists(GdbLibFile);
  45. end;
  46. end;
  47. end;
  48. GdbVerTarget:=TTarget(p.Targets.ItemByName('gdbver'));
  49. // When we're cross-compiling, running the gdbver executable to detect the
  50. // gdb-version is not possible, unless a i386-win32 to i386-go32v2 compilation
  51. // is performed.
  52. if GdbLibFound and
  53. (not Defaults.IsBuildDifferentFromTarget
  54. or ((Defaults.CPU=i386) and (Defaults.OS=go32v2) and (Defaults.BuildOS=win32) and (Defaults.BuildCPU=i386))) then
  55. begin
  56. P.Options.Add('-Fl'+GdbLibDir);
  57. Installer.BuildEngine.CreateOutputDir(p);
  58. Installer.BuildEngine.Log(vlCommand,'GDB-lib found, compiling and running gdbver to obtain GDB-version');
  59. Installer.BuildEngine.Compile(P,GdbVerTarget);
  60. Installer.BuildEngine.ExecuteCommand(Installer.BuildEngine.AddPathPrefix(p,p.
  61. GetBinOutputDir(Defaults.CPU, Defaults.OS))+PathDelim+
  62. AddProgramExtension('gdbver',Defaults.BuildOS),'-o ' +
  63. Installer.BuildEngine.AddPathPrefix(p,'src'+PathDelim+'gdbver.inc'));
  64. // Pass -dUSE_MINGW_GDB to the compiler when a MinGW gdb is used
  65. if FileExists(GdbLibDir+PathDelim+MinGWGdbLibName) then
  66. begin
  67. P.Options.Add('-dUSE_MINGW_GDB');
  68. Installer.BuildEngine.Log(vlCommand,'Using GDB (MinGW)')
  69. end
  70. else
  71. begin
  72. Installer.BuildEngine.Log(vlCommand,'Using GDB')
  73. end;
  74. // Detect if gdblib.inc is available
  75. if FileExists(GDBLibDir+PathDelim+'gdblib.inc') then
  76. begin
  77. P.Options.Add('-dUSE_GDBLIBINC');
  78. P.Options.Add('-Fi'+GdbLibDir);
  79. Installer.BuildEngine.Log(vlCommand,'Using gdblib.inc include file')
  80. end;
  81. end
  82. else
  83. begin
  84. // No suitable gdb found
  85. // No need to compile gdbver.
  86. p.Targets.Delete(GdbVerTarget.Index);
  87. // use gdb_nogdb.inc
  88. L := TStringList.Create;
  89. try
  90. if P.Directory<>'' then
  91. L.values[Installer.BuildEngine.AddPathPrefix(P,'src')+DirectorySeparator+'gdbver_nogdb.inc'] := IncludeTrailingPathDelimiter(P.Directory) +'src'+DirectorySeparator+'gdbver.inc'
  92. else
  93. L.values[Installer.BuildEngine.AddPathPrefix(P,'src')+DirectorySeparator+'gdbver_nogdb.inc'] := 'src'+DirectorySeparator+'gdbver.inc';
  94. Installer.BuildEngine.cmdcopyfiles(L, Installer.BuildEngine.StartDir);
  95. finally
  96. L.Free;
  97. end;
  98. end;
  99. end;
  100. procedure AfterCompile_gdbint(Sender: TObject);
  101. var
  102. L : TStrings;
  103. begin
  104. // Remove the generated gdbver.inc
  105. L := TStringList.Create;
  106. try
  107. L.add(IncludeTrailingPathDelimiter(Installer.BuildEngine.StartDir)+'src/gdbver.inc');
  108. Installer.BuildEngine.CmdDeleteFiles(L);
  109. finally
  110. L.Free;
  111. end;
  112. end;
  113. procedure add_gdbint;
  114. Var
  115. P : TPackage;
  116. T : TTarget;
  117. begin
  118. With Installer do
  119. begin
  120. P:=AddPackage('gdbint');
  121. {$ifdef ALLPACKAGES}
  122. P.Directory:='gdbint';
  123. {$endif ALLPACKAGES}
  124. P.Version:='2.7.1';
  125. P.Author := 'Library : Cygnus, header: Peter Vreman';
  126. P.License := 'Library: GPL2 or later, header: LGPL with modification, ';
  127. P.HomepageURL := 'www.freepascal.org';
  128. P.Email := '';
  129. P.Description := 'Interface to libgdb, the GDB debugger in library format';
  130. P.NeedLibC:= true; // true for headers that indirectly link to libc?
  131. // In case of using a buildunit, it is not possible to compile a single
  132. // file within the BeforeCompile event.
  133. P.SupportBuildModes:= [bmOneByOne];
  134. P.OSes:=[beos,haiku,freebsd,netbsd,openbsd,linux,win32,win64,go32v2];
  135. P.SourcePath.Add('src');
  136. P.IncludePath.Add('src');
  137. P.BeforeCompileProc:=@BeforeCompile_gdbint;
  138. P.AfterCompileProc:=@AfterCompile_gdbint;
  139. p.Targets.AddProgram('src'+PathDelim+'gdbver.pp');
  140. //
  141. // NOTE: the gdbver.inc dependancies gives warnings because the makefile.fpc
  142. // does a "cp src/gdbver_nogdb.inc src/gdbver.inc" to create it
  143. T:=P.Targets.AddUnit('gdbcon.pp');
  144. with T.Dependencies do
  145. begin
  146. AddUnit('gdbint');
  147. end;
  148. T:=P.Targets.AddUnit('gdbint.pp');
  149. with T.Dependencies do
  150. begin
  151. AddInclude('gdbver.inc');
  152. end;
  153. end;
  154. end;
  155. {$ifndef ALLPACKAGES}
  156. begin
  157. add_gdbint;
  158. Installer.Run;
  159. end.
  160. {$endif ALLPACKAGES}