fpmake.pp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. if Defaults.Namespaces then
  157. exit;
  158. With Installer do
  159. begin
  160. s := GetCustomFpmakeCommandlineOptionValue('NoIDE');
  161. if (s='1') or (s='Y') then
  162. Exit;
  163. s := GetCustomFpmakeCommandlineOptionValue('NoGDB');
  164. if (s='1') or (s='Y') then
  165. NoGDBOption := true;
  166. s := GetCustomFpmakeCommandlineOptionValue('NOGDBMI');
  167. if (s='1') or (s='Y') then
  168. GDBMI_Disabled := true;
  169. if not GDBMI_Disabled then
  170. begin
  171. s := GetCustomFpmakeCommandlineOptionValue('GDBMI');
  172. if (s='1') or (s='Y') then
  173. GDBMIOption := true;
  174. if (Defaults.OS in GDBMI_DEFAULT_OSes) then
  175. GDBMIOption := True;
  176. end;
  177. s :=GetCustomFpmakeCommandlineOptionValue('CompilerTarget');
  178. if s <> '' then
  179. CompilerTarget:=StringToCPU(s)
  180. else
  181. CompilerTarget:=Defaults.CPU;
  182. {$ifdef CPULLVM}
  183. llvm:=true;
  184. {$else}
  185. llvm:=false;
  186. {$endif}
  187. s := GetCustomFpmakeCommandlineOptionValue('NOLLVM');
  188. if (s='1') or (s='Y') then
  189. LLVM_Disabled := true;
  190. if LLVM_Disabled then
  191. llvm:=false
  192. else
  193. begin
  194. s:=GetCustomFpmakeCommandlineOptionValue('LLVM');
  195. if (s='1') or (s='Y') then
  196. llvm:=true;
  197. end;
  198. { Only try to build natively }
  199. { or for cross-compile if the resulting executable
  200. does not depend on C libs }
  201. if ((GDBMIOption or NoGDBOption) and
  202. ((Defaults.BuildOS=Defaults.OS) and (Defaults.BuildCPU=Defaults.CPU)
  203. or (Defaults.OS in [go32v2,win32,win64,linux,freebsd])
  204. or not Defaults.SkipCrossPrograms)) or
  205. { This is the list of native targets that can be compiled natively with gdbint packages }
  206. ((((Defaults.BuildOS=Defaults.OS) and (Defaults.BuildCPU=Defaults.CPU)) or
  207. not Defaults.SkipCrossPrograms) and
  208. (Defaults.OS in [go32v2,win32,win64,linux,freebsd,os2,emx,beos,haiku])
  209. ) then
  210. begin
  211. P:=AddPackage('ide');
  212. P.Version:='3.3.1';
  213. {$ifdef ALLPACKAGES}
  214. P.Directory:=ADirectory;
  215. {$endif ALLPACKAGES}
  216. s :=GetCustomFpmakeCommandlineOptionValue('IDE');
  217. if (s='1') or (s='Y') then
  218. P.OSes := AllOSes
  219. else
  220. P.OSes := AllOSes-[darwin];
  221. P.Dependencies.Add('rtl-extra');
  222. P.Dependencies.Add('fv');
  223. P.Dependencies.Add('chm');
  224. { This one is only needed if DEBUG is set }
  225. P.Dependencies.Add('regexpr');
  226. if not (NoGDBOption) and not (GDBMIOption) then
  227. P.Dependencies.Add('gdbint',AllOSes-AllAmigaLikeOSes);
  228. if GDBMIOption then
  229. P.Dependencies.Add('fcl-process');
  230. P.Dependencies.Add('graph',[go32v2]);
  231. P.Dependencies.Add('ami-extra',AllAmigaLikeOSes);
  232. P.SupportBuildModes:=[bmOneByOne];
  233. P.Options.Add('-Ur');
  234. P.Options.Add('-dNOCATCH');
  235. P.Options.Add('-dBrowserCol');
  236. P.Options.Add('-dGDB');
  237. if CompilerTarget=wasm32 then
  238. P.Options.Add('-dNOOPT');
  239. CompilerDir:=P.Directory +'../../compiler';
  240. P.Options.Add('-d'+CPUToString(CompilerTarget));
  241. P.Options.Add('-Fu'+CompilerDir);
  242. P.Options.Add('-Fu'+CompilerDir+'/'+CPUToString(CompilerTarget));
  243. P.Options.Add('-Fu'+CompilerDir+'/targets');
  244. P.Options.Add('-Fu'+CompilerDir+'/systems');
  245. P.Options.Add('-Fi'+CompilerDir+'/'+CPUToString(CompilerTarget));
  246. P.Options.Add('-Fi'+CompilerDir);
  247. if CompilerTarget in [x86_64, i386, i8086] then
  248. P.Options.Add('-Fu'+CompilerDir+'/x86');
  249. if CompilerTarget in [powerpc, powerpc64] then
  250. P.Options.Add('-Fu'+CompilerDir+'/ppcgen');
  251. if CompilerTarget in [arm, aarch64] then
  252. P.Options.Add('-Fu'+CompilerDir+'/armgen');
  253. if CompilerTarget in [sparc, sparc64] then
  254. begin
  255. P.Options.Add('-Fu'+CompilerDir+'/sparcgen');
  256. P.Options.add('-Fi'+CompilerDir+'/sparcgen');
  257. end;
  258. if CompilerTarget in [riscv32, riscv64] then
  259. begin
  260. P.Options.Add('-Fu'+CompilerDir+'/riscv');
  261. end;
  262. if CompilerTarget = mipsel then
  263. P.Options.Add('-Fu'+CompilerDir+'/mips');
  264. if CompilerTarget = loongarch64 then
  265. P.Options.Add('-Fu'+CompilerDir+'/loongarch64');
  266. if llvm then
  267. begin
  268. P.Options.Add('-Fu'+CompilerDir+'/llvm');
  269. P.Options.Add('-Fi'+CompilerDir+'/llvm');
  270. end;
  271. { powerpc64-aix compiled IDE needs -CTsmalltoc option }
  272. if (Defaults.OS=aix) and (Defaults.CPU=powerpc64) then
  273. P.Options.Add('-CTsmalltoc');
  274. { Handle SPECIALLINK environment variable if available }
  275. s:=GetEnvironmentVariable('SPECIALLINK');
  276. if s<>'' then
  277. P.Options.Add(s);
  278. P.Options.Add('-Sg');
  279. P.IncludePath.Add('compiler');
  280. T:=P.Targets.AddProgram('fp.pas');
  281. if CompilerTarget<>Defaults.CPU then
  282. begin
  283. T.SetExeName(AddProgramExtension(CPUToString(CompilerTarget)+'-fp',Defaults.BuildOS));
  284. P.SetUnitsOutputDir(P.GetUnitsOutputDir(Defaults.BuildTarget)+CPUToString(CompilerTarget));
  285. P.Options.Add('-dCROSSGDB');
  286. end;
  287. with T.Dependencies do
  288. begin
  289. AddUnit('compunit');
  290. end;
  291. T:=P.Targets.AddUnit('compunit.pas');
  292. T.Directory:='compiler';
  293. T.Install:=false;
  294. if (OSToString(defaults.OS)=lowercase({$I %FPCTARGETOS%})) and
  295. (CPUToString(defaults.CPU)=lowercase({$I %FPCTARGETCPU%})) then
  296. begin
  297. P.InstallFiles.Add('fp.ans','$(bininstalldir)');
  298. P.InstallFiles.Add('gplprog.pt','$(bininstalldir)');
  299. P.InstallFiles.Add('gplunit.pt','$(bininstalldir)');
  300. P.InstallFiles.Add('program.pt','$(bininstalldir)');
  301. P.InstallFiles.Add('unit.pt','$(bininstalldir)');
  302. P.InstallFiles.Add('cvsco.tdf','$(bininstalldir)');
  303. P.InstallFiles.Add('cvsdiff.tdf','$(bininstalldir)');
  304. P.InstallFiles.Add('cvsup.tdf','$(bininstalldir)');
  305. P.InstallFiles.Add('grep.tdf','$(bininstalldir)');
  306. P.InstallFiles.Add('tpgrep.tdf','$(bininstalldir)');
  307. P.InstallFiles.Add('fp32.ico', [win32, win64], '$(bininstalldir)');
  308. end;
  309. with P.Sources do
  310. begin
  311. AddDoc('readme.ide');
  312. AddSrc('README.txt');
  313. AddSrc('TODO.txt');
  314. AddSrc('fp.ans');
  315. AddSrcFiles('*.tdf',P.Directory);
  316. AddSrcFiles('*.pas',P.Directory,true);
  317. AddSrcFiles('*.inc',P.Directory,true);
  318. AddSrcFiles('*.rc',P.Directory);
  319. AddSrcFiles('*.ico',P.Directory);
  320. AddSrcFiles('*.term',P.Directory);
  321. AddSrcFiles('*.pt',P.Directory);
  322. end;
  323. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.ppu');
  324. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.ppu');
  325. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.ppu');
  326. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.ppu');
  327. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.ppu');
  328. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.o');
  329. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.o');
  330. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.o');
  331. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.o');
  332. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.o');
  333. P.BeforeCompileProc:=@ide_check_gdb_availability;
  334. P.NamespaceMap:='namespaces.lst';
  335. end;
  336. end;
  337. end;
  338. {$ifndef ALLPACKAGES}
  339. begin
  340. If Assigned(Installer) and not Defaults.Namespaces then
  341. begin
  342. add_ide_comandlineoptions();
  343. add_ide('');
  344. Installer.Run;
  345. end;
  346. end.
  347. {$endif ALLPACKAGES}