~ubuntu-branches/debian/lenny/fpc/lenny

« back to all changes in this revision

Viewing changes to fpcsrc/utils/fppkg/pkgoptions.pp

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-05-17 17:12:11 UTC
  • mfrom: (3.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080517171211-9qi33xhd9evfa0kg
Tags: 2.2.0-dfsg1-9
[ Torsten Werner ]
* Add Mazen Neifer to Uploaders field.

[ Mazen Neifer ]
* Moved FPC sources into a version dependent directory from /usr/share/fpcsrc
  to /usr/share/fpcsrc/${FPCVERSION}. This allow installing more than on FPC
  release.
* Fixed far call issue in compiler preventing building huge binearies.
  (closes: #477743)
* Updated building dependencies, recomennded and suggested packages.
* Moved fppkg to fp-utils as it is just a helper tool and is not required by
  compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
    This file is part of the Free Pascal Utilities
 
3
    Copyright (c) 1999-2000 by the Free Pascal development team
 
4
 
 
5
    See the file COPYING.FPC, included in this distribution,
 
6
    for details about the copyright.
 
7
 
 
8
    This program is distributed in the hope that it will be useful,
 
9
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
11
 
 
12
 **********************************************************************}
 
13
{$mode objfpc}
 
14
{$h+}
 
15
unit pkgoptions;
 
16
 
 
17
interface
 
18
 
 
19
uses Classes, Sysutils, Inifiles, fprepos;
 
20
 
 
21
Const
 
22
  DefaultManifestFile      = 'manifest.xml';
 
23
 
 
24
Type
 
25
 
 
26
  { TPackagerOptions }
 
27
 
 
28
  TPackagerOptions = Class(TPersistent)
 
29
  private
 
30
    FDirty: Boolean;
 
31
    // Global options
 
32
    FRemoteMirrorsLocation : String;
 
33
    FLocalMirrorsLocation : String;
 
34
    FRemoteRepository : String;
 
35
    FLocalRepository : String;
 
36
    FCompilerConfigDir,
 
37
    FPackagesDir,
 
38
    FBuildDir : String;
 
39
    FDefaultVerbosity,
 
40
    FCurrentCompilerConfig,
 
41
    FDefaultCompilerConfig : String;
 
42
    // Compiler specific options
 
43
    FCompiler : String;
 
44
    FCompilerCPU: TCPU;
 
45
    FCompilerOS: TOS;
 
46
    FCompilerVersion : String;
 
47
    FInstallDir : String;
 
48
    // Compiler settings for compiling FPMake.pp
 
49
    FFPMakeCompiler : String;
 
50
    FFPMakeUnitDir : String;
 
51
    function GetOptString(Index: integer): String;
 
52
    procedure SetOptString(Index: integer; const AValue: String);
 
53
    procedure SetCompilerCPU(const AValue: TCPU);
 
54
    procedure SetCompilerOS(const AValue: TOS);
 
55
  Public
 
56
    Constructor Create;
 
57
    Procedure InitGlobalDefaults;
 
58
    Procedure LoadGlobalFromIni(Ini : TCustomIniFile); virtual;
 
59
    Procedure SaveGlobalToIni(Ini : TCustomIniFile); virtual;
 
60
    Procedure LoadGlobalFromFile(FileName : String);
 
61
    Procedure SaveGlobalToFile(FileName : String);
 
62
    Procedure InitCompilerDefaults;
 
63
    Procedure LoadCompilerFromIni(Ini : TCustomIniFile); virtual;
 
64
    Procedure SaveCompilerToIni(Ini : TCustomIniFile); virtual;
 
65
    Procedure LoadCompilerFromFile(FileName : String);
 
66
    Procedure SaveCompilerToFile(FileName : String);
 
67
    Property Dirty : Boolean Read FDirty;
 
68
    function RemotePackagesFile:string;
 
69
    function LocalPackagesFile:string;
 
70
    function LocalVersionsFile(CompilerConfig:String):string;
 
71
  Published
 
72
    Property RemoteMirrorsLocation : String Index 0 Read GetOptString Write SetOptString;
 
73
    Property LocalMirrorsLocation : String Index 1 Read GetOptString Write SetOptString;
 
74
    Property RemoteRepository : String Index 2 Read GetOptString Write SetOptString;
 
75
    Property LocalRepository : String Index 3 Read GetOptString Write SetOptString;
 
76
    Property BuildDir : String Index 5 Read GetOptString Write SetOptString;
 
77
    Property Compiler : String Index 6 Read GetOptString Write SetOptString;
 
78
    Property CompilerTarget : String Index 7 Read GetOptString Write SetOptString;
 
79
    Property DefaultCompilerConfig : String Index 8 Read GetOptString Write SetOptString;
 
80
    Property CompilerVersion : String Index 9 Read GetOptString Write SetOptString;
 
81
    Property InstallDir : String Index 10 Read GetOptString Write SetOptString;
 
82
    Property DefaultVerbosity : String Index 11 Read GetOptString Write SetOptString;
 
83
    Property PackagesDir : String Index 12 Read GetOptString Write SetOptString;
 
84
    Property CompilerConfigDir : String Index 13 Read GetOptString Write SetOptString;
 
85
    Property FPMakeCompiler : String Index 14 Read GetOptString Write SetOptString;
 
86
    Property FPMakeUnitDir : String Index 15 Read GetOptString Write SetOptString;
 
87
    Property CurrentCompilerConfig : String Index 16 Read GetOptString Write SetOptString;
 
88
    Property CompilerOS : TOS Read FCompilerOS Write SetCompilerOS;
 
89
    Property CompilerCPU : TCPU Read FCompilerCPU Write SetCompilerCPU;
 
90
  end;
 
91
 
 
92
var
 
93
  Defaults : TPackagerOptions;
 
94
 
 
95
Implementation
 
96
 
 
97
uses
 
98
{$ifdef unix}
 
99
  baseunix,
 
100
{$endif}
 
101
  pkgglobals,
 
102
  pkgmessages;
 
103
 
 
104
Const
 
105
  DefaultMirrorFile       = 'mirrors.xml';
 
106
  DefaultPackagesFile     = 'packages.xml';
 
107
  DefaultVersionsFile     = 'versions-%s.dat';
 
108
  DefaultMirrorsLocation  = 'http://www.freepascal.org/repository/'+DefaultMirrorFile;
 
109
{$warning TODO use real repository}
 
110
{$ifdef unix}
 
111
  DefaultRemoteRepository = 'file://'+{$I %HOME%}+'/repository/';
 
112
{$else}
 
113
  DefaultRemoteRepository = 'c:/repository/';
 
114
{$endif}
 
115
 
 
116
  // ini file keys
 
117
  SDefaults = 'Defaults';
 
118
 
 
119
  // Global config
 
120
  KeyLocalMirrorsLocation  = 'LocalMirrors';
 
121
  KeyRemoteMirrorsLocation = 'RemoteMirrors';
 
122
  KeyRemoteRepository      = 'RemoteRepository';
 
123
  KeyLocalRepository       = 'LocalRepository';
 
124
  KeyCompilerConfigDir     = 'CompilerConfigDir';
 
125
  KeyPackagesDir           = 'PackagesDir';
 
126
  KeyBuildDir              = 'BuildDir';
 
127
  KeyCompilerConfig        = 'CompilerConfig';
 
128
  KeyVerbosity             = 'Verbosity';
 
129
  // Compiler dependent config
 
130
  KeyInstallDir            = 'InstallDir';
 
131
  KeyCompiler              = 'Compiler' ;
 
132
  KeyCompilerOS            = 'OS';
 
133
  KeyCompilerCPU           = 'CPU';
 
134
  KeyCompilerVersion       = 'Version';
 
135
  KeyFPMakeCompiler        = 'FPMakeCompiler';
 
136
  KeyFPMakeUnitDir         = 'FPMakeUnitDir';
 
137
 
 
138
 
 
139
{ TPackagerOptions }
 
140
 
 
141
constructor TPackagerOptions.Create;
 
142
begin
 
143
  InitGlobalDefaults;
 
144
end;
 
145
 
 
146
 
 
147
function TPackagerOptions.GetOptString(Index: integer): String;
 
148
begin
 
149
  Case Index of
 
150
    0 : Result:=FRemoteMirrorsLocation;
 
151
    1 : Result:=FLocalMirrorsLocation;
 
152
    2 : Result:=FRemoteRepository;
 
153
    3 : Result:=FLocalRepository;
 
154
    5 : Result:=FBuildDir;
 
155
    6 : Result:=FCompiler;
 
156
    7 : Result:=MakeTargetString(CompilerCPU,CompilerOS);
 
157
    8 : Result:=FDefaultCompilerConfig;
 
158
    9 : Result:=FCompilerVersion;
 
159
   10 : Result:=FInstallDir;
 
160
   11 : Result:=FDefaultVerbosity;
 
161
   12 : Result:=FPackagesDir;
 
162
   13 : Result:=FCompilerConfigDir;
 
163
   14 : Result:=FFPMakeCompiler;
 
164
   15 : Result:=FFPMakeUnitDir;
 
165
   16 : Result:=FCurrentCompilerConfig;
 
166
  end;
 
167
end;
 
168
 
 
169
procedure TPackagerOptions.SetOptString(Index: integer; const AValue: String);
 
170
begin
 
171
  If AValue=GetOptString(Index) then
 
172
    Exit;
 
173
  Case Index of
 
174
    0 : FLocalMirrorsLocation:=AValue;
 
175
    1 : FRemoteMirrorsLocation:=AValue;
 
176
    2 : FRemoteRepository:=AValue;
 
177
    3 : FLocalRepository:=AValue;
 
178
    5 : FBuildDir:=FixPath(AValue);
 
179
    6 : FCompiler:=AValue;
 
180
    7 : StringToCPUOS(AValue,FCompilerCPU,FCompilerOS);
 
181
    8 : FDefaultCompilerConfig:=AValue;
 
182
    9 : FCompilerVersion:=AValue;
 
183
   10 : FInstallDir:=FixPath(AValue);
 
184
   11 : FDefaultVerbosity:=AValue;
 
185
   12 : FPackagesDir:=FixPath(AValue);
 
186
   13 : FCompilerConfigDir:=FixPath(AValue);
 
187
   14 : FFPMakeCompiler:=AValue;
 
188
   15 : FFPMakeUnitDir:=FixPath(AValue);
 
189
   16 : FCurrentCompilerConfig:=AValue;
 
190
  end;
 
191
  FDirty:=True;
 
192
end;
 
193
 
 
194
 
 
195
procedure TPackagerOptions.SetCompilerCPU(const AValue: TCPU);
 
196
begin
 
197
  if FCompilerCPU=AValue then
 
198
    exit;
 
199
  FCompilerCPU:=AValue;
 
200
  FDirty:=True;
 
201
end;
 
202
 
 
203
 
 
204
procedure TPackagerOptions.SetCompilerOS(const AValue: TOS);
 
205
begin
 
206
  if FCompilerOS=AValue then
 
207
    exit;
 
208
  FCompilerOS:=AValue;
 
209
  FDirty:=True;
 
210
end;
 
211
 
 
212
 
 
213
function TPackagerOptions.RemotePackagesFile:string;
 
214
begin
 
215
  Result:=FRemoteRepository+DefaultPackagesFile;
 
216
end;
 
217
 
 
218
 
 
219
function TPackagerOptions.LocalPackagesFile:string;
 
220
begin
 
221
  Result:=FLocalRepository+DefaultPackagesFile;
 
222
end;
 
223
 
 
224
 
 
225
function TPackagerOptions.LocalVersionsFile(CompilerConfig:String):string;
 
226
begin
 
227
  Result:=FLocalRepository+Format(DefaultVersionsFile,[CompilerConfig]);
 
228
end;
 
229
 
 
230
Procedure TPackagerOptions.InitGlobalDefaults;
 
231
var
 
232
  LocalDir : String;
 
233
begin
 
234
  // Retrieve Local fppkg directory
 
235
{$ifdef unix}
 
236
  if (fpGetUID=0) then
 
237
    begin
 
238
      if DirectoryExists('/usr/local/lib/fpc') then
 
239
        LocalDir:='/usr/local/lib/fpc/fppkg/'
 
240
      else
 
241
        LocalDir:='/usr/lib/fpc/fppkg/';
 
242
    end
 
243
  else
 
244
    LocalDir:=IncludeTrailingPathDelimiter(GetEnvironmentVariable('HOME'))+'.fppkg/';
 
245
{$else}
 
246
  // Change as needed on all OS-es...
 
247
  LocalDir:=ExtractFilePath(Paramstr(0))+'fppkg'+PathDelim;
 
248
{$endif}
 
249
  // Directories
 
250
  FBuildDir:=LocalDir+'build'+PathDelim;
 
251
  FPackagesDir:=LocalDir+'packages'+PathDelim;
 
252
  FCompilerConfigDir:=LocalDir+'config'+PathDelim;
 
253
  FLocalMirrorsLocation:=LocalDir+DefaultMirrorFile;
 
254
  FLocalRepository:=LocalDir;
 
255
  // Remote
 
256
  FRemoteMirrorsLocation:=DefaultMirrorsLocation;
 
257
  FRemoteRepository:=DefaultRemoteRepository;
 
258
  // Other config
 
259
  FDefaultCompilerConfig:='default';
 
260
  FCurrentCompilerConfig:=FDefaultCompilerConfig;
 
261
  FDefaultVerbosity:='error,warning,info,debug,commands';
 
262
end;
 
263
 
 
264
 
 
265
Procedure TPackagerOptions.InitCompilerDefaults;
 
266
var
 
267
  infoSL : TStringList;
 
268
begin
 
269
  FCompiler:=FileSearch('fpc'+ExeExt,GetEnvironmentVariable('PATH'));
 
270
  if FCompiler='' then
 
271
    Raise EPackagerError.Create(SErrMissingFPC);
 
272
  // Detect compiler version/target from -i option
 
273
  infosl:=TStringList.Create;
 
274
  infosl.Delimiter:=' ';
 
275
  infosl.DelimitedText:=GetCompilerInfo(FCompiler,'-iVTPTO');
 
276
  if infosl.Count<>3 then
 
277
    Raise EPackagerError.Create(SErrInvalidFPCInfo);
 
278
  FCompilerVersion:=infosl[0];
 
279
  FCompilerCPU:=StringToCPU(infosl[1]);
 
280
  FCompilerOS:=StringToOS(infosl[2]);
 
281
  Log(vDebug,SLogDetectedCompiler,[FCompiler,FCompilerVersion,MakeTargetString(FCompilerCPU,FCompilerOS)]);
 
282
  // Use the same algorithm as the compiler, see options.pas
 
283
{$ifdef Unix}
 
284
  FInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR'));
 
285
  if FInstallDir='' then
 
286
    begin
 
287
      FInstallDir:='/usr/local/lib/fpc/'+FCompilerVersion+'/';
 
288
      if not DirectoryExists(FInstallDir) and
 
289
         DirectoryExists('/usr/lib/fpc/'+FCompilerVersion) then
 
290
        FInstallDir:='/usr/lib/fpc/'+FCompilerVersion+'/';
 
291
    end;
 
292
{$else unix}
 
293
  FInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR'));
 
294
  if FInstallDir='' then
 
295
    begin
 
296
      FInstallDir:=ExtractFilePath(FCompiler)+'../';
 
297
      if not(DirectoryExists(FInstallDir+'/units')) and
 
298
         not(DirectoryExists(FInstallDir+'/rtl')) then
 
299
        FInstallDir:=FInstallDir+'../';
 
300
    end;
 
301
{$endif unix}
 
302
  Log(vDebug,SLogDetectedFPCDIR,[FInstallDir]);
 
303
  // Detect directory where fpmake units are located
 
304
  FFPMakeCompiler:=FCompiler;
 
305
  FFPMakeUnitDir:=FInstallDir+'units'+PathDelim+CompilerTarget+PathDelim+'fpmkunit'+PathDelim;
 
306
  if not DirectoryExists(FFPMakeUnitDir) then
 
307
    Log(vWarning,SWarnFPMKUnitNotFound);
 
308
end;
 
309
 
 
310
 
 
311
procedure TPackagerOptions.LoadGlobalFromIni(Ini: TCustomIniFile);
 
312
begin
 
313
 With Ini do
 
314
   begin
 
315
     FLocalMirrorsLocation:=ReadString(SDefaults,KeyLocalMirrorsLocation,FLocalMirrorsLocation);
 
316
     FRemoteMirrorsLocation:=ReadString(SDefaults,KeyRemoteMirrorsLocation,FRemoteMirrorsLocation);
 
317
     FRemoteRepository:=ReadString(SDefaults,KeyRemoteRepository,FRemoteRepository);
 
318
     FLocalRepository:=ReadString(SDefaults,KeyLocalRepository,FLocalRepository);
 
319
     FBuildDir:=FixPath(ReadString(SDefaults,KeyBuildDir,FBuildDir));
 
320
     FPackagesDir:=FixPath(ReadString(SDefaults,KeyPackagesDir,FPackagesDir));
 
321
     FCompilerConfigDir:=FixPath(ReadString(SDefaults,KeyCompilerConfigDir,FCompilerConfigDir));
 
322
     FDefaultCompilerConfig:=ReadString(SDefaults,KeyCompilerConfig,FDefaultCompilerConfig);
 
323
     FDefaultVerbosity:=ReadString(SDefaults,KeyVerbosity,FDefaultVerbosity);
 
324
   end;
 
325
end;
 
326
 
 
327
 
 
328
procedure TPackagerOptions.SaveGlobalToIni(Ini: TCustomIniFile);
 
329
begin
 
330
 With Ini do
 
331
   begin
 
332
     WriteString(SDefaults,KeyBuildDir,FBuildDir);
 
333
     WriteString(SDefaults,KeyPackagesDir,FPackagesDir);
 
334
     WriteString(SDefaults,KeyCompilerConfigDir,FCompilerConfigDir);
 
335
     WriteString(SDefaults,KeyLocalRepository,FLocalRepository);
 
336
     WriteString(SDefaults,KeyLocalMirrorsLocation,FLocalMirrorsLocation);
 
337
     WriteString(SDefaults,KeyRemoteMirrorsLocation,FRemoteMirrorsLocation);
 
338
     WriteString(SDefaults,KeyRemoteRepository,FRemoteRepository);
 
339
     WriteString(SDefaults,KeyCompilerConfig,FDefaultCompilerConfig);
 
340
     WriteString(SDefaults,KeyVerbosity,FDefaultVerbosity);
 
341
   end;
 
342
end;
 
343
 
 
344
 
 
345
procedure TPackagerOptions.LoadGlobalFromFile(FileName: String);
 
346
Var
 
347
  Ini : TMemIniFile;
 
348
begin
 
349
  Ini:=TMemIniFile.Create(FileName);
 
350
  try
 
351
    LoadGlobalFromIni(Ini);
 
352
  finally
 
353
    Ini.Free;
 
354
  end;
 
355
end;
 
356
 
 
357
 
 
358
procedure TPackagerOptions.SaveGlobalToFile(FileName: String);
 
359
Var
 
360
  Ini : TIniFile;
 
361
begin
 
362
  Ini:=TIniFile.Create(FileName);
 
363
  try
 
364
    SaveGlobalToIni(Ini);
 
365
    Ini.UpdateFile;
 
366
  finally
 
367
    Ini.Free;
 
368
  end;
 
369
end;
 
370
 
 
371
 
 
372
procedure TPackagerOptions.LoadCompilerFromIni(Ini: TCustomIniFile);
 
373
begin
 
374
 With Ini do
 
375
   begin
 
376
     FInstallDir:=FixPath(ReadString(SDefaults,KeyInstallDir,FInstallDir));
 
377
     FCompiler:=ReadString(SDefaults,KeyCompiler,FCompiler);
 
378
     FCompilerOS:=StringToOS(ReadString(SDefaults,KeyCompilerOS,OSToString(CompilerOS)));
 
379
     FCompilerCPU:=StringToCPU(ReadString(SDefaults,KeyCompilerCPU,CPUtoString(CompilerCPU)));
 
380
     FCompilerVersion:=ReadString(SDefaults,KeyCompilerVersion,FCompilerVersion);
 
381
     FFPMakeCompiler:=ReadString(SDefaults,KeyFPMakeCompiler,FFPMakeCompiler);
 
382
     FFPMakeUnitDir:=FixPath(ReadString(SDefaults,KeyFPMakeUnitDir,FFPMakeUnitDir));
 
383
   end;
 
384
end;
 
385
 
 
386
 
 
387
procedure TPackagerOptions.SaveCompilerToIni(Ini: TCustomIniFile);
 
388
begin
 
389
 With Ini do
 
390
   begin
 
391
     WriteString(SDefaults,KeyInstallDir,FInstallDir);
 
392
     WriteString(SDefaults,KeyCompiler,FCompiler);
 
393
     WriteString(SDefaults,KeyCompilerOS,OSToString(CompilerOS));
 
394
     WriteString(SDefaults,KeyCompilerCPU,CPUtoString(CompilerCPU));
 
395
     WriteString(SDefaults,KeyCompilerVersion,FCompilerVersion);
 
396
     WriteString(SDefaults,KeyFPMakeCompiler,FFPMakeCompiler);
 
397
     WriteString(SDefaults,KeyFPMakeUnitDir,FFPMakeUnitDir);
 
398
   end;
 
399
end;
 
400
 
 
401
 
 
402
procedure TPackagerOptions.LoadCompilerFromFile(FileName: String);
 
403
Var
 
404
  Ini : TMemIniFile;
 
405
begin
 
406
  Ini:=TMemIniFile.Create(FileName);
 
407
  try
 
408
    LoadCompilerFromIni(Ini);
 
409
  finally
 
410
    Ini.Free;
 
411
  end;
 
412
end;
 
413
 
 
414
 
 
415
procedure TPackagerOptions.SaveCompilerToFile(FileName: String);
 
416
Var
 
417
  Ini : TIniFile;
 
418
begin
 
419
  Ini:=TIniFile.Create(FileName);
 
420
  try
 
421
    SaveCompilerToIni(Ini);
 
422
    Ini.UpdateFile;
 
423
  finally
 
424
    Ini.Free;
 
425
  end;
 
426
end;
 
427
 
 
428
initialization
 
429
  Defaults:=TPackagerOptions.Create;
 
430
finalization
 
431
  FreeAndNil(Defaults);
 
432
end.