fpmake.pp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. {$ifndef ALLPACKAGES}
  2. {$mode objfpc}{$H+}
  3. program fpmake;
  4. uses
  5. fpmkunit,
  6. sysutils;
  7. {$endif ALLPACKAGES}
  8. const
  9. NoGDBOption: boolean = false;
  10. GDBMIOption: boolean = false;
  11. procedure ide_check_gdb_availability(Sender: TObject);
  12. function DetectLibGDBDir: string;
  13. var
  14. SearchPath: string;
  15. const
  16. LibGDBName = 'libgdb.a';
  17. begin
  18. result:='';
  19. // First look for the GDBLIBDIR environment variable
  20. SearchPath := GetEnvironmentVariable('GDBLIBDIR');
  21. if (SearchPath<>'') and DirectoryExists(SearchPath) and FileExists(IncludeTrailingPathDelimiter(SearchPath)+LibGDBName) then
  22. begin
  23. result:=IncludeTrailingPathDelimiter(SearchPath);
  24. exit;
  25. end;
  26. // Search in the default locations
  27. SearchPath := '..'+PathDelim+'libgdb'+PathDelim+OSToString(Defaults.OS)+PathDelim+CPUToString(Defaults.CPU)+PathDelim;
  28. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  29. begin
  30. result := SearchPath;
  31. exit;
  32. end;
  33. SearchPath := '..'+PathDelim+'libgdb'+PathDelim+OSToString(Defaults.OS)+PathDelim;
  34. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  35. begin
  36. result := SearchPath;
  37. exit;
  38. end;
  39. // No custom libgdb.a found, try using system default library if available
  40. SearchPath := '..'+PathDelim+'lib'+PathDelim;
  41. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  42. begin
  43. result := SearchPath;
  44. installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
  45. exit;
  46. end;
  47. SearchPath := '..'+PathDelim+'usr'+PathDelim+'lib'+PathDelim;
  48. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  49. begin
  50. result := SearchPath;
  51. installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
  52. exit;
  53. end;
  54. SearchPath := '..'+PathDelim+'usr'+PathDelim+'local'+PathDelim+'lib'+PathDelim;
  55. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  56. begin
  57. result := SearchPath;
  58. installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
  59. exit;
  60. end;
  61. end;
  62. var
  63. s: string;
  64. GDBLibDir: string;
  65. P: TPackage;
  66. begin
  67. P := sender as TPackage;
  68. with installer do
  69. begin
  70. if GDBMIOption then
  71. begin
  72. BuildEngine.log(vlCommand, 'Compiling IDE with GDB/MI debugger support, LibGDB is not needed');
  73. P.Options.Add('-dGDBMI');
  74. end
  75. else if not (NoGDBOption) then
  76. begin
  77. // Detection of GDB.
  78. GDBLibDir := DetectLibGDBDir;
  79. if GDBLibDir<>'' then
  80. begin
  81. // Include GDB
  82. BuildEngine.log(vlCommand, 'LibGDB was found, build IDE with debugger support');
  83. if FileExists(GDBLibDir+'gdblib.inc') then
  84. begin
  85. P.Options.Add('-dUSE_GDBLIBINC');
  86. P.Options.Add('-I'+GDBLibDir);
  87. end;
  88. P.Options.Add('-Fl'+GDBLibDir);
  89. case Defaults.OS of
  90. win32,
  91. win64 : begin
  92. P.Options.Add('-Xe');
  93. P.Options.Add('-k--allow-multiple-definition');
  94. end;
  95. freebsd : begin
  96. P.Options.Add('-Fl/usr/local/lib');
  97. P.Options.Add('-Xd');
  98. end;
  99. openbsd : begin
  100. P.Options.Add('-Fl/usr/local/lib');
  101. P.Options.Add('-Fl/usr/lib');
  102. P.Options.Add('-Xd');
  103. end;
  104. netbsd : P.Options.Add('-Xd');
  105. linux : P.Options.Add('-Xd');
  106. aix : begin
  107. P.Options.Add('-Xd');
  108. P.Options.Add('-Fl/opt/freeware/lib');
  109. P.Options.Add('-k-bbigtoc');
  110. end;
  111. end; {case}
  112. P.NeedLibc := true;
  113. end
  114. else
  115. begin
  116. BuildEngine.log(vlCommand, 'LibGDB was not found, IDE has no debugger support');
  117. P.Options.Add('-dNODEBUG');
  118. end;
  119. end
  120. else
  121. begin
  122. BuildEngine.log(vlCommand, 'Debugger support disabled');
  123. P.Options.Add('-dNODEBUG');
  124. end;
  125. end;
  126. end;
  127. procedure add_ide(const ADirectory: string);
  128. Var
  129. P : TPackage;
  130. T : TTarget;
  131. CompilerTarget : TCpu;
  132. s: string;
  133. begin
  134. AddCustomFpmakeCommandlineOption('CompilerTarget','Target CPU for the IDE''s compiler');
  135. AddCustomFpmakeCommandlineOption('NoGDB','If value=1 or ''Y'', no GDB support');
  136. AddCustomFpmakeCommandlineOption('GDBMI','If value=1 or ''Y'', builds IDE with GDB/MI support (no need for LibGDB)');
  137. With Installer do
  138. begin
  139. s := GetCustomFpmakeCommandlineOptionValue('NoGDB');
  140. if (s='1') or (s='Y') then
  141. NoGDBOption := true;
  142. s := GetCustomFpmakeCommandlineOptionValue('GDBMI');
  143. if (s='1') or (s='Y') then
  144. GDBMIOption := true;
  145. s :=GetCustomFpmakeCommandlineOptionValue('CompilerTarget');
  146. if s <> '' then
  147. CompilerTarget:=StringToCPU(s)
  148. else
  149. CompilerTarget:=Defaults.CPU;
  150. P:=AddPackage('ide');
  151. P.Version:='3.1.1';
  152. {$ifdef ALLPACKAGES}
  153. P.Directory:=ADirectory;
  154. {$endif ALLPACKAGES}
  155. P.Dependencies.Add('rtl-extra');
  156. P.Dependencies.Add('fv');
  157. P.Dependencies.Add('chm');
  158. { This one is only needed if DEBUG is set }
  159. P.Dependencies.Add('regexpr');
  160. if not (NoGDBOption) and not (GDBMIOption) then
  161. P.Dependencies.Add('gdbint',AllOSes-AllAmigaLikeOSes);
  162. P.Dependencies.Add('graph',[go32v2]);
  163. P.SupportBuildModes:=[bmOneByOne];
  164. P.Options.Add('-Ur');
  165. P.Options.Add('-dNOCATCH');
  166. P.Options.Add('-dBrowserCol');
  167. P.Options.Add('-dGDB');
  168. P.Options.Add('-d'+CPUToString(CompilerTarget));
  169. P.Options.Add('-Fu../compiler');
  170. P.Options.Add('-Fu../compiler/'+CPUToString(CompilerTarget));
  171. P.Options.Add('-Fu../compiler/targets');
  172. P.Options.Add('-Fu../compiler/systems');
  173. P.Options.Add('-Fi../compiler/'+CPUToString(CompilerTarget));
  174. P.Options.Add('-Fi../compiler');
  175. if CompilerTarget in [x86_64, i386] then
  176. P.Options.Add('-Fu../compiler/x86');
  177. if CompilerTarget in [powerpc, powerpc64] then
  178. P.Options.Add('-Fu../compiler/ppcgen');
  179. if CompilerTarget = x86_64 then
  180. P.Options.Add('-dNOOPT');
  181. if CompilerTarget = mipsel then
  182. P.Options.Add('-Fu../compiler/mips');
  183. P.Options.Add('-Sg');
  184. T:=P.Targets.AddProgram('fp.pas');
  185. T.Dependencies.AddUnit('compunit');
  186. T:=P.Targets.AddUnit('compunit.pas');
  187. T.Directory:='compiler';
  188. T.Install:=false;
  189. P.InstallFiles.Add('fp.ans','$(bininstalldir)');
  190. P.InstallFiles.Add('gplprog.pt','$(bininstalldir)');
  191. P.InstallFiles.Add('gplunit.pt','$(bininstalldir)');
  192. P.InstallFiles.Add('program.pt','$(bininstalldir)');
  193. P.InstallFiles.Add('unit.pt','$(bininstalldir)');
  194. P.InstallFiles.Add('cvsco.tdf','$(bininstalldir)');
  195. P.InstallFiles.Add('cvsdiff.tdf','$(bininstalldir)');
  196. P.InstallFiles.Add('cvsup.tdf','$(bininstalldir)');
  197. P.InstallFiles.Add('grep.tdf','$(bininstalldir)');
  198. P.InstallFiles.Add('tpgrep.tdf','$(bininstalldir)');
  199. P.InstallFiles.Add('fp32.ico', [win32, win64], '$(bininstalldir)');
  200. P.Sources.AddDoc('readme.ide');
  201. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.ppu');
  202. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.ppu');
  203. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.ppu');
  204. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.ppu');
  205. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.ppu');
  206. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.o');
  207. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.o');
  208. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.o');
  209. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.o');
  210. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.o');
  211. P.BeforeCompileProc:=@ide_check_gdb_availability;
  212. end;
  213. end;
  214. {$ifndef ALLPACKAGES}
  215. begin
  216. add_ide('');
  217. Installer.Run;
  218. end.
  219. {$endif ALLPACKAGES}