fpmake.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. GDBMI_Disabled: boolean = false;
  12. GDBMI_DEFAULT_OSes = [aix, darwin, freebsd, haiku,linux, netbsd, openbsd, solaris, win32, win64];
  13. procedure ide_check_gdb_availability(Sender: TObject);
  14. function DetectLibGDBDir: string;
  15. var
  16. SearchPath: string;
  17. const
  18. LibGDBName = 'libgdb.a';
  19. begin
  20. result:='';
  21. // First look for the GDBLIBDIR environment variable
  22. SearchPath := GetEnvironmentVariable('GDBLIBDIR');
  23. if (SearchPath<>'') and DirectoryExists(SearchPath) and FileExists(IncludeTrailingPathDelimiter(SearchPath)+LibGDBName) then
  24. begin
  25. result:=IncludeTrailingPathDelimiter(SearchPath);
  26. exit;
  27. end;
  28. // Search in the default locations
  29. SearchPath := '..'+PathDelim+'libgdb'+PathDelim+OSToString(Defaults.OS)+PathDelim+CPUToString(Defaults.CPU)+PathDelim;
  30. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  31. begin
  32. result := SearchPath;
  33. exit;
  34. end;
  35. SearchPath := '..'+PathDelim+'libgdb'+PathDelim+OSToString(Defaults.OS)+PathDelim;
  36. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  37. begin
  38. result := SearchPath;
  39. exit;
  40. end;
  41. // No custom libgdb.a found, try using system default library if available
  42. SearchPath := '..'+PathDelim+'lib'+PathDelim;
  43. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  44. begin
  45. result := SearchPath;
  46. installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
  47. exit;
  48. end;
  49. SearchPath := '..'+PathDelim+'usr'+PathDelim+'lib'+PathDelim;
  50. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  51. begin
  52. result := SearchPath;
  53. installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
  54. exit;
  55. end;
  56. SearchPath := '..'+PathDelim+'usr'+PathDelim+'local'+PathDelim+'lib'+PathDelim;
  57. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  58. begin
  59. result := SearchPath;
  60. installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
  61. exit;
  62. end;
  63. end;
  64. var
  65. GDBLibDir: string;
  66. P: TPackage;
  67. begin
  68. P := sender as TPackage;
  69. with installer do
  70. begin
  71. if GDBMIOption then
  72. begin
  73. BuildEngine.log(vlCommand, 'Compiling IDE with GDB/MI debugger support, LibGDB is not needed');
  74. P.Options.Add('-dGDBMI');
  75. { AIX also requires -CTsmalltoc for gdbmi }
  76. if Defaults.OS=aix then
  77. P.Options.Add('-CTsmalltoc');
  78. end
  79. else if not (NoGDBOption) then
  80. begin
  81. // Detection of GDB.
  82. GDBLibDir := DetectLibGDBDir;
  83. if GDBLibDir<>'' then
  84. begin
  85. // Include GDB
  86. BuildEngine.log(vlCommand, 'LibGDB was found, build IDE with debugger support');
  87. if FileExists(GDBLibDir+'gdblib.inc') then
  88. begin
  89. P.Options.Add('-dUSE_GDBLIBINC');
  90. P.Options.Add('-I'+GDBLibDir);
  91. end;
  92. P.Options.Add('-Fl'+GDBLibDir);
  93. case Defaults.OS of
  94. win32,
  95. win64 : begin
  96. P.Options.Add('-Xe');
  97. P.Options.Add('-k--allow-multiple-definition');
  98. end;
  99. freebsd : begin
  100. P.Options.Add('-Fl/usr/local/lib');
  101. P.Options.Add('-Xd');
  102. end;
  103. openbsd : begin
  104. P.Options.Add('-Fl/usr/local/lib');
  105. P.Options.Add('-Fl/usr/lib');
  106. P.Options.Add('-Xd');
  107. end;
  108. netbsd : P.Options.Add('-Xd');
  109. linux : P.Options.Add('-Xd');
  110. aix : begin
  111. P.Options.Add('-Xd');
  112. P.Options.Add('-Fl/opt/freeware/lib');
  113. P.Options.Add('-k-bbigtoc');
  114. end;
  115. end; {case}
  116. P.NeedLibc := true;
  117. end
  118. else
  119. begin
  120. BuildEngine.log(vlCommand, 'LibGDB was not found, IDE has no debugger support');
  121. P.Options.Add('-dNODEBUG');
  122. end;
  123. end
  124. else
  125. begin
  126. BuildEngine.log(vlCommand, 'Debugger support disabled');
  127. P.Options.Add('-dNODEBUG');
  128. end;
  129. end;
  130. end;
  131. procedure add_ide(const ADirectory: string);
  132. Var
  133. P : TPackage;
  134. T : TTarget;
  135. CompilerTarget : TCpu;
  136. CompilerDir,
  137. s: string;
  138. begin
  139. AddCustomFpmakeCommandlineOption('CompilerTarget','Target CPU for the IDE''s compiler');
  140. AddCustomFpmakeCommandlineOption('NoGDB','If value=1 or ''Y'', no GDB support');
  141. AddCustomFpmakeCommandlineOption('NOGDBMI','If value=1 or ''Y'', explicitly disable GDB/MI option');
  142. AddCustomFpmakeCommandlineOption('GDBMI','If value=1 or ''Y'', builds IDE with GDB/MI support (no need for LibGDB)');
  143. With Installer do
  144. begin
  145. s := GetCustomFpmakeCommandlineOptionValue('NoGDB');
  146. if (s='1') or (s='Y') then
  147. NoGDBOption := true;
  148. s := GetCustomFpmakeCommandlineOptionValue('NOGDBMI');
  149. if (s='1') or (s='Y') then
  150. GDBMI_Disabled := true;
  151. if not GDBMI_Disabled then
  152. begin
  153. s := GetCustomFpmakeCommandlineOptionValue('GDBMI');
  154. if (s='1') or (s='Y') then
  155. GDBMIOption := true;
  156. if (Defaults.OS in GDBMI_DEFAULT_OSes) then
  157. GDBMIOption := True;
  158. end;
  159. s :=GetCustomFpmakeCommandlineOptionValue('CompilerTarget');
  160. if s <> '' then
  161. CompilerTarget:=StringToCPU(s)
  162. else
  163. CompilerTarget:=Defaults.CPU;
  164. if GDBMIOption or GDBMI_Disabled or
  165. ( (Defaults.BuildOS=Defaults.OS) and (Defaults.BuildCPU=Defaults.CPU) and
  166. (Defaults.OS in [go32v2,win32,win64,linux,freebsd,os2,emx,beos,haiku])
  167. ) then
  168. begin
  169. P:=AddPackage('ide');
  170. P.Version:='3.1.1';
  171. {$ifdef ALLPACKAGES}
  172. P.Directory:=ADirectory;
  173. {$endif ALLPACKAGES}
  174. P.Dependencies.Add('rtl-extra');
  175. P.Dependencies.Add('fv');
  176. P.Dependencies.Add('chm');
  177. { This one is only needed if DEBUG is set }
  178. P.Dependencies.Add('regexpr');
  179. if not (NoGDBOption) and not (GDBMIOption) then
  180. P.Dependencies.Add('gdbint',AllOSes-AllAmigaLikeOSes);
  181. if GDBMIOption then
  182. P.Dependencies.Add('fcl-process');
  183. P.Dependencies.Add('graph',[go32v2]);
  184. P.Dependencies.Add('ami-extra',AllAmigaLikeOSes);
  185. P.SupportBuildModes:=[bmOneByOne];
  186. P.Options.Add('-Ur');
  187. P.Options.Add('-dNOCATCH');
  188. P.Options.Add('-dBrowserCol');
  189. P.Options.Add('-dGDB');
  190. CompilerDir:=P.Directory +'../../compiler';
  191. P.Options.Add('-d'+CPUToString(CompilerTarget));
  192. P.Options.Add('-Fu'+CompilerDir);
  193. P.Options.Add('-Fu'+CompilerDir+'/'+CPUToString(CompilerTarget));
  194. P.Options.Add('-Fu'+CompilerDir+'/targets');
  195. P.Options.Add('-Fu'+CompilerDir+'/systems');
  196. P.Options.Add('-Fi'+CompilerDir+'/'+CPUToString(CompilerTarget));
  197. P.Options.Add('-Fi'+CompilerDir);
  198. if CompilerTarget in [x86_64, i386, i8086] then
  199. P.Options.Add('-Fu'+CompilerDir+'/x86');
  200. if CompilerTarget in [powerpc, powerpc64] then
  201. P.Options.Add('-Fu'+CompilerDir+'/ppcgen');
  202. if CompilerTarget in [sparc, sparc64] then
  203. begin
  204. P.Options.Add('-Fu'+CompilerDir+'/sparcgen');
  205. P.Options.add('-Fi'+CompilerDir+'/sparcgen');
  206. end;
  207. if CompilerTarget = mipsel then
  208. P.Options.Add('-Fu'+CompilerDir+'/mips');
  209. { powerpc64-aix compiled IDE needs -CTsmalltoc option }
  210. if (Defaults.OS=aix) and (Defaults.CPU=powerpc64) then
  211. P.Options.Add('-CTsmalltoc');
  212. { Handle SPECIALLINK environment variable if available }
  213. s:=GetEnvironmentVariable('SPECIALLINK');
  214. if s<>'' then
  215. P.Options.Add(s);
  216. P.Options.Add('-Sg');
  217. P.IncludePath.Add('compiler');
  218. T:=P.Targets.AddProgram('fp.pas');
  219. if CompilerTarget<>Defaults.CPU then
  220. begin
  221. T.SetExeName(CPUToString(CompilerTarget)+'-fp');
  222. P.SetUnitsOutputDir(P.GetUnitsOutputDir(Defaults.BuildCPU,Defaults.BuildOS)+CPUToString(CompilerTarget));
  223. P.Options.Add('-dCROSSGDB');
  224. end;
  225. with T.Dependencies do
  226. begin
  227. AddUnit('compunit');
  228. end;
  229. T:=P.Targets.AddUnit('compunit.pas');
  230. T.Directory:='compiler';
  231. T.Install:=false;
  232. P.InstallFiles.Add('fp.ans','$(bininstalldir)');
  233. P.InstallFiles.Add('gplprog.pt','$(bininstalldir)');
  234. P.InstallFiles.Add('gplunit.pt','$(bininstalldir)');
  235. P.InstallFiles.Add('program.pt','$(bininstalldir)');
  236. P.InstallFiles.Add('unit.pt','$(bininstalldir)');
  237. P.InstallFiles.Add('cvsco.tdf','$(bininstalldir)');
  238. P.InstallFiles.Add('cvsdiff.tdf','$(bininstalldir)');
  239. P.InstallFiles.Add('cvsup.tdf','$(bininstalldir)');
  240. P.InstallFiles.Add('grep.tdf','$(bininstalldir)');
  241. P.InstallFiles.Add('tpgrep.tdf','$(bininstalldir)');
  242. P.InstallFiles.Add('fp32.ico', [win32, win64], '$(bininstalldir)');
  243. with P.Sources do
  244. begin
  245. AddDoc('readme.ide');
  246. AddSrc('readme.txt');
  247. AddSrc('todo.txt');
  248. AddSrc('fp.ans');
  249. AddSrcFiles('*.tdf',P.Directory);
  250. AddSrcFiles('*.pas',P.Directory,true);
  251. AddSrcFiles('*.inc',P.Directory,true);
  252. AddSrcFiles('*.rc',P.Directory);
  253. AddSrcFiles('*.ico',P.Directory);
  254. AddSrcFiles('*.term',P.Directory);
  255. AddSrcFiles('*.pt',P.Directory);
  256. end;
  257. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.ppu');
  258. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.ppu');
  259. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.ppu');
  260. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.ppu');
  261. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.ppu');
  262. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.o');
  263. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.o');
  264. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.o');
  265. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.o');
  266. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.o');
  267. P.BeforeCompileProc:=@ide_check_gdb_availability;
  268. end;
  269. end;
  270. end;
  271. {$ifndef ALLPACKAGES}
  272. begin
  273. add_ide('');
  274. Installer.Run;
  275. end.
  276. {$endif ALLPACKAGES}