fpmake.pp 5.7 KB

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