* no -- before commands

* fixed auto-detect of baseinstalldir

git-svn-id: trunk@6568 -
This commit is contained in:
peter 2007-02-19 22:21:45 +00:00
parent 7fa93d8b1a
commit 03625cee19
3 changed files with 112 additions and 95 deletions

View File

@ -1,8 +1,10 @@
Const Const
// Aliases // Aliases
AmD64 = X86_64; Amd64 = X86_64;
PowerPC = PPC; PowerPC = PPC;
dos = go32v2; PowerPC64 = PPC64;
DOS = Go32v2;
MacOSX = Darwin;
AllOSs = [Low(TOS)..High(TOS)]; AllOSs = [Low(TOS)..High(TOS)];
AllCPUs = [Low(TCPU)..High(TCPU)]; AllCPUs = [Low(TCPU)..High(TCPU)];
@ -21,6 +23,7 @@ Const
ExeExt = '.exe'; ExeExt = '.exe';
ZipExt = '.zip'; ZipExt = '.zip';
{
// Targets // Targets
i386_Linux = 'i386-linux'; i386_Linux = 'i386-linux';
i386_Win32 = 'i386-win32'; i386_Win32 = 'i386-win32';
@ -38,9 +41,9 @@ Const
arm_linux = 'arm-linux'; arm_linux = 'arm-linux';
ppc_macos = 'ppc-macos'; ppc_macos = 'ppc-macos';
ppc_darwin = 'ppc-darwin'; ppc_darwin = 'ppc-darwin';
}
UnitTargets = [ttUnit,ttExampleUnit]; UnitTargets = [ttUnit,ttExampleUnit];
ProgramTargets = [ttProgram,ttExampleProgram]; ProgramTargets = [ttProgram,ttExampleProgram];
AllMessages = [vlError,vlWarning,vlInfo,vlCompare,vlCommand]; AllMessages = [vlError,vlWarning,vlInfo,vlCompare,vlCommand];

View File

@ -11,14 +11,14 @@ Type
ftSharedLibrary); ftSharedLibrary);
TFileTypes = set of TFileType; TFileTypes = set of TFileType;
TOS = (Amiga,Atari,Darwin,FreeBSD,Go32v2,Linux,MacOS,MorphOS,NetBSD, TOS = (osNone,Amiga,Atari,Darwin,FreeBSD,Go32v2,Linux,MacOS,MorphOS,NetBSD,
Netware,NetwLibc,OpenBSD,OS2,PalmOS,Solaris,Win32,Win64,wince,Emx); Netware,NetwLibc,OpenBSD,OS2,PalmOS,Solaris,Win32,Win64,WinCE,Emx);
TOSes = Set of TOS; TOSes = Set of TOS;
TCPU = (Arm,I386,PPC,SPARC,X86_64,m68k); TCPU = (cpuNone,Arm,I386,PPC,SPARC,X86_64,M68K,PPC64);
TCPUS = Set of TCPU; TCPUS = Set of TCPU;
TCompilerMode = (FPC,TP,ObjFPC,Delphi,MacPas); TCompilerMode = (cmFPC,cmTP,cmObjFPC,cmDelphi,cmMacPas);
TCompilerModes = Set of TCompilerMode; TCompilerModes = Set of TCompilerMode;
TTargetType = (ttUnit,ttProgram,ttExampleUnit,ttExampleProgram); TTargetType = (ttUnit,ttProgram,ttExampleUnit,ttExampleProgram);

View File

@ -8,31 +8,7 @@ Interface
uses SysUtils,Classes,fpmktype; uses SysUtils,Classes,fpmktype;
Type Type
// aliases for easy use and backwards compatibility. TRunMode = (rmCompile,rmBuild,rmInstall,rmArchive,rmClean,rmManifest);
TFileType = fpmktype.TFileType;
TFileTypes = fpmktype.TFileTypes;
TOS = fpmktype.TOS;
TOSes = fpmktype.TOSes;
TCPU = fpmkType.TCPU;
TCPUS = fpmktype.TCPUS;
TCompilerMode = fpmktype.TCompilerMode;
TCompilerModes = fpmktype.TCompilerModes;
TTargetType = fpmktype.TTargetType;
TTargetTypes = fpmktype.TTargetTypes;
TTargetState = fpmktype.TTargetState;
TTargetStates = fpmktype.TTargetStates;
TVerboseLevel = fpmktype.TVerboseLevel;
TVerboseLevels = fpmktype.TVerboseLevels;
TLogEvent = fpmktype.TLogEvent;
TRunMode = (rmHelp,rmCompile,rmBuild,rmInstall,rmArchive,rmClean,rmManifest);
{ TNamedItem } { TNamedItem }
@ -336,6 +312,7 @@ Type
FCPU: TCPU; FCPU: TCPU;
FOS: TOS; FOS: TOS;
FMode : TCompilerMode; FMode : TCompilerMode;
FCompilerVersion : String;
FPrefix: String; FPrefix: String;
FBaseInstallDir, FBaseInstallDir,
FUnitInstallDir, FUnitInstallDir,
@ -362,6 +339,7 @@ Type
Constructor Create; Constructor Create;
Procedure InitDefaults; Procedure InitDefaults;
Procedure Assign(ASource : TPersistent);override; Procedure Assign(ASource : TPersistent);override;
procedure CompilerDefaults;
Procedure LocalInit(Const AFileName : String); Procedure LocalInit(Const AFileName : String);
Procedure LoadFromFile(Const AFileName : String); Procedure LoadFromFile(Const AFileName : String);
Procedure SaveToFile(Const AFileName : String); Procedure SaveToFile(Const AFileName : String);
@ -689,7 +667,7 @@ ResourceString
// Help messages for usage // Help messages for usage
SValue = 'Value'; SValue = 'Value';
SHelpUSage = 'command [options]'; SHelpUsage = 'Usage: %s command [options]';
SHelpCommand = 'Where command is one of the following:'; SHelpCommand = 'Where command is one of the following:';
SHelpCompile = 'Compile all units in the package(s).'; SHelpCompile = 'Compile all units in the package(s).';
SHelpBuild = 'Build all units in the package(s).'; SHelpBuild = 'Build all units in the package(s).';
@ -1132,13 +1110,7 @@ begin
If (FCompiler<>'') then If (FCompiler<>'') then
Result:=FCompiler Result:=FCompiler
else else
Case CPU of Result:='fpc';
i386 : Result:='ppc386';
PowerPC : Result:='ppcppc';
sparc : Result:='ppcsparc';
arm : Result:='ppcarm';
x86_64 : Result:='ppcx64';
end;
end; end;
function TDefaults.GetDocInstallDir: String; function TDefaults.GetDocInstallDir: String;
@ -1166,7 +1138,7 @@ end;
function TDefaults.GetUnitInstallDir: String; function TDefaults.GetUnitInstallDir: String;
begin begin
If (FUnitInstallDir<>'') then If (FUnitInstallDir<>'') then
Result:=FBinInstallDir Result:=FUnitInstallDir
else else
If UnixPaths then If UnixPaths then
Result:=BaseInstallDir+PathDelim+'units'+PathDelim+Target Result:=BaseInstallDir+PathDelim+'units'+PathDelim+Target
@ -1232,10 +1204,6 @@ begin
{$else} {$else}
UnixPaths:=False; UnixPaths:=False;
{$endif} {$endif}
// Code to init defaults for compiled platform.
CPU:=StringToCPU({$I %FPCTARGETCPU%});
OS:=StringToOS({$I %FPCTARGETOS%});
Compiler:='ppc386';
end; end;
procedure TDefaults.Assign(ASource: TPersistent); procedure TDefaults.Assign(ASource: TPersistent);
@ -1298,8 +1266,43 @@ begin
end; end;
end; end;
If (FN<>'') and FileExists(FN) then If (FN<>'') and FileExists(FN) then
LoadFromFile(FN) LoadFromFile(FN);
// Code to find local config file and load it using LoadFromFile. end;
procedure TDefaults.CompilerDefaults;
begin
if Compiler<>'' then
Compiler:='fpc';
if CPU=cpuNone then
CPU:=StringToCPU({$I %FPCTARGETCPU%});
if OS=osNone then
OS:=StringToOS({$I %FPCTARGETOS%});
if FCompilerVersion='' then
FCompilerVersion:='2.0.4';
if (FBaseInstallDir='') and (FPrefix='') then
begin
// Use the same algorithm as the compiler, see options.pas
{$ifdef Unix}
FBaseInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR'));
if FBaseInstallDir='' then
begin
FBaseInstallDir:='/usr/local/lib/fpc/'+FCompilerVersion;
if not DirectoryExists(FBaseInstallDir) and
DirectoryExists('/usr/lib/fpc/'+FCompilerVersion) then
FBaseInstallDir:='/usr/lib/fpc/'+FCompilerVersion;
end;
{$else unix}
FBaseInstallDir:=FixPath(GetEnvironmentVariable('FPCDIR'));
if FBaseInstallDir='' then
begin
FBaseInstallDir:=ExtractFilePath(FCompiler)+'..';
if not(DirectoryExists(FBaseInstallDir+'/units')) and
not(DirectoryExists(FBaseInstallDir+'/rtl')) then
FBaseInstallDir:=FBaseInstallDir+'..';
end;
{$endif unix}
end;
end; end;
procedure TDefaults.LoadFromFile(Const AFileName: String); procedure TDefaults.LoadFromFile(Const AFileName: String);
@ -1914,6 +1917,16 @@ procedure TInstaller.AnalyzeOptions;
Result:=(O='-'+short) or (O='--'+long) or (copy(O,1,Length(Long)+3)=('--'+long+'=')); Result:=(O='-'+short) or (O='--'+long) or (copy(O,1,Length(Long)+3)=('--'+long+'='));
end; end;
Function CheckCommand(Index : Integer;Short,Long : String): Boolean;
var
O : String;
begin
O:=Paramstr(Index);
Result:=(O='-'+short) or (O=long);
end;
Function OptionArg(Var Index : Integer) : String; Function OptionArg(Var Index : Integer) : String;
Var Var
@ -1955,20 +1968,20 @@ begin
While (I<ParamCount) do While (I<ParamCount) do
begin begin
Inc(I); Inc(I);
if Checkoption(I,'m','compile') then if CheckCommand(I,'m','compile') then
FRunMode:=rmCompile FRunMode:=rmCompile
else if Checkoption(I,'b','build') then else if CheckCommand(I,'b','build') then
FRunMode:=rmBuild FRunMode:=rmBuild
else if CheckOption(I,'i','install') then else if CheckCommand(I,'i','install') then
FRunMode:=rmInstall FRunMode:=rmInstall
else if CheckOption(I,'c','clean') then else if CheckCommand(I,'c','clean') then
FRunMode:=rmClean FRunMode:=rmClean
else if CheckOption(I,'a','archive') then else if CheckCommand(I,'a','archive') then
FRunMode:=rmarchive FRunMode:=rmarchive
else if CheckOption(I,'h','help') then else if CheckCommand(I,'M','manifest') then
FRunMode:=rmHelp
else if CheckOption(I,'M','manifest') then
FRunMode:=rmManifest FRunMode:=rmManifest
else if CheckOption(I,'h','help') then
Usage('',[])
else if Checkoption(I,'C','CPU') then else if Checkoption(I,'C','CPU') then
Defaults.CPU:=StringToCPU(OptionArg(I)) Defaults.CPU:=StringToCPU(OptionArg(I))
else if Checkoption(I,'O','OS') then else if Checkoption(I,'O','OS') then
@ -2002,6 +2015,7 @@ begin
end; end;
If Not NoDefaults then If Not NoDefaults then
Defaults.LocalInit(DefaultsFileName); Defaults.LocalInit(DefaultsFileName);
Defaults.CompilerDefaults;
{$ifdef debug} {$ifdef debug}
FLogLevels:=AllMessages; FLogLevels:=AllMessages;
{$endif} {$endif}
@ -2011,45 +2025,52 @@ end;
procedure TInstaller.Usage(FMT: String; Args: array of const); procedure TInstaller.Usage(FMT: String; Args: array of const);
Procedure WriteCmd(C: Char; LC : String; Msg : String); Procedure WriteCmd(LC : String; Msg : String);
begin begin
Writeln(stderr,'-',C,' --',LC,' ',MSG); Writeln(stderr,Format(' %-12s %s',[LC,MSG]));
end; end;
Procedure WriteOption(C: Char; LC : String; Msg : String); Procedure WriteOption(C: Char; LC : String; Msg : String);
begin begin
Writeln(stderr,'-',C,' --',LC,'=',SValue,' ',MSG); Writeln(stderr,Format(' -%s --%-16s %s',[C,LC,MSG]));
end;
Procedure WriteArgOption(C: Char; LC : String; Msg : String);
begin
Writeln(stderr,Format(' -%s --%-20s %s',[C,LC+'='+SValue,MSG]));
end; end;
begin begin
If (FMT<>'') then If (FMT<>'') then
Writeln(stderr,Format(Fmt,Args)); Writeln(stderr,Format(Fmt,Args));
Writeln(stderr,ExtractFileName(Paramstr(0)),' usage: '); Writeln(stderr,Format(SHelpUsage,[Paramstr(0)]));
Writeln(stderr,SHelpUsage);
Writeln(stderr,SHelpCommand); Writeln(stderr,SHelpCommand);
WriteCmd('m','compile',SHelpCompile); WriteCmd('compile',SHelpCompile);
WriteCmd('b','build',SHelpBuild); WriteCmd('build',SHelpBuild);
WriteCmd('i','install',SHelpInstall); WriteCmd('install',SHelpInstall);
WriteCmd('c','clean',SHelpClean); WriteCmd('clean',SHelpClean);
WriteCmd('a','archive',SHelpArchive); WriteCmd('archive',SHelpArchive);
WriteCmd('h','help',SHelpHelp); WriteCmd('manifest',SHelpManifest);
WriteCmd('M','manifest',SHelpManifest);
Writeln(stderr,SHelpCmdOptions); Writeln(stderr,SHelpCmdOptions);
WriteCmd('l','list-commands',SHelpList); WriteOption('h','help',SHelpHelp);
WriteCmd('n','nodefaults',SHelpNoDefaults); WriteOption('l','list-commands',SHelpList);
WriteCmd('v','verbose',SHelpVerbose); WriteOption('n','nodefaults',SHelpNoDefaults);
WriteOption('C','CPU',SHelpCPU); WriteOption('v','verbose',SHelpVerbose);
WriteOption('O','OS',SHelpOS); WriteArgOption('C','CPU',SHelpCPU);
WriteOption('t','target',SHelpTarget); WriteArgOption('O','OS',SHelpOS);
WriteOption('P','prefix',SHelpPrefix); WriteArgOption('t','target',SHelpTarget);
WriteOption('B','baseinstalldir',SHelpBaseInstalldir); WriteArgOption('P','prefix',SHelpPrefix);
WriteOption('r','compiler',SHelpCompiler); WriteArgOption('B','baseinstalldir',SHelpBaseInstalldir);
WriteOption('f','config',SHelpConfig); WriteArgOption('r','compiler',SHelpCompiler);
WriteArgOption('f','config',SHelpConfig);
Writeln(stderr,''); Writeln(stderr,'');
If (FMT<>'') then If (FMT<>'') then
halt(1); halt(1)
else
halt(0);
end; end;
procedure TInstaller.Compile(Force: Boolean); procedure TInstaller.Compile(Force: Boolean);
@ -2118,13 +2139,9 @@ Function TInstaller.Run : Boolean;
begin begin
Result:=True; Result:=True;
try try
If RunMode<>rmHelp then CheckPackages;
begin CreateBuildEngine;
CheckPackages;
CreateBuildEngine;
end;
Case RunMode of Case RunMode of
rmHelp : Usage('',[]);
rmCompile : Compile(False); rmCompile : Compile(False);
rmBuild : Compile(True); rmBuild : Compile(True);
rmInstall : Install; rmInstall : Install;
@ -2539,9 +2556,9 @@ begin
Result:='-FE.' // Make this relative to target directory. Result:='-FE.' // Make this relative to target directory.
else else
Result:='-FU'+RD; Result:='-FU'+RD;
If Target.Mode<>fpc then If Target.Mode<>cmFPC then
Result:=Result+' -M'+ModeToString(Target.Mode) Result:=Result+' -M'+ModeToString(Target.Mode)
else If Defaults.Mode<>fpc then else If Defaults.Mode<>cmFPC then
Result:=Result+' -M'+ModeToString(Defaults.Mode); Result:=Result+' -M'+ModeToString(Defaults.Mode);
If (Defaults.Options<>'') then If (Defaults.Options<>'') then
Result:=Result+' '+Defaults.Options; Result:=Result+' '+Defaults.Options;
@ -2782,7 +2799,6 @@ end;
Procedure TBuildEngine.InstallPackageFiles(APAckage : TPackage; tt : TTargetType; Const Src,Dest : String); Procedure TBuildEngine.InstallPackageFiles(APAckage : TPackage; tt : TTargetType; Const Src,Dest : String);
Var Var
I : Integer;
List : TStringList; List : TStringList;
begin begin
@ -2858,7 +2874,7 @@ procedure TBuildEngine.Archive(APackage: TPackage);
Var Var
L : TStrings; L : TStrings;
A,S,C,O : String; A : String;
begin begin
Log(vlInfo,SLogArchivingPackage,[APackage.Name]); Log(vlInfo,SLogArchivingPackage,[APackage.Name]);
@ -3129,7 +3145,7 @@ end;
function TTarget.GetProgramFileName(AnOS : TOS): String; function TTarget.GetProgramFileName(AnOS : TOS): String;
begin begin
if AnOS in [dos,win32,os2] then if AnOS in [Go32v2,Win32,Win64,OS2] then
Result:=Name+ExeExt Result:=Name+ExeExt
else else
Result:=Name; Result:=Name;
@ -3152,11 +3168,10 @@ end;
function TTarget.GetOutputFileName(AOs: TOS): String; function TTarget.GetOutputFileName(AOs: TOS): String;
begin begin
Result:=Name;
if TargetType in UnitTargets then if TargetType in UnitTargets then
Result:=Result+UnitExt Result:=GetUnitFileName
else if AOs in [Win32,dos,OS2] then else
Result:=Result+ExeExt Result:=GetProgramFileName(AOs);
end; end;
@ -3409,8 +3424,7 @@ function TDictionary.ReplaceStrings(Const ASource: String): String;
Var Var
S,FN,FV : String; S,FN,FV : String;
I,P: Integer; P: Integer;
O : TObject;
begin begin
Result:=''; Result:='';