fpmake.pp 13 KB

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