fpmake.pp 7.2 KB

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