fpmake.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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_comandlineoptions();
  132. begin
  133. AddCustomFpmakeCommandlineOption('CompilerTarget','Target CPU for the IDE''s compiler');
  134. AddCustomFpmakeCommandlineOption('NoGDB','If value=1 or ''Y'', no GDB support');
  135. AddCustomFpmakeCommandlineOption('NoGDBMI','If value=1 or ''Y'', explicitly disable GDB/MI option');
  136. AddCustomFpmakeCommandlineOption('GDBMI','If value=1 or ''Y'', builds IDE with GDB/MI support (no need for LibGDB)');
  137. AddCustomFpmakeCommandlineOption('NoIDE','If value=1 or ''Y'', the IDE will be skipped');
  138. end;
  139. procedure add_ide(const ADirectory: string);
  140. Var
  141. P : TPackage;
  142. T : TTarget;
  143. CompilerTarget : TCpu;
  144. CompilerDir,
  145. s: string;
  146. begin
  147. With Installer do
  148. begin
  149. s := GetCustomFpmakeCommandlineOptionValue('NoIDE');
  150. if (s='1') or (s='Y') then
  151. Exit;
  152. s := GetCustomFpmakeCommandlineOptionValue('NoGDB');
  153. if (s='1') or (s='Y') then
  154. NoGDBOption := true;
  155. s := GetCustomFpmakeCommandlineOptionValue('NOGDBMI');
  156. if (s='1') or (s='Y') then
  157. GDBMI_Disabled := true;
  158. if not GDBMI_Disabled then
  159. begin
  160. s := GetCustomFpmakeCommandlineOptionValue('GDBMI');
  161. if (s='1') or (s='Y') then
  162. GDBMIOption := true;
  163. if (Defaults.OS in GDBMI_DEFAULT_OSes) then
  164. GDBMIOption := True;
  165. end;
  166. s :=GetCustomFpmakeCommandlineOptionValue('CompilerTarget');
  167. if s <> '' then
  168. CompilerTarget:=StringToCPU(s)
  169. else
  170. CompilerTarget:=Defaults.CPU;
  171. { Only try to build natively }
  172. { or for cross-compile if the resulting executable
  173. does not depend on C libs }
  174. if ((GDBMIOption or NoGDBOption) and
  175. ((Defaults.BuildOS=Defaults.OS) and (Defaults.BuildCPU=Defaults.CPU)
  176. or (Defaults.OS in [go32v2,win32,win64,linux,freebsd])
  177. or not Defaults.SkipCrossPrograms)) or
  178. { This is the list of native targets that can be compiled natively with gdbint packages }
  179. ((((Defaults.BuildOS=Defaults.OS) and (Defaults.BuildCPU=Defaults.CPU)) or
  180. not Defaults.SkipCrossPrograms) and
  181. (Defaults.OS in [go32v2,win32,win64,linux,freebsd,os2,emx,beos,haiku])
  182. ) then
  183. begin
  184. P:=AddPackage('ide');
  185. P.Version:='3.3.1';
  186. {$ifdef ALLPACKAGES}
  187. P.Directory:=ADirectory;
  188. {$endif ALLPACKAGES}
  189. P.Dependencies.Add('rtl-extra');
  190. P.Dependencies.Add('fv');
  191. P.Dependencies.Add('chm');
  192. { This one is only needed if DEBUG is set }
  193. P.Dependencies.Add('regexpr');
  194. if not (NoGDBOption) and not (GDBMIOption) then
  195. P.Dependencies.Add('gdbint',AllOSes-AllAmigaLikeOSes);
  196. if GDBMIOption then
  197. P.Dependencies.Add('fcl-process');
  198. P.Dependencies.Add('graph',[go32v2]);
  199. P.Dependencies.Add('ami-extra',AllAmigaLikeOSes);
  200. P.SupportBuildModes:=[bmOneByOne];
  201. P.Options.Add('-Ur');
  202. P.Options.Add('-dNOCATCH');
  203. P.Options.Add('-dBrowserCol');
  204. P.Options.Add('-dGDB');
  205. CompilerDir:=P.Directory +'../../compiler';
  206. P.Options.Add('-d'+CPUToString(CompilerTarget));
  207. P.Options.Add('-Fu'+CompilerDir);
  208. P.Options.Add('-Fu'+CompilerDir+'/'+CPUToString(CompilerTarget));
  209. P.Options.Add('-Fu'+CompilerDir+'/targets');
  210. P.Options.Add('-Fu'+CompilerDir+'/systems');
  211. P.Options.Add('-Fi'+CompilerDir+'/'+CPUToString(CompilerTarget));
  212. P.Options.Add('-Fi'+CompilerDir);
  213. if CompilerTarget in [x86_64, i386, i8086] then
  214. P.Options.Add('-Fu'+CompilerDir+'/x86');
  215. if CompilerTarget in [powerpc, powerpc64] then
  216. P.Options.Add('-Fu'+CompilerDir+'/ppcgen');
  217. if CompilerTarget in [arm, aarch64] then
  218. P.Options.Add('-Fu'+CompilerDir+'/armgen');
  219. if CompilerTarget in [sparc, sparc64] then
  220. begin
  221. P.Options.Add('-Fu'+CompilerDir+'/sparcgen');
  222. P.Options.add('-Fi'+CompilerDir+'/sparcgen');
  223. end;
  224. if CompilerTarget in [riscv32, riscv64] then
  225. begin
  226. P.Options.Add('-Fu'+CompilerDir+'/riscv');
  227. end;
  228. if CompilerTarget = mipsel then
  229. P.Options.Add('-Fu'+CompilerDir+'/mips');
  230. { powerpc64-aix compiled IDE needs -CTsmalltoc option }
  231. if (Defaults.OS=aix) and (Defaults.CPU=powerpc64) then
  232. P.Options.Add('-CTsmalltoc');
  233. { Handle SPECIALLINK environment variable if available }
  234. s:=GetEnvironmentVariable('SPECIALLINK');
  235. if s<>'' then
  236. P.Options.Add(s);
  237. P.Options.Add('-Sg');
  238. P.IncludePath.Add('compiler');
  239. T:=P.Targets.AddProgram('fp.pas');
  240. if CompilerTarget<>Defaults.CPU then
  241. begin
  242. T.SetExeName(CPUToString(CompilerTarget)+'-fp');
  243. P.SetUnitsOutputDir(P.GetUnitsOutputDir(Defaults.BuildCPU,Defaults.BuildOS)+CPUToString(CompilerTarget));
  244. P.Options.Add('-dCROSSGDB');
  245. end;
  246. with T.Dependencies do
  247. begin
  248. AddUnit('compunit');
  249. end;
  250. T:=P.Targets.AddUnit('compunit.pas');
  251. T.Directory:='compiler';
  252. T.Install:=false;
  253. P.InstallFiles.Add('fp.ans','$(bininstalldir)');
  254. P.InstallFiles.Add('gplprog.pt','$(bininstalldir)');
  255. P.InstallFiles.Add('gplunit.pt','$(bininstalldir)');
  256. P.InstallFiles.Add('program.pt','$(bininstalldir)');
  257. P.InstallFiles.Add('unit.pt','$(bininstalldir)');
  258. P.InstallFiles.Add('cvsco.tdf','$(bininstalldir)');
  259. P.InstallFiles.Add('cvsdiff.tdf','$(bininstalldir)');
  260. P.InstallFiles.Add('cvsup.tdf','$(bininstalldir)');
  261. P.InstallFiles.Add('grep.tdf','$(bininstalldir)');
  262. P.InstallFiles.Add('tpgrep.tdf','$(bininstalldir)');
  263. P.InstallFiles.Add('fp32.ico', [win32, win64], '$(bininstalldir)');
  264. with P.Sources do
  265. begin
  266. AddDoc('readme.ide');
  267. AddSrc('readme.txt');
  268. AddSrc('todo.txt');
  269. AddSrc('fp.ans');
  270. AddSrcFiles('*.tdf',P.Directory);
  271. AddSrcFiles('*.pas',P.Directory,true);
  272. AddSrcFiles('*.inc',P.Directory,true);
  273. AddSrcFiles('*.rc',P.Directory);
  274. AddSrcFiles('*.ico',P.Directory);
  275. AddSrcFiles('*.term',P.Directory);
  276. AddSrcFiles('*.pt',P.Directory);
  277. end;
  278. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.ppu');
  279. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.ppu');
  280. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.ppu');
  281. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.ppu');
  282. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.ppu');
  283. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.o');
  284. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.o');
  285. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.o');
  286. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.o');
  287. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.o');
  288. P.BeforeCompileProc:=@ide_check_gdb_availability;
  289. end;
  290. end;
  291. end;
  292. {$ifndef ALLPACKAGES}
  293. begin
  294. add_ide_comandlineoptions();
  295. add_ide('');
  296. Installer.Run;
  297. end.
  298. {$endif ALLPACKAGES}