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