fpmake.pp 13 KB

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