fpmake.pp 12 KB

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