fpmake.pp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. { AIX also requires -CTsmalltoc for gdbmi }
  75. if Defaults.OS=aix then
  76. P.Options.Add('-CTsmalltoc');
  77. end
  78. else if not (NoGDBOption) then
  79. begin
  80. // Detection of GDB.
  81. GDBLibDir := DetectLibGDBDir;
  82. if GDBLibDir<>'' then
  83. begin
  84. // Include GDB
  85. BuildEngine.log(vlCommand, 'LibGDB was found, build IDE with debugger support');
  86. if FileExists(GDBLibDir+'gdblib.inc') then
  87. begin
  88. P.Options.Add('-dUSE_GDBLIBINC');
  89. P.Options.Add('-I'+GDBLibDir);
  90. end;
  91. P.Options.Add('-Fl'+GDBLibDir);
  92. case Defaults.OS of
  93. win32,
  94. win64 : begin
  95. P.Options.Add('-Xe');
  96. P.Options.Add('-k--allow-multiple-definition');
  97. end;
  98. freebsd : begin
  99. P.Options.Add('-Fl/usr/local/lib');
  100. P.Options.Add('-Xd');
  101. end;
  102. openbsd : begin
  103. P.Options.Add('-Fl/usr/local/lib');
  104. P.Options.Add('-Fl/usr/lib');
  105. P.Options.Add('-Xd');
  106. end;
  107. netbsd : P.Options.Add('-Xd');
  108. linux : P.Options.Add('-Xd');
  109. aix : begin
  110. P.Options.Add('-Xd');
  111. P.Options.Add('-Fl/opt/freeware/lib');
  112. P.Options.Add('-k-bbigtoc');
  113. end;
  114. end; {case}
  115. P.NeedLibc := true;
  116. end
  117. else
  118. begin
  119. BuildEngine.log(vlCommand, 'LibGDB was not found, IDE has no debugger support');
  120. P.Options.Add('-dNODEBUG');
  121. end;
  122. end
  123. else
  124. begin
  125. BuildEngine.log(vlCommand, 'Debugger support disabled');
  126. P.Options.Add('-dNODEBUG');
  127. end;
  128. end;
  129. end;
  130. procedure add_ide(const ADirectory: string);
  131. Var
  132. P : TPackage;
  133. T : TTarget;
  134. CompilerTarget : TCpu;
  135. s: string;
  136. begin
  137. AddCustomFpmakeCommandlineOption('CompilerTarget','Target CPU for the IDE''s compiler');
  138. AddCustomFpmakeCommandlineOption('NoGDB','If value=1 or ''Y'', no GDB support');
  139. AddCustomFpmakeCommandlineOption('GDBMI','If value=1 or ''Y'', builds IDE with GDB/MI support (no need for LibGDB)');
  140. With Installer do
  141. begin
  142. s := GetCustomFpmakeCommandlineOptionValue('NoGDB');
  143. if (s='1') or (s='Y') then
  144. NoGDBOption := true;
  145. s := GetCustomFpmakeCommandlineOptionValue('GDBMI');
  146. if (s='1') or (s='Y') then
  147. GDBMIOption := true;
  148. s :=GetCustomFpmakeCommandlineOptionValue('CompilerTarget');
  149. if s <> '' then
  150. CompilerTarget:=StringToCPU(s)
  151. else
  152. CompilerTarget:=Defaults.CPU;
  153. P:=AddPackage('ide');
  154. P.Version:='3.1.1';
  155. {$ifdef ALLPACKAGES}
  156. P.Directory:=ADirectory;
  157. {$endif ALLPACKAGES}
  158. P.Dependencies.Add('rtl-extra');
  159. P.Dependencies.Add('fv');
  160. P.Dependencies.Add('chm');
  161. { This one is only needed if DEBUG is set }
  162. P.Dependencies.Add('regexpr');
  163. if not (NoGDBOption) and not (GDBMIOption) then
  164. P.Dependencies.Add('gdbint',AllOSes-AllAmigaLikeOSes);
  165. if GDBMIOption then
  166. P.Dependencies.Add('fcl-process');
  167. P.Dependencies.Add('graph',[go32v2]);
  168. P.Dependencies.Add('ami-extra',AllAmigaLikeOSes);
  169. P.SupportBuildModes:=[bmOneByOne];
  170. P.Options.Add('-Ur');
  171. P.Options.Add('-dNOCATCH');
  172. P.Options.Add('-dBrowserCol');
  173. P.Options.Add('-dGDB');
  174. P.Options.Add('-d'+CPUToString(CompilerTarget));
  175. P.Options.Add('-Fu../compiler');
  176. P.Options.Add('-Fu../compiler/'+CPUToString(CompilerTarget));
  177. P.Options.Add('-Fu../compiler/targets');
  178. P.Options.Add('-Fu../compiler/systems');
  179. P.Options.Add('-Fi../compiler/'+CPUToString(CompilerTarget));
  180. P.Options.Add('-Fi../compiler');
  181. if CompilerTarget in [x86_64, i386, i8086] then
  182. P.Options.Add('-Fu../compiler/x86');
  183. if CompilerTarget in [powerpc, powerpc64] then
  184. P.Options.Add('-Fu../compiler/ppcgen');
  185. if CompilerTarget = x86_64 then
  186. P.Options.Add('-dNOOPT');
  187. if CompilerTarget = mipsel then
  188. P.Options.Add('-Fu../compiler/mips');
  189. { powerpc64-aix compiled IDE needs -CTsmalltoc option }
  190. if (Defaults.OS=aix) and (Defaults.CPU=powerpc64) then
  191. P.Options.Add('-CTsmalltoc');
  192. { Handle SPECIALLINK environment variable if available }
  193. s:=GetEnvironmentVariable('SPECIALLINK');
  194. if s<>'' then
  195. P.Options.Add(s);
  196. P.Options.Add('-Sg');
  197. P.IncludePath.Add('compiler');
  198. T:=P.Targets.AddProgram('fp.pas');
  199. with T.Dependencies do
  200. begin
  201. AddUnit('compunit');
  202. end;
  203. T:=P.Targets.AddUnit('compunit.pas');
  204. T.Directory:='compiler';
  205. T.Install:=false;
  206. P.InstallFiles.Add('fp.ans','$(bininstalldir)');
  207. P.InstallFiles.Add('gplprog.pt','$(bininstalldir)');
  208. P.InstallFiles.Add('gplunit.pt','$(bininstalldir)');
  209. P.InstallFiles.Add('program.pt','$(bininstalldir)');
  210. P.InstallFiles.Add('unit.pt','$(bininstalldir)');
  211. P.InstallFiles.Add('cvsco.tdf','$(bininstalldir)');
  212. P.InstallFiles.Add('cvsdiff.tdf','$(bininstalldir)');
  213. P.InstallFiles.Add('cvsup.tdf','$(bininstalldir)');
  214. P.InstallFiles.Add('grep.tdf','$(bininstalldir)');
  215. P.InstallFiles.Add('tpgrep.tdf','$(bininstalldir)');
  216. P.InstallFiles.Add('fp32.ico', [win32, win64], '$(bininstalldir)');
  217. with P.Sources do
  218. begin
  219. AddDoc('readme.ide');
  220. AddSrc('readme.txt');
  221. AddSrc('todo.txt');
  222. AddSrc('fp.ans');
  223. AddSrcFiles('*.tdf',P.Directory);
  224. AddSrcFiles('*.pas',P.Directory,true);
  225. AddSrcFiles('*.inc',P.Directory,true);
  226. AddSrcFiles('*.rc',P.Directory);
  227. AddSrcFiles('*.ico',P.Directory);
  228. AddSrcFiles('*.term',P.Directory);
  229. AddSrcFiles('*.pt',P.Directory);
  230. end;
  231. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.ppu');
  232. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.ppu');
  233. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.ppu');
  234. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.ppu');
  235. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.ppu');
  236. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.o');
  237. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.o');
  238. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.o');
  239. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.o');
  240. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.o');
  241. P.BeforeCompileProc:=@ide_check_gdb_availability;
  242. end;
  243. end;
  244. {$ifndef ALLPACKAGES}
  245. begin
  246. add_ide('');
  247. Installer.Run;
  248. end.
  249. {$endif ALLPACKAGES}