summaryrefslogtreecommitdiff
path: root/ide/fpmake.pp
blob: c467f54b91ae52dca14aa4ea012fc89352af4d9b (plain)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
{$ifndef ALLPACKAGES}
{$mode objfpc}{$H+}
program fpmake;

uses
  fpmkunit,
  sysutils;
{$endif ALLPACKAGES}

const
  NoGDBOption: boolean = false;

procedure ide_check_gdb_availability(Sender: TObject);

  function DetectLibGDBDir: string;

  var
    SearchPath: string;

  const
    LibGDBName = 'libgdb.a';

  begin
    result:='';
    // First look for the GDBLIBDIR environment variable
    SearchPath := GetEnvironmentVariable('GDBLIBDIR');
    if (SearchPath<>'') and DirectoryExists(SearchPath) and FileExists(IncludeTrailingPathDelimiter(SearchPath)+LibGDBName) then
      begin
        result:=IncludeTrailingPathDelimiter(SearchPath);
        exit;
      end;
    // Search in the default locations
    SearchPath := '..'+PathDelim+'libgdb'+PathDelim+OSToString(Defaults.OS)+PathDelim+CPUToString(Defaults.CPU)+PathDelim;
    if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
      begin
        result := SearchPath;
        exit;
      end;
    SearchPath := '..'+PathDelim+'libgdb'+PathDelim+OSToString(Defaults.OS)+PathDelim;
    if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
      begin
        result := SearchPath;
        exit;
      end;
    // No custom libgdb.a found, try using system default library if available
    SearchPath := '..'+PathDelim+'lib'+PathDelim;
    if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
      begin
        result := SearchPath;
        installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
        exit;
      end;
    SearchPath := '..'+PathDelim+'usr'+PathDelim+'lib'+PathDelim;
    if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
      begin
        result := SearchPath;
        installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
        exit;
      end;
    SearchPath := '..'+PathDelim+'usr'+PathDelim+'local'+PathDelim+'lib'+PathDelim;
    if DirectoryExists(SearchPath) and FileExists(SearchPath+LibGDBName) then
      begin
        result := SearchPath;
        installer.BuildEngine.Log(vlWarning, 'Using system default libgdb file located in '+Result);
        exit;
      end;
  end;

var
  s: string;
  GDBLibDir: string;
  P: TPackage;

begin
  P := sender as TPackage;
  with installer do
    begin
    if not (NoGDBOption) then
      begin
        // Detection of GDB.
        GDBLibDir := DetectLibGDBDir;
        if GDBLibDir<>'' then
          begin
            // Include GDB
            BuildEngine.log(vlCommand, 'LibGDB was found, build IDE with debugger support');
            if FileExists(GDBLibDir+'gdblib.inc') then
              begin
                P.Options.Add('-dUSE_GDBLIBINC');
                P.Options.Add('-I'+GDBLibDir);
              end;
            P.Options.Add('-Fl'+GDBLibDir);

            case Defaults.OS of
              win32,
              win64 :   begin
                          P.Options.Add('-Xe');
                          P.Options.Add('-k--allow-multiple-definition');
                        end;
              freebsd : begin
                          P.Options.Add('-Fl/usr/local/lib');
                          P.Options.Add('-Xd');
                        end;
              openbsd : begin
                          P.Options.Add('-Fl/usr/local/lib');
                          P.Options.Add('-Fl/usr/lib');
                          P.Options.Add('-Xd');
                        end;
              netbsd  : P.Options.Add('-Xd');
              linux   : P.Options.Add('-Xd');
              aix     : begin
                          P.Options.Add('-Xd');
                          P.Options.Add('-Fl/opt/freeware/lib');
                          P.Options.Add('-k-bbigtoc');
                        end;
            end; {case}

            P.NeedLibc := true;
          end
        else
          begin
          BuildEngine.log(vlCommand, 'LibGDB was not found, IDE has no debugger support');
          P.Options.Add('-dNODEBUG');
          end;
      end
    else
      begin
      BuildEngine.log(vlCommand, 'Debugger support disabled');
      P.Options.Add('-dNODEBUG');
      end;
    end;
end;

procedure add_ide(const ADirectory: string);

Var
  P : TPackage;
  T : TTarget;
  CompilerTarget : TCpu;
  s: string;

begin
  AddCustomFpmakeCommandlineOption('CompilerTarget','Target CPU for the IDE''s compiler');
  AddCustomFpmakeCommandlineOption('NoGDB','If value=1 or ''Y'', no GDB support');
  With Installer do
    begin
    s := GetCustomFpmakeCommandlineOptionValue('NoGDB');
    if (s='1') or (s='Y') then
     NoGDBOption := true;
    s :=GetCustomFpmakeCommandlineOptionValue('CompilerTarget');
    if s <> '' then
      CompilerTarget:=StringToCPU(s)
    else
      CompilerTarget:=Defaults.CPU;

    P:=AddPackage('ide');
    P.Version:='3.0.5';
{$ifdef ALLPACKAGES}
    P.Directory:=ADirectory;
{$endif ALLPACKAGES}

    P.Dependencies.Add('rtl-extra');
    P.Dependencies.Add('fv');
    P.Dependencies.Add('chm');
    { This one is only needed if DEBUG is set }
    P.Dependencies.Add('regexpr');
    if not (NoGDBOption) then
      P.Dependencies.Add('gdbint',AllOSes-AllAmigaLikeOSes);
    P.Dependencies.Add('graph',[go32v2]);

    P.SupportBuildModes:=[bmOneByOne];

    P.Options.Add('-Ur');
    P.Options.Add('-dNOCATCH');
    P.Options.Add('-dBrowserCol');
    P.Options.Add('-dGDB');

    P.Options.Add('-d'+CPUToString(CompilerTarget));
    P.Options.Add('-Fu../compiler');
    P.Options.Add('-Fu../compiler/'+CPUToString(CompilerTarget));
    P.Options.Add('-Fu../compiler/targets');
    P.Options.Add('-Fu../compiler/systems');
    P.Options.Add('-Fi../compiler/'+CPUToString(CompilerTarget));
    P.Options.Add('-Fi../compiler');

    if CompilerTarget in [x86_64, i386] then
      P.Options.Add('-Fu../compiler/x86');
    if CompilerTarget in [powerpc, powerpc64] then
      P.Options.Add('-Fu../compiler/ppcgen');
    if CompilerTarget = x86_64 then
      P.Options.Add('-dNOOPT');
    if CompilerTarget = mipsel then
      P.Options.Add('-Fu../compiler/mips');

    P.Options.Add('-Sg');
    P.IncludePath.Add('compiler');

    T:=P.Targets.AddProgram('fp.pas');
    with T.Dependencies do
     begin
      AddUnit('compunit');
     end;

    T:=P.Targets.AddUnit('compunit.pas');
    T.Directory:='compiler';
    T.Install:=false;

    P.InstallFiles.Add('fp.ans','$(bininstalldir)');
    P.InstallFiles.Add('gplprog.pt','$(bininstalldir)');
    P.InstallFiles.Add('gplunit.pt','$(bininstalldir)');
    P.InstallFiles.Add('program.pt','$(bininstalldir)');
    P.InstallFiles.Add('unit.pt','$(bininstalldir)');
    P.InstallFiles.Add('cvsco.tdf','$(bininstalldir)');
    P.InstallFiles.Add('cvsdiff.tdf','$(bininstalldir)');
    P.InstallFiles.Add('cvsup.tdf','$(bininstalldir)');
    P.InstallFiles.Add('grep.tdf','$(bininstalldir)');
    P.InstallFiles.Add('tpgrep.tdf','$(bininstalldir)');
    P.InstallFiles.Add('fp32.ico', [win32, win64], '$(bininstalldir)');

    with P.Sources do
     begin
      AddDoc('readme.ide');
      AddSrc('readme.txt');
      AddSrc('todo.txt');
      AddSrc('fp.ans');
      AddSrcFiles('*.tdf',P.Directory);
      AddSrcFiles('*.pas',P.Directory,true);
      AddSrcFiles('*.inc',P.Directory,true);
      AddSrcFiles('*.rc',P.Directory);
      AddSrcFiles('*.ico',P.Directory);
      AddSrcFiles('*.term',P.Directory);
      AddSrcFiles('*.pt',P.Directory);
     end;

    P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.ppu');
    P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.ppu');
    P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.ppu');
    P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.ppu');
    P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.ppu');
    P.CleanFiles.Add('$(UNITSOUTPUTDIR)ppheap.o');
    P.CleanFiles.Add('$(UNITSOUTPUTDIR)compiler.o');
    P.CleanFiles.Add('$(UNITSOUTPUTDIR)comphook.o');
    P.CleanFiles.Add('$(UNITSOUTPUTDIR)cpuinfo.o');
    P.CleanFiles.Add('$(UNITSOUTPUTDIR)browcol.o');

    P.BeforeCompileProc:=@ide_check_gdb_availability;
    end;
end;

{$ifndef ALLPACKAGES}
begin
  add_ide('');
  Installer.Run;
end.
{$endif ALLPACKAGES}