fpmake.pp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. {$ifndef ALLPACKAGES}
  2. {$mode objfpc}{$H+}
  3. program fpmake;
  4. uses fpmkunit, classes, sysutils;
  5. {$endif ALLPACKAGES}
  6. const
  7. GdbLibName = 'libgdb.a';
  8. MinGWGdbLibName = 'libmingw32.a';
  9. procedure BeforeCompile_gdbint(Sender: TObject);
  10. var
  11. L : TStrings;
  12. P : TPackage;
  13. GdbLibDir, GdbLibFile: string;
  14. GdbLibFound: boolean;
  15. GdbVerTarget: TTarget;
  16. HostOS: TOS;
  17. HostCPU: TCpu;
  18. begin
  19. P := Sender as TPackage;
  20. HostOS:=StringToOS({$I %FPCTARGETOS%});
  21. HostCPU:=StringToCPU({$I %FPCTARGETCPU%});
  22. // Search for a libgdb file.
  23. GdbLibFound:=false;
  24. // First try the environment setting GDBLIBDIR
  25. GdbLibDir := GetEnvironmentVariable('GDBLIBDIR');
  26. if (GdbLibDir<>'') and DirectoryExists(GdbLibDir) then
  27. begin
  28. GdbLibFile:=IncludeTrailingPathDelimiter(GdbLibDir)+GdbLibName;
  29. if not FileExists(GdbLibFile) then
  30. Installer.BuildEngine.Log(vlCommand,'GDBLIBDIR environment variable set, but libgdb not found. ('+GdbLibFile+')')
  31. else
  32. GdbLibFound:=true;
  33. end;
  34. // Try the default locations
  35. if not GdbLibFound then
  36. begin
  37. GdbLibDir:='..'+PathDelim+'..'+PathDelim+'libgdb';
  38. if DirectoryExists(GdbLibDir) then
  39. begin
  40. GdbLibDir:=GdbLibDir+PathDelim+OSToString(Defaults.OS);
  41. GdbLibFile:=GdbLibDir+PathDelim+GdbLibName;
  42. if FileExists(GdbLibFile) then
  43. GdbLibFound:=true
  44. else
  45. begin
  46. GdbLibDir:=GdbLibDir+PathDelim+CPUToString(Defaults.CPU);
  47. GdbLibFile:=GdbLibDir+PathDelim+GdbLibName;
  48. GdbLibFound:=FileExists(GdbLibFile);
  49. end;
  50. end;
  51. end;
  52. // When we're cross-compiling, running the gdbver executable to detect the
  53. // gdb-version is not possible, unless a i386-win32 to i386-go32v2 compilation
  54. // is performed.
  55. if GdbLibFound and
  56. (((Defaults.CPU=HostCPU) and (Defaults.OS=HostOS))
  57. or ((Defaults.CPU=i386) and (Defaults.OS=go32v2) and (HostOS=win32) and (HostCPU=i386))) then
  58. begin
  59. P.Options.Add('-Fl'+GdbLibDir);
  60. GdbVerTarget:=p.Targets.AddUnit('src'+PathDelim+'gdbver.pp');
  61. Installer.BuildEngine.ResolveFileNames(p,HostCPU,HostOS,false);
  62. Installer.BuildEngine.Log(vlCommand,'GDB-lib found, compiling and running gdbver to obtain GDB-version');
  63. Installer.BuildEngine.Compile(P,GdbVerTarget);
  64. p.Targets.Delete(GdbVerTarget.Index);
  65. Installer.BuildEngine.ExecuteCommand('src/gdbver','-o src/gdbver.inc');
  66. // Pass -dUSE_MINGW_GDB to the compiler when a MinGW gdb is used
  67. if FileExists(GdbLibDir+PathDelim+MinGWGdbLibName) then
  68. begin
  69. P.Options.Add('-dUSE_MINGW_GDB');
  70. Installer.BuildEngine.Log(vlCommand,'Using GDB (MinGW)')
  71. end
  72. else
  73. begin
  74. Installer.BuildEngine.Log(vlCommand,'Using GDB')
  75. end;
  76. end
  77. else
  78. begin
  79. // No suitable gdb found, use gdb_nogdb.inc
  80. L := TStringList.Create;
  81. try
  82. if P.Directory<>'' then
  83. L.values['src'+DirectorySeparator+'gdbver_nogdb.inc'] := IncludeTrailingPathDelimiter(P.Directory) +'src'+DirectorySeparator+'gdbver.inc'
  84. else
  85. L.values['src'+DirectorySeparator+'gdbver_nogdb.inc'] := 'src'+DirectorySeparator+'gdbver.inc';
  86. Installer.BuildEngine.cmdcopyfiles(L, Installer.BuildEngine.StartDir);
  87. finally
  88. L.Free;
  89. end;
  90. end;
  91. end;
  92. procedure AfterCompile_gdbint(Sender: TObject);
  93. var
  94. L : TStrings;
  95. begin
  96. // Remove the generated gdbver.inc
  97. L := TStringList.Create;
  98. try
  99. L.add(IncludeTrailingPathDelimiter(Installer.BuildEngine.StartDir)+'src/gdbver.inc');
  100. Installer.BuildEngine.CmdDeleteFiles(L);
  101. finally
  102. L.Free;
  103. end;
  104. end;
  105. procedure add_gdbint;
  106. Var
  107. P : TPackage;
  108. T : TTarget;
  109. begin
  110. With Installer do
  111. begin
  112. P:=AddPackage('gdbint');
  113. {$ifdef ALLPACKAGES}
  114. P.Directory:='gdbint';
  115. {$endif ALLPACKAGES}
  116. P.Version:='2.7.1';
  117. P.Author := 'Library : Cygnus, header: Peter Vreman';
  118. P.License := 'Library: GPL2 or later, header: LGPL with modification, ';
  119. P.HomepageURL := 'www.freepascal.org';
  120. P.Email := '';
  121. P.Description := 'Interface to libgdb, the GDB debugger in library format';
  122. P.NeedLibC:= true; // true for headers that indirectly link to libc?
  123. P.SourcePath.Add('src');
  124. P.IncludePath.Add('src');
  125. P.BeforeCompileProc:=@BeforeCompile_gdbint;
  126. P.AfterCompileProc:=@AfterCompile_gdbint;
  127. //
  128. // NOTE: the gdbver.inc dependancies gives warnings because the makefile.fpc
  129. // does a "cp src/gdbver_nogdb.inc src/gdbver.inc" to create it
  130. T:=P.Targets.AddUnit('gdbcon.pp');
  131. with T.Dependencies do
  132. begin
  133. AddUnit('gdbint');
  134. end;
  135. T:=P.Targets.AddUnit('gdbint.pp');
  136. with T.Dependencies do
  137. begin
  138. AddInclude('gdbver.inc');
  139. end;
  140. end;
  141. end;
  142. {$ifndef ALLPACKAGES}
  143. begin
  144. add_gdbint;
  145. Installer.Run;
  146. end.
  147. {$endif ALLPACKAGES}