fpmake.pp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. end; {case}
  101. P.NeedLibc := true;
  102. end
  103. else
  104. begin
  105. BuildEngine.log(vlCommand, 'LibGDB was not found, IDE has no debugger support');
  106. P.Options.Add('-dNODEBUG');
  107. end;
  108. end
  109. else
  110. begin
  111. BuildEngine.log(vlCommand, 'Debugger support disabled');
  112. P.Options.Add('-dNODEBUG');
  113. end;
  114. end;
  115. end;
  116. procedure add_ide(const ADirectory: string);
  117. Var
  118. P : TPackage;
  119. T : TTarget;
  120. CompilerTarget : TCpu;
  121. s: string;
  122. begin
  123. AddCustomFpmakeCommandlineOption('CompilerTarget','Target CPU for the IDE''s compiler');
  124. AddCustomFpmakeCommandlineOption('NoGDB','If value=1 or ''Y'', no GDB support');
  125. With Installer do
  126. begin
  127. s := GetCustomFpmakeCommandlineOptionValue('NoGDB');
  128. if (s='1') or (s='Y') then
  129. NoGDBOption := true;
  130. s :=GetCustomFpmakeCommandlineOptionValue('CompilerTarget');
  131. if s <> '' then
  132. CompilerTarget:=StringToCPU(s)
  133. else
  134. CompilerTarget:=Defaults.CPU;
  135. P:=AddPackage('ide');
  136. P.Version:='2.7.1';
  137. {$ifdef ALLPACKAGES}
  138. P.Directory:=ADirectory;
  139. {$endif ALLPACKAGES}
  140. P.Dependencies.Add('rtl');
  141. P.Dependencies.Add('rtl-extra');
  142. P.Dependencies.Add('fv');
  143. P.Dependencies.Add('chm');
  144. { This one is only needed if DEBUG is set }
  145. P.Dependencies.Add('regexpr');
  146. if not (NoGDBOption) then
  147. P.Dependencies.Add('gdbint',AllOSes-[morphos]);
  148. P.Dependencies.Add('graph',[go32v2]);
  149. P.SupportBuildModes:=[bmOneByOne];
  150. P.Options.Add('-Ur');
  151. P.Options.Add('-dNOCATCH');
  152. P.Options.Add('-dBrowserCol');
  153. P.Options.Add('-dGDB');
  154. P.Options.Add('-d'+CPUToString(CompilerTarget));
  155. P.Options.Add('-Fu../compiler');
  156. P.Options.Add('-Fu../compiler/'+CPUToString(CompilerTarget));
  157. P.Options.Add('-Fu../compiler/targets');
  158. P.Options.Add('-Fu../compiler/systems');
  159. P.Options.Add('-Fi../compiler/'+CPUToString(CompilerTarget));
  160. P.Options.Add('-Fi../compiler');
  161. if CompilerTarget in [x86_64, i386] then
  162. P.Options.Add('-Fu../compiler/x86');
  163. if CompilerTarget in [powerpc, powerpc64] then
  164. P.Options.Add('-Fu../compiler/ppcgen');
  165. if CompilerTarget = x86_64 then
  166. P.Options.Add('-dNOOPT');
  167. if CompilerTarget = mipsel then
  168. P.Options.Add('-Fu../compiler/mips');
  169. P.Options.Add('-Sg');
  170. T:=P.Targets.AddProgram('fp.pas');
  171. T.Dependencies.AddUnit('compunit');
  172. T:=P.Targets.AddUnit('compunit.pas');
  173. T.Directory:='compiler';
  174. T.Install:=false;
  175. P.InstallFiles.Add('fp.ans','$(BININSTALLDIR)');
  176. P.InstallFiles.Add('gplprog.pt','$(BININSTALLDIR)');
  177. P.InstallFiles.Add('gplunit.pt','$(BININSTALLDIR)');
  178. P.InstallFiles.Add('program.pt','$(BININSTALLDIR)');
  179. P.InstallFiles.Add('unit.pt','$(BININSTALLDIR)');
  180. P.InstallFiles.Add('cvsco.tdf','$(BININSTALLDIR)');
  181. P.InstallFiles.Add('cvsdiff.tdf','$(BININSTALLDIR)');
  182. P.InstallFiles.Add('cvsup.tdf','$(BININSTALLDIR)');
  183. P.InstallFiles.Add('grep.tdf','$(BININSTALLDIR)');
  184. P.InstallFiles.Add('tpgrep.tdf','$(BININSTALLDIR)');
  185. P.InstallFiles.Add('fp32.ico', [win32, win64], '$(BININSTALLDIR)');
  186. P.Sources.AddDoc('readme.ide');
  187. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.ppu');
  188. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.ppu');
  189. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.ppu');
  190. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.ppu');
  191. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.ppu');
  192. P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.o');
  193. P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.o');
  194. P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.o');
  195. P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.o');
  196. P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.o');
  197. P.BeforeCompileProc:=@ide_check_gdb_availability;
  198. end;
  199. end;
  200. {$ifndef ALLPACKAGES}
  201. begin
  202. add_ide('');
  203. Installer.Run;
  204. end.
  205. {$endif ALLPACKAGES}