fpmake.pp 9.7 KB

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