fpmake.pp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. {$ifndef ALLPACKAGES}
  2. {$mode objfpc}{$H+}
  3. program fpmake;
  4. uses
  5. {$ifdef unix}cthreads,{$endif} fpmkunit,
  6. sysutils;
  7. {$endif ALLPACKAGES}
  8. const
  9. NoGDBOption: boolean = false;
  10. GDBMIOption: boolean = false;
  11. GDBMI_Disabled: boolean = false;
  12. LLVM_Disabled: boolean = false;
  13. GDBMI_DEFAULT_OSes = [aix, darwin, freebsd, haiku,linux, netbsd, openbsd, solaris, win32, win64];
  14. procedure ide_check_gdb_availability(Sender: TObject);
  15. function DetectLibGDBDir: string;
  16. var
  17. SearchPath: string;
  18. const
  19. LibGDBName = 'libgdb.a';
  20. begin
  21. result:='';
  22. // First look for the GDBLIBDIR environment variable
  23. SearchPath := GetEnvironmentVariable('GDBLIBDIR');
  24. if (SearchPath<>'') and DirectoryExists(SearchPath) and FileExists(IncludeTrailingPathDelimiter(SearchPath)+LibGDBName) then
  25. begin
  26. result:=IncludeTrailingPathDelimiter(SearchPath);
  27. exit;
  28. end;
  29. // Search in the default locations
  30. SearchPath := '..'+PathDelim+'libgdb'+PathDelim+OSToString(Defaults.OS)+PathDelim+CPUToString(Defaults.CPU)+PathDelim;
  31. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  32. begin
  33. result := SearchPath;
  34. exit;
  35. end;
  36. SearchPath := '..'+PathDelim+'libgdb'+PathDelim+OSToString(Defaults.OS)+PathDelim;
  37. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  38. begin
  39. result := SearchPath;
  40. exit;
  41. end;
  42. // No custom libgdb.a found, try using system default library if available
  43. SearchPath := '..'+PathDelim+'lib'+PathDelim;
  44. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  45. begin
  46. result := SearchPath;
  47. installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
  48. exit;
  49. end;
  50. SearchPath := '..'+PathDelim+'usr'+PathDelim+'lib'+PathDelim;
  51. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  52. begin
  53. result := SearchPath;
  54. installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
  55. exit;
  56. end;
  57. SearchPath := '..'+PathDelim+'usr'+PathDelim+'local'+PathDelim+'lib'+PathDelim;
  58. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  59. begin
  60. result := SearchPath;
  61. installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
  62. exit;
  63. end;
  64. end;
  65. var
  66. GDBLibDir: string;
  67. P: TPackage;
  68. begin
  69. P := sender as TPackage;
  70. with installer do
  71. begin
  72. if GDBMIOption then
  73. begin
  74. BuildEngine.log(vlCommand, 'Compiling IDE with GDB/MI debugger support, LibGDB is not needed');
  75. P.Options.Add('-dGDBMI');
  76. { AIX also requires -CTsmalltoc for gdbmi }
  77. if Defaults.OS=aix then
  78. P.Options.Add('-CTsmalltoc');
  79. end
  80. else if not (NoGDBOption) then
  81. begin
  82. // Detection of GDB.
  83. GDBLibDir := DetectLibGDBDir;
  84. if GDBLibDir<>'' then
  85. begin
  86. // Include GDB
  87. BuildEngine.log(vlCommand, 'LibGDB was found, build IDE with debugger support');
  88. if FileExists(GDBLibDir+'gdblib.inc') then
  89. begin
  90. P.Options.Add('-dUSE_GDBLIBINC');
  91. P.Options.Add('-I'+GDBLibDir);
  92. end;
  93. P.Options.Add('-Fl'+GDBLibDir);
  94. case Defaults.OS of
  95. win32,
  96. win64 : begin
  97. P.Options.Add('-Xe');
  98. P.Options.Add('-k--allow-multiple-definition');
  99. end;
  100. freebsd : begin
  101. P.Options.Add('-Fl/usr/local/lib');
  102. P.Options.Add('-Xd');
  103. end;
  104. openbsd : begin
  105. P.Options.Add('-Fl/usr/local/lib');
  106. P.Options.Add('-Fl/usr/lib');
  107. P.Options.Add('-Xd');
  108. end;
  109. netbsd : P.Options.Add('-Xd');
  110. linux : P.Options.Add('-Xd');
  111. aix : begin
  112. P.Options.Add('-Xd');
  113. P.Options.Add('-Fl/opt/freeware/lib');
  114. P.Options.Add('-k-bbigtoc');
  115. end;
  116. else
  117. ; // Avoid compiler warning
  118. end; {case}
  119. P.NeedLibc := true;
  120. end
  121. else
  122. begin
  123. BuildEngine.log(vlCommand, 'LibGDB was not found, IDE has no debugger support');
  124. P.Options.Add('-dNODEBUG');
  125. end;
  126. end
  127. else
  128. begin
  129. BuildEngine.log(vlCommand, 'Debugger support disabled');
  130. P.Options.Add('-dNODEBUG');
  131. end;
  132. end;
  133. end;
  134. procedure add_ide_comandlineoptions();
  135. begin
  136. AddCustomFpmakeCommandlineOption('CompilerTarget','Target CPU for the IDE''s compiler');
  137. AddCustomFpmakeCommandlineOption('NoGDB','If value=1 or ''Y'', no GDB support');
  138. AddCustomFpmakeCommandlineOption('NoGDBMI','If value=1 or ''Y'', explicitly disable GDB/MI option');
  139. AddCustomFpmakeCommandlineOption('GDBMI','If value=1 or ''Y'', builds IDE with GDB/MI support (no need for LibGDB)');
  140. AddCustomFpmakeCommandlineOption('NoIDE','If value=1 or ''Y'', the IDE will be skipped');
  141. AddCustomFpmakeCommandlineOption('IDE','If value=1 or ''Y'', the IDE will be build for each target');
  142. AddCustomFpmakeCommandlineOption('LLVM','If value=1 or ''Y'', the Compiler codegenerator will use LLVM');
  143. AddCustomFpmakeCommandlineOption('NoLLVM','If value=1 or ''Y'', ito explicitly disable use of LLVM');
  144. end;
  145. procedure add_ide(const ADirectory: string);
  146. Var
  147. P : TPackage;
  148. T : TTarget;
  149. CompilerTarget : TCpu;
  150. CompilerDir,
  151. s: string;
  152. llvm: boolean;
  153. begin
  154. if SameText(Defaults.SubTarget,'unicodertl') then
  155. exit;
  156. With Installer do
  157. begin
  158. s := GetCustomFpmakeCommandlineOptionValue('NoIDE');
  159. if (s='1') or (s='Y') then
  160. Exit;
  161. s := GetCustomFpmakeCommandlineOptionValue('NoGDB');
  162. if (s='1') or (s='Y') then
  163. NoGDBOption := true;
  164. s := GetCustomFpmakeCommandlineOptionValue('NOGDBMI');
  165. if (s='1') or (s='Y') then
  166. GDBMI_Disabled := true;
  167. if not GDBMI_Disabled then
  168. begin
  169. s := GetCustomFpmakeCommandlineOptionValue('GDBMI');
  170. if (s='1') or (s='Y') then
  171. GDBMIOption := true;
  172. if (Defaults.OS in GDBMI_DEFAULT_OSes) then
  173. GDBMIOption := True;
  174. end;
  175. s :=GetCustomFpmakeCommandlineOptionValue('CompilerTarget');
  176. if s <> '' then
  177. CompilerTarget:=StringToCPU(s)
  178. else
  179. CompilerTarget:=Defaults.CPU;
  180. {$ifdef CPULLVM}
  181. llvm:=true;
  182. {$else}
  183. llvm:=false;
  184. {$endif}
  185. s := GetCustomFpmakeCommandlineOptionValue('NOLLVM');
  186. if (s='1') or (s='Y') then
  187. LLVM_Disabled := true;
  188. if LLVM_Disabled then
  189. llvm:=false
  190. else
  191. begin
  192. s:=GetCustomFpmakeCommandlineOptionValue('LLVM');
  193. if (s='1') or (s='Y') then
  194. llvm:=true;
  195. end;
  196. { Only try to build natively }
  197. { or for cross-compile if the resulting executable
  198. does not depend on C libs }
  199. if ((GDBMIOption or NoGDBOption) and
  200. ((Defaults.BuildOS=Defaults.OS) and (Defaults.BuildCPU=Defaults.CPU)
  201. or (Defaults.OS in [go32v2,win32,win64,linux,freebsd])
  202. or not Defaults.SkipCrossPrograms)) or
  203. { This is the list of native targets that can be compiled natively with gdbint packages }
  204. ((((Defaults.BuildOS=Defaults.OS) and (Defaults.BuildCPU=Defaults.CPU)) or
  205. not Defaults.SkipCrossPrograms) and
  206. (Defaults.OS in [go32v2,win32,win64,linux,freebsd,os2,emx,beos,haiku])
  207. ) then
  208. begin
  209. P:=AddPackage('ide');
  210. P.Version:='3.3.1';
  211. {$ifdef ALLPACKAGES}
  212. P.Directory:=ADirectory;
  213. {$endif ALLPACKAGES}
  214. s :=GetCustomFpmakeCommandlineOptionValue('IDE');
  215. if (s='1') or (s='Y') then
  216. P.OSes := AllOSes
  217. else
  218. P.OSes := AllOSes-[darwin];
  219. P.Dependencies.Add('rtl-extra');
  220. P.Dependencies.Add('fv');
  221. P.Dependencies.Add('chm');
  222. { This one is only needed if DEBUG is set }
  223. P.Dependencies.Add('regexpr');
  224. if not (NoGDBOption) and not (GDBMIOption) then
  225. P.Dependencies.Add('gdbint',AllOSes-AllAmigaLikeOSes);
  226. if GDBMIOption then
  227. P.Dependencies.Add('fcl-process');
  228. P.Dependencies.Add('graph',[go32v2]);
  229. P.Dependencies.Add('ami-extra',AllAmigaLikeOSes);
  230. P.SupportBuildModes:=[bmOneByOne];
  231. P.Options.Add('-Ur');
  232. P.Options.Add('-dNOCATCH');
  233. P.Options.Add('-dBrowserCol');
  234. P.Options.Add('-dGDB');
  235. if CompilerTarget=wasm32 then
  236. P.Options.Add('-dNOOPT');
  237. CompilerDir:=P.Directory +'../../compiler';
  238. P.Options.Add('-d'+CPUToString(CompilerTarget));
  239. P.Options.Add('-Fu'+CompilerDir);
  240. P.Options.Add('-Fu'+CompilerDir+'/'+CPUToString(CompilerTarget));
  241. P.Options.Add('-Fu'+CompilerDir+'/targets');
  242. P.Options.Add('-Fu'+CompilerDir+'/systems');
  243. P.Options.Add('-Fi'+CompilerDir+'/'+CPUToString(CompilerTarget));
  244. P.Options.Add('-Fi'+CompilerDir);
  245. if CompilerTarget in [x86_64, i386, i8086] then
  246. P.Options.Add('-Fu'+CompilerDir+'/x86');
  247. if CompilerTarget in [powerpc, powerpc64] then
  248. P.Options.Add('-Fu'+CompilerDir+'/ppcgen');
  249. if CompilerTarget in [arm, aarch64] then
  250. P.Options.Add('-Fu'+CompilerDir+'/armgen');
  251. if CompilerTarget in [sparc, sparc64] then
  252. begin
  253. P.Options.Add('-Fu'+CompilerDir+'/sparcgen');
  254. P.Options.add('-Fi'+CompilerDir+'/sparcgen');
  255. end;
  256. if CompilerTarget in [riscv32, riscv64] then
  257. begin
  258. P.Options.Add('-Fu'+CompilerDir+'/riscv');
  259. end;
  260. if CompilerTarget = mipsel then
  261. P.Options.Add('-Fu'+CompilerDir+'/mips');
  262. if CompilerTarget = loongarch64 then
  263. P.Options.Add('-Fu'+CompilerDir+'/loongarch64');
  264. if llvm then
  265. begin
  266. P.Options.Add('-Fu'+CompilerDir+'/llvm');
  267. P.Options.Add('-Fi'+CompilerDir+'/llvm');
  268. end;
  269. { powerpc64-aix compiled IDE needs -CTsmalltoc option }
  270. if (Defaults.OS=aix) and (Defaults.CPU=powerpc64) then
  271. P.Options.Add('-CTsmalltoc');
  272. { Handle SPECIALLINK environment variable if available }
  273. s:=GetEnvironmentVariable('SPECIALLINK');
  274. if s<>'' then
  275. P.Options.Add(s);
  276. P.Options.Add('-Sg');
  277. P.IncludePath.Add('compiler');
  278. T:=P.Targets.AddProgram('fp.pas');
  279. if CompilerTarget<>Defaults.CPU then
  280. begin
  281. T.SetExeName(AddProgramExtension(CPUToString(CompilerTarget)+'-fp',Defaults.BuildOS));
  282. P.SetUnitsOutputDir(P.GetUnitsOutputDir(Defaults.BuildTarget)+CPUToString(CompilerTarget));
  283. P.Options.Add('-dCROSSGDB');
  284. end;
  285. with T.Dependencies do
  286. begin
  287. AddUnit('compunit');
  288. end;
  289. T:=P.Targets.AddUnit('compunit.pas');
  290. T.Directory:='compiler';
  291. T.Install:=false;
  292. if (OSToString(defaults.OS)=lowercase({$I %FPCTARGETOS%})) and
  293. (CPUToString(defaults.CPU)=lowercase({$I %FPCTARGETCPU%})) then
  294. begin
  295. P.InstallFiles.Add('fp.ans','$(bininstalldir)');
  296. P.InstallFiles.Add('gplprog.pt','$(bininstalldir)');
  297. P.InstallFiles.Add('gplunit.pt','$(bininstalldir)');
  298. P.InstallFiles.Add('program.pt','$(bininstalldir)');
  299. P.InstallFiles.Add('unit.pt','$(bininstalldir)');
  300. P.InstallFiles.Add('cvsco.tdf','$(bininstalldir)');
  301. P.InstallFiles.Add('cvsdiff.tdf','$(bininstalldir)');
  302. P.InstallFiles.Add('cvsup.tdf','$(bininstalldir)');
  303. P.InstallFiles.Add('grep.tdf','$(bininstalldir)');
  304. P.InstallFiles.Add('tpgrep.tdf','$(bininstalldir)');
  305. P.InstallFiles.Add('fp32.ico', [win32, win64], '$(bininstalldir)');
  306. end;
  307. with P.Sources do
  308. begin
  309. AddDoc('readme.ide');
  310. AddSrc('README.txt');
  311. AddSrc('TODO.txt');
  312. AddSrc('fp.ans');
  313. AddSrcFiles('*.tdf',P.Directory);
  314. AddSrcFiles('*.pas',P.Directory,true);
  315. AddSrcFiles('*.inc',P.Directory,true);
  316. AddSrcFiles('*.rc',P.Directory);
  317. AddSrcFiles('*.ico',P.Directory);
  318. AddSrcFiles('*.term',P.Directory);
  319. AddSrcFiles('*.pt',P.Directory);
  320. end;
  321. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.ppu');
  322. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.ppu');
  323. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.ppu');
  324. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.ppu');
  325. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.ppu');
  326. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.o');
  327. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.o');
  328. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.o');
  329. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.o');
  330. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.o');
  331. P.BeforeCompileProc:=@ide_check_gdb_availability;
  332. end;
  333. end;
  334. end;
  335. {$ifndef ALLPACKAGES}
  336. begin
  337. If Assigned(Installer) then
  338. begin
  339. add_ide_comandlineoptions();
  340. add_ide('');
  341. Installer.Run;
  342. end;
  343. end.
  344. {$endif ALLPACKAGES}