fpmake.pp 6.9 KB

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