2
This file is part of the Free Pascal Utilities
3
Copyright (c) 1999-2000 by the Free Pascal development team
5
See the file COPYING.FPC, included in this distribution,
6
for details about the copyright.
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.
12
**********************************************************************}
19
uses Classes, Sysutils, Inifiles, fprepos;
22
DefaultManifestFile = 'manifest.xml';
28
TPackagerOptions = Class(TPersistent)
32
FRemoteMirrorsLocation : String;
33
FLocalMirrorsLocation : String;
34
FRemoteRepository : String;
35
FLocalRepository : String;
40
FCurrentCompilerConfig,
41
FDefaultCompilerConfig : String;
42
// Compiler specific options
46
FCompilerVersion : 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);
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;
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;
93
Defaults : TPackagerOptions;
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}
111
DefaultRemoteRepository = 'file://'+{$I %HOME%}+'/repository/';
113
DefaultRemoteRepository = 'c:/repository/';
117
SDefaults = 'Defaults';
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';
141
constructor TPackagerOptions.Create;
147
function TPackagerOptions.GetOptString(Index: integer): String;
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;
169
procedure TPackagerOptions.SetOptString(Index: integer; const AValue: String);
171
If AValue=GetOptString(Index) then
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;
195
procedure TPackagerOptions.SetCompilerCPU(const AValue: TCPU);
197
if FCompilerCPU=AValue then
199
FCompilerCPU:=AValue;
204
procedure TPackagerOptions.SetCompilerOS(const AValue: TOS);
206
if FCompilerOS=AValue then
213
function TPackagerOptions.RemotePackagesFile:string;
215
Result:=FRemoteRepository+DefaultPackagesFile;
219
function TPackagerOptions.LocalPackagesFile:string;
221
Result:=FLocalRepository+DefaultPackagesFile;
225
function TPackagerOptions.LocalVersionsFile(CompilerConfig:String):string;
227
Result:=FLocalRepository+Format(DefaultVersionsFile,[CompilerConfig]);
230
Procedure TPackagerOptions.InitGlobalDefaults;
234
// Retrieve Local fppkg directory
238
if DirectoryExists('/usr/local/lib/fpc') then
239
LocalDir:='/usr/local/lib/fpc/fppkg/'
241
LocalDir:='/usr/lib/fpc/fppkg/';
244
LocalDir:=IncludeTrailingPathDelimiter(GetEnvironmentVariable('HOME'))+'.fppkg/';
246
// Change as needed on all OS-es...
247
LocalDir:=ExtractFilePath(Paramstr(0))+'fppkg'+PathDelim;
250
FBuildDir:=LocalDir+'build'+PathDelim;
251
FPackagesDir:=LocalDir+'packages'+PathDelim;
252
FCompilerConfigDir:=LocalDir+'config'+PathDelim;
253
FLocalMirrorsLocation:=LocalDir+DefaultMirrorFile;
254
FLocalRepository:=LocalDir;
256
FRemoteMirrorsLocation:=DefaultMirrorsLocation;
257
FRemoteRepository:=DefaultRemoteRepository;
259
FDefaultCompilerConfig:='default';
260
FCurrentCompilerConfig:=FDefaultCompilerConfig;
261
FDefaultVerbosity:='error,warning,info,debug,commands';
265
Procedure TPackagerOptions.InitCompilerDefaults;
267
infoSL : TStringList;
269
FCompiler:=FileSearch('fpc'+ExeExt,GetEnvironmentVariable('PATH'));
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
284
FInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR'));
285
if FInstallDir='' then
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+'/';
293
FInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR'));
294
if FInstallDir='' then
296
FInstallDir:=ExtractFilePath(FCompiler)+'../';
297
if not(DirectoryExists(FInstallDir+'/units')) and
298
not(DirectoryExists(FInstallDir+'/rtl')) then
299
FInstallDir:=FInstallDir+'../';
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);
311
procedure TPackagerOptions.LoadGlobalFromIni(Ini: TCustomIniFile);
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);
328
procedure TPackagerOptions.SaveGlobalToIni(Ini: TCustomIniFile);
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);
345
procedure TPackagerOptions.LoadGlobalFromFile(FileName: String);
349
Ini:=TMemIniFile.Create(FileName);
351
LoadGlobalFromIni(Ini);
358
procedure TPackagerOptions.SaveGlobalToFile(FileName: String);
362
Ini:=TIniFile.Create(FileName);
364
SaveGlobalToIni(Ini);
372
procedure TPackagerOptions.LoadCompilerFromIni(Ini: TCustomIniFile);
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));
387
procedure TPackagerOptions.SaveCompilerToIni(Ini: TCustomIniFile);
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);
402
procedure TPackagerOptions.LoadCompilerFromFile(FileName: String);
406
Ini:=TMemIniFile.Create(FileName);
408
LoadCompilerFromIni(Ini);
415
procedure TPackagerOptions.SaveCompilerToFile(FileName: String);
419
Ini:=TIniFile.Create(FileName);
421
SaveCompilerToIni(Ini);
429
Defaults:=TPackagerOptions.Create;
431
FreeAndNil(Defaults);