fpmake.pp 11 KB

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