fpmake.pp 12 KB

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