fpmake.pp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. procedure ide_check_gdb_availability(Sender: TObject);
  11. function DetectLibGDBDir: string;
  12. var
  13. SearchPath: string;
  14. const
  15. LibGDBName = 'libgdb.a';
  16. begin
  17. result:='';
  18. // First look for the GDBLIBDIR environment variable
  19. SearchPath := GetEnvironmentVariable('GDBLIBDIR');
  20. if (SearchPath<>'') and DirectoryExists(SearchPath) and FileExists(IncludeTrailingPathDelimiter(SearchPath)+LibGDBName) then
  21. begin
  22. result:=IncludeTrailingPathDelimiter(SearchPath);
  23. exit;
  24. end;
  25. // Search in the default locations
  26. SearchPath := '..'+PathDelim+'libgdb'+PathDelim+OSToString(Defaults.OS)+PathDelim+CPUToString(Defaults.CPU)+PathDelim;
  27. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  28. begin
  29. result := SearchPath;
  30. exit;
  31. end;
  32. SearchPath := '..'+PathDelim+'libgdb'+PathDelim+OSToString(Defaults.OS)+PathDelim;
  33. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  34. begin
  35. result := SearchPath;
  36. exit;
  37. end;
  38. // No custom libgdb.a found, try using system default library if available
  39. SearchPath := '..'+PathDelim+'lib'+PathDelim;
  40. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  41. begin
  42. result := SearchPath;
  43. installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
  44. exit;
  45. end;
  46. SearchPath := '..'+PathDelim+'usr'+PathDelim+'lib'+PathDelim;
  47. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  48. begin
  49. result := SearchPath;
  50. installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
  51. exit;
  52. end;
  53. SearchPath := '..'+PathDelim+'usr'+PathDelim+'local'+PathDelim+'lib'+PathDelim;
  54. if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
  55. begin
  56. result := SearchPath;
  57. installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
  58. exit;
  59. end;
  60. end;
  61. var
  62. s: string;
  63. GDBLibDir: string;
  64. P: TPackage;
  65. begin
  66. P := sender as TPackage;
  67. with installer do
  68. begin
  69. if not (NoGDBOption) then
  70. begin
  71. // Detection of GDB.
  72. GDBLibDir := DetectLibGDBDir;
  73. if GDBLibDir<>'' then
  74. begin
  75. // Include GDB
  76. BuildEngine.log(vlCommand, 'LibGDB was found, build IDE with debugger support');
  77. if FileExists(GDBLibDir+'gdblib.inc') then
  78. begin
  79. P.Options.Add('-dUSE_GDBLIBINC');
  80. P.Options.Add('-I'+GDBLibDir);
  81. end;
  82. P.Options.Add('-Fl'+GDBLibDir);
  83. case Defaults.OS of
  84. win32,
  85. win64 : begin
  86. P.Options.Add('-Xe');
  87. P.Options.Add('-k--allow-multiple-definition');
  88. end;
  89. freebsd : begin
  90. P.Options.Add('-Fl/usr/local/lib');
  91. P.Options.Add('-Xd');
  92. end;
  93. openbsd : begin
  94. P.Options.Add('-Fl/usr/local/lib');
  95. P.Options.Add('-Fl/usr/lib');
  96. P.Options.Add('-Xd');
  97. end;
  98. netbsd : P.Options.Add('-Xd');
  99. linux : P.Options.Add('-Xd');
  100. aix : begin
  101. P.Options.Add('-Xd');
  102. P.Options.Add('-Fl/opt/freeware/lib');
  103. P.Options.Add('-k-bbigtoc');
  104. end;
  105. end; {case}
  106. P.NeedLibc := true;
  107. end
  108. else
  109. begin
  110. BuildEngine.log(vlCommand, 'LibGDB was not found, IDE has no debugger support');
  111. P.Options.Add('-dNODEBUG');
  112. end;
  113. end
  114. else
  115. begin
  116. BuildEngine.log(vlCommand, 'Debugger support disabled');
  117. P.Options.Add('-dNODEBUG');
  118. end;
  119. end;
  120. end;
  121. procedure add_ide(const ADirectory: string);
  122. Var
  123. P : TPackage;
  124. T : TTarget;
  125. CompilerTarget : TCpu;
  126. s: string;
  127. begin
  128. AddCustomFpmakeCommandlineOption('CompilerTarget','Target CPU for the IDE''s compiler');
  129. AddCustomFpmakeCommandlineOption('NoGDB','If value=1 or ''Y'', no GDB support');
  130. With Installer do
  131. begin
  132. s := GetCustomFpmakeCommandlineOptionValue('NoGDB');
  133. if (s='1') or (s='Y') then
  134. NoGDBOption := true;
  135. s :=GetCustomFpmakeCommandlineOptionValue('CompilerTarget');
  136. if s <> '' then
  137. CompilerTarget:=StringToCPU(s)
  138. else
  139. CompilerTarget:=Defaults.CPU;
  140. P:=AddPackage('ide');
  141. P.Version:='3.0.4';
  142. {$ifdef ALLPACKAGES}
  143. P.Directory:=ADirectory;
  144. {$endif ALLPACKAGES}
  145. P.Dependencies.Add('rtl-extra');
  146. P.Dependencies.Add('fv');
  147. P.Dependencies.Add('chm');
  148. { This one is only needed if DEBUG is set }
  149. P.Dependencies.Add('regexpr');
  150. if not (NoGDBOption) then
  151. P.Dependencies.Add('gdbint',AllOSes-AllAmigaLikeOSes);
  152. P.Dependencies.Add('graph',[go32v2]);
  153. P.SupportBuildModes:=[bmOneByOne];
  154. P.Options.Add('-Ur');
  155. P.Options.Add('-dNOCATCH');
  156. P.Options.Add('-dBrowserCol');
  157. P.Options.Add('-dGDB');
  158. P.Options.Add('-d'+CPUToString(CompilerTarget));
  159. P.Options.Add('-Fu../compiler');
  160. P.Options.Add('-Fu../compiler/'+CPUToString(CompilerTarget));
  161. P.Options.Add('-Fu../compiler/targets');
  162. P.Options.Add('-Fu../compiler/systems');
  163. P.Options.Add('-Fi../compiler/'+CPUToString(CompilerTarget));
  164. P.Options.Add('-Fi../compiler');
  165. if CompilerTarget in [x86_64, i386] then
  166. P.Options.Add('-Fu../compiler/x86');
  167. if CompilerTarget in [powerpc, powerpc64] then
  168. P.Options.Add('-Fu../compiler/ppcgen');
  169. if CompilerTarget = x86_64 then
  170. P.Options.Add('-dNOOPT');
  171. if CompilerTarget = mipsel then
  172. P.Options.Add('-Fu../compiler/mips');
  173. P.Options.Add('-Sg');
  174. P.IncludePath.Add('compiler');
  175. T:=P.Targets.AddProgram('fp.pas');
  176. with T.Dependencies do
  177. begin
  178. AddUnit('compunit');
  179. end;
  180. T:=P.Targets.AddUnit('compunit.pas');
  181. T.Directory:='compiler';
  182. T.Install:=false;
  183. P.InstallFiles.Add('fp.ans','$(bininstalldir)');
  184. P.InstallFiles.Add('gplprog.pt','$(bininstalldir)');
  185. P.InstallFiles.Add('gplunit.pt','$(bininstalldir)');
  186. P.InstallFiles.Add('program.pt','$(bininstalldir)');
  187. P.InstallFiles.Add('unit.pt','$(bininstalldir)');
  188. P.InstallFiles.Add('cvsco.tdf','$(bininstalldir)');
  189. P.InstallFiles.Add('cvsdiff.tdf','$(bininstalldir)');
  190. P.InstallFiles.Add('cvsup.tdf','$(bininstalldir)');
  191. P.InstallFiles.Add('grep.tdf','$(bininstalldir)');
  192. P.InstallFiles.Add('tpgrep.tdf','$(bininstalldir)');
  193. P.InstallFiles.Add('fp32.ico', [win32, win64], '$(bininstalldir)');
  194. with P.Sources do
  195. begin
  196. AddDoc('readme.ide');
  197. AddSrc('readme.txt');
  198. AddSrc('todo.txt');
  199. AddSrc('fp.ans');
  200. AddSrcFiles('*.tdf',P.Directory);
  201. AddSrcFiles('*.pas',P.Directory,true);
  202. AddSrcFiles('*.inc',P.Directory,true);
  203. AddSrcFiles('*.rc',P.Directory);
  204. AddSrcFiles('*.ico',P.Directory);
  205. AddSrcFiles('*.term',P.Directory);
  206. AddSrcFiles('*.pt',P.Directory);
  207. end;
  208. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.ppu');
  209. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.ppu');
  210. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.ppu');
  211. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.ppu');
  212. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.ppu');
  213. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.o');
  214. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.o');
  215. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.o');
  216. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.o');
  217. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.o');
  218. P.BeforeCompileProc:=@ide_check_gdb_availability;
  219. end;
  220. end;
  221. {$ifndef ALLPACKAGES}
  222. begin
  223. add_ide('');
  224. Installer.Run;
  225. end.
  226. {$endif ALLPACKAGES}