IDE: build IDE: merged calculating parameters

git-svn-id: trunk@48255 -
This commit is contained in:
mattias 2015-03-10 22:49:38 +00:00
parent 5be0415a8c
commit c71e215426

View File

@ -158,19 +158,21 @@ type
TLazarusBuilder = class TLazarusBuilder = class
private private
fProfile: TBuildLazarusProfile; fDefaultTargetCPU: string;
fDefaultTargetOS: String;
fExtraOptions: string; fExtraOptions: string;
fPackageOptions: string;
fMacros: TTransferMacroList; fMacros: TTransferMacroList;
fUpdateRevInc: boolean;
fOutputDirRedirected: boolean; fOutputDirRedirected: boolean;
fTargetOS: string; fPackageOptions: string;
fTargetCPU: string; fProfile: TBuildLazarusProfile;
fTargetFilename: string; // = fTargetDir + 'lazarus'+GetExecutableExt(fTargetOS)
fTargetDir: string;
fUnitOutDir: string;
fWorkingDir: string;
fProfileChanged: boolean; fProfileChanged: boolean;
fTargetCPU: string;
fTargetDir: string;
fTargetFilename: string; // = fTargetDir + 'lazarus'+GetExecutableExt(fTargetOS)
fTargetOS: string;
fUnitOutDir: string;
fUpdateRevInc: boolean;
fWorkingDir: string;
// Methods used by MakeLazarus : // Methods used by MakeLazarus :
procedure ApplyCleanOnce; procedure ApplyCleanOnce;
function CheckDirectoryWritable(Dir: string): boolean; function CheckDirectoryWritable(Dir: string): boolean;
@ -189,7 +191,7 @@ type
function CreateAppleBundle: TModalResult; function CreateAppleBundle: TModalResult;
procedure AppendExtraOption(const aOption: string; EncloseIfSpace: boolean = True); procedure AppendExtraOption(const aOption: string; EncloseIfSpace: boolean = True);
// This is used by MakeLazarus and SaveIDEMakeOptions // This is used by MakeLazarus and SaveIDEMakeOptions
function CreateIDEMakeOptions(Flags: TBuildLazarusFlags): TModalResult; function PrepareTargetDir(Flags: TBuildLazarusFlags): TModalResult;
public public
constructor Create; constructor Create;
function ShowConfigureBuildLazarusDlg(AProfiles: TBuildLazarusProfiles): TModalResult; function ShowConfigureBuildLazarusDlg(AProfiles: TBuildLazarusProfiles): TModalResult;
@ -413,8 +415,10 @@ var
IdeBuildMode: TIdeBuildMode; IdeBuildMode: TIdeBuildMode;
s: String; s: String;
begin begin
// Get target files and directories.
Result:=mrCancel; Result:=mrCancel;
fProfile:=Profile; fProfile:=Profile;
if CalcTargets(Flags)<>mrOk then exit;
if LazarusIDE<>nil then if LazarusIDE<>nil then
LazarusIDE.MainBarSubTitle:=Profile.Name; LazarusIDE.MainBarSubTitle:=Profile.Name;
@ -446,15 +450,14 @@ begin
// add -w option to print leaving/entering messages of "make" // add -w option to print leaving/entering messages of "make"
CmdLineParams:=' -w'; CmdLineParams:=' -w';
// append target OS // append target OS
if Profile.TargetOS<>'' then if fTargetOS<>fDefaultTargetOS then
CmdLineParams+=' OS_TARGET='+Profile.FPCTargetOS+' OS_SOURCE='+Profile.FPCTargetOS; CmdLineParams+=' OS_TARGET='+fTargetOS+' OS_SOURCE='+fTargetOS;
// append target CPU // append target CPU
if Profile.TargetCPU<>'' then if fTargetCPU<>fDefaultTargetCPU then
CmdLineParams+=' CPU_TARGET='+Profile.FPCTargetCPU+' CPU_SOURCE='+Profile.FPCTargetCPU; CmdLineParams+=' CPU_TARGET='+fTargetCPU+' CPU_SOURCE='+fTargetCPU;
// append extra Profile // create target directory and bundle
fExtraOptions:=''; Result:=PrepareTargetDir(Flags);
Result:=CreateIDEMakeOptions(Flags);
if Result<>mrOk then exit; if Result<>mrOk then exit;
fWorkingDir:=EnvironmentOptions.GetParsedLazarusDirectory; fWorkingDir:=EnvironmentOptions.GetParsedLazarusDirectory;
@ -553,8 +556,8 @@ end;
function TLazarusBuilder.CalcTargets(Flags: TBuildLazarusFlags): TModalResult; function TLazarusBuilder.CalcTargets(Flags: TBuildLazarusFlags): TModalResult;
var var
DefaultTargetOS, DefaultTargetCPU: string;
LazDir, TargetLCLPlatform: string; LazDir, TargetLCLPlatform: string;
DefaultTargetFilename: String;
begin begin
Result:=mrOk; Result:=mrOk;
fOutputDirRedirected:=False; fOutputDirRedirected:=False;
@ -582,16 +585,16 @@ begin
fTargetFilename:=''; fTargetFilename:='';
fUnitOutDir:=''; fUnitOutDir:='';
CodeToolBoss.FPCDefinesCache.ConfigCaches.GetDefaultCompilerTarget( CodeToolBoss.FPCDefinesCache.ConfigCaches.GetDefaultCompilerTarget(
EnvironmentOptions.GetParsedCompilerFilename,'',DefaultTargetOS,DefaultTargetCPU); EnvironmentOptions.GetParsedCompilerFilename,'',fDefaultTargetOS,fDefaultTargetCPU);
if DefaultTargetOS='' then if fDefaultTargetOS='' then
DefaultTargetOS:=GetCompiledTargetOS; fDefaultTargetOS:=GetCompiledTargetOS;
if DefaultTargetCPU='' then if fDefaultTargetCPU='' then
DefaultTargetCPU:=GetCompiledTargetCPU; fDefaultTargetCPU:=GetCompiledTargetCPU;
fTargetOS:=fProfile.FPCTargetOS; fTargetOS:=fProfile.FPCTargetOS;
fTargetCPU:=fProfile.FPCTargetCPU; fTargetCPU:=fProfile.FPCTargetCPU;
TargetLCLPlatform:=LCLPlatformDirNames[fProfile.TargetPlatform]; TargetLCLPlatform:=LCLPlatformDirNames[fProfile.TargetPlatform];
if fTargetOS='' then fTargetOS:=DefaultTargetOS; if fTargetOS='' then fTargetOS:=fDefaultTargetOS;
if fTargetCPU='' then fTargetCPU:=DefaultTargetCPU; if fTargetCPU='' then fTargetCPU:=fDefaultTargetCPU;
LazDir:=EnvironmentOptions.GetParsedLazarusDirectory; LazDir:=EnvironmentOptions.GetParsedLazarusDirectory;
//DebugLn(['CalcTargets NewTargetOS=',fTargetOS,' NewTargetCPU=',fTargetCPU]); //DebugLn(['CalcTargets NewTargetOS=',fTargetOS,' NewTargetCPU=',fTargetCPU]);
@ -608,8 +611,8 @@ begin
end else begin end else begin
// no user defined target directory // no user defined target directory
// => find it automatically // => find it automatically
if (CompareText(fTargetOS,DefaultTargetOS)<>0) if (CompareText(fTargetOS,fDefaultTargetOS)<>0)
or (CompareText(fTargetCPU,DefaultTargetCPU)<>0) then or (CompareText(fTargetCPU,fDefaultTargetCPU)<>0) then
begin begin
// Case 2. crosscompiling the IDE // Case 2. crosscompiling the IDE
// lazarus.exe to <primary config dir>/bin/<fTargetCPU>-<fTargetOS> // lazarus.exe to <primary config dir>/bin/<fTargetCPU>-<fTargetOS>
@ -619,7 +622,7 @@ begin
fUnitOutDir:=AppendPathDelim(GetPrimaryConfigPath)+'units' fUnitOutDir:=AppendPathDelim(GetPrimaryConfigPath)+'units'
+PathDelim+fTargetCPU+'-'+fTargetOS+PathDelim+TargetLCLPlatform; +PathDelim+fTargetCPU+'-'+fTargetOS+PathDelim+TargetLCLPlatform;
debugln('CalcTargets Options.TargetOS=',fProfile.FPCTargetOS,' Options.TargetCPU=', debugln('CalcTargets Options.TargetOS=',fProfile.FPCTargetOS,' Options.TargetCPU=',
fProfile.FPCTargetCPU,' DefaultOS=',DefaultTargetOS,' DefaultCPU=',DefaultTargetCPU); fProfile.FPCTargetCPU,' DefaultOS=',fDefaultTargetOS,' DefaultCPU=',fDefaultTargetCPU);
end else begin end else begin
// -> normal compile for this platform // -> normal compile for this platform
@ -661,6 +664,40 @@ begin
// check if target file is default // check if target file is default
fOutputDirRedirected:=CompareFilenames(ChompPathDelim(LazDir), fOutputDirRedirected:=CompareFilenames(ChompPathDelim(LazDir),
ChompPathDelim(fTargetDir))<>0; ChompPathDelim(fTargetDir))<>0;
// write full file names and message ids
AppendExtraOption('-vbq');
if fUnitOutDir<>'' then
// FPC interpretes '\ ' as an escape for a space in a path on Windows,
// so make sure the directory doesn't end with the path delimiter.
AppendExtraOption('-FU'+ChompPathDelim(fUnitOutDir));
//debugln(['TLazarusBuilder.CreateIDEMakeOptions fTargetDir=',fTargetDir,' fOutputDirRedirected=',fOutputDirRedirected,' fTargetFilename=',fTargetFilename]);
if fOutputDirRedirected then
// FPC interpretes '\ ' as an escape for a space in a path on Windows,
// so make sure the directory doesn't end with the path delimiter.
AppendExtraOption('-FE'+ChompPathDelim(fTargetDir));
// Note: FPC automatically changes the last extension (append or replace)
// For example under linux, where executables don't need any extension
// fpc removes the last extension of the -o option.
DefaultTargetFilename:='lazarus'+GetExecutableExt(fTargetOS);
if CreateRelativePath(fTargetFilename,fTargetDir) <> DefaultTargetFilename then
AppendExtraOption('-o'+fTargetFilename);
{$IFDEF Windows}
if (fProfile.TargetPlatform=lpWin32)
and (Win32MajorVersion <=4)
and (Win32Platform = VER_PLATFORM_WIN32_WINDOWS) then
AppendExtraOption('-dWIN9XPLATFORM');
{$ENDIF}
// add package options for IDE
//DebugLn(['CreateIDEMakeOptions blfUseMakeIDECfg=',blfUseMakeIDECfg in FLags,' ExtraOptions="',fExtraOptions,'" ',fPackageOptions]);
if not (blfUseMakeIDECfg in Flags) then
AppendExtraOption(fPackageOptions,false);
//DebugLn(['CreateIDEMakeOptions ',MMDef.Name,' ',fExtraOptions]);
end; end;
procedure TLazarusBuilder.BackupExe(Flags: TBuildLazarusFlags); procedure TLazarusBuilder.BackupExe(Flags: TBuildLazarusFlags);
@ -755,14 +792,8 @@ begin
//DebugLn(['AppendExtraOption ',fExtraOptions]); //DebugLn(['AppendExtraOption ',fExtraOptions]);
end; end;
function TLazarusBuilder.CreateIDEMakeOptions(Flags: TBuildLazarusFlags): TModalResult; function TLazarusBuilder.PrepareTargetDir(Flags: TBuildLazarusFlags): TModalResult;
var
DefaultTargetFilename: string;
begin begin
// Get target files and directories.
Result:=CalcTargets(Flags);
if Result<>mrOk then exit;
// backup old exe // backup old exe
BackupExe(Flags); BackupExe(Flags);
@ -778,53 +809,21 @@ begin
// create apple bundle if needed // create apple bundle if needed
//debugln(['CreateIDEMakeOptions NewTargetDirectory=',fTargetDir]); //debugln(['CreateIDEMakeOptions NewTargetDirectory=',fTargetDir]);
if (compareText(fProfile.TargetOS,'darwin')=0) if (compareText(fTargetOS,'darwin')=0)
and fOutputDirRedirected and DirectoryIsWritableCached(fTargetDir) then and fOutputDirRedirected and DirectoryIsWritableCached(fTargetDir) then
begin begin
Result:=CreateAppleBundle; Result:=CreateAppleBundle;
if not (Result in [mrOk,mrIgnore]) then Exit; if not (Result in [mrOk,mrIgnore]) then Exit;
end; end;
// write full file names and message ids Result:=mrOk;
AppendExtraOption('-vbq');
if fUnitOutDir<>'' then
// FPC interpretes '\ ' as an escape for a space in a path on Windows,
// so make sure the directory doesn't end with the path delimiter.
AppendExtraOption('-FU'+ChompPathDelim(fUnitOutDir));
//debugln(['TLazarusBuilder.CreateIDEMakeOptions fTargetDir=',fTargetDir,' fOutputDirRedirected=',fOutputDirRedirected,' fTargetFilename=',fTargetFilename]);
if fOutputDirRedirected then
// FPC interpretes '\ ' as an escape for a space in a path on Windows,
// so make sure the directory doesn't end with the path delimiter.
AppendExtraOption('-FE'+ChompPathDelim(fTargetDir));
// Note: FPC automatically changes the last extension (append or replace)
// For example under linux, where executables don't need any extension
// fpc removes the last extension of the -o option.
DefaultTargetFilename:='lazarus'+GetExecutableExt(fTargetOS);
if CreateRelativePath(fTargetFilename,fTargetDir) <> DefaultTargetFilename then
AppendExtraOption('-o'+fTargetFilename);
{$IFDEF Windows}
if (fProfile.TargetPlatform=lpWin32)
and (Win32MajorVersion <=4)
and (Win32Platform = VER_PLATFORM_WIN32_WINDOWS) then
AppendExtraOption('-dWIN9XPLATFORM');
{$ENDIF}
// add package options for IDE
//DebugLn(['CreateIDEMakeOptions blfUseMakeIDECfg=',blfUseMakeIDECfg in FLags,' ExtraOptions="',fExtraOptions,'" ',fPackageOptions]);
if not (blfUseMakeIDECfg in Flags) then
AppendExtraOption(fPackageOptions,false);
//DebugLn(['CreateIDEMakeOptions ',MMDef.Name,' ',fExtraOptions]);
end; end;
function TLazarusBuilder.IsWriteProtected(Profile: TBuildLazarusProfile): Boolean; function TLazarusBuilder.IsWriteProtected(Profile: TBuildLazarusProfile): Boolean;
// Returns True if Lazarus installation directory is write protected. Now uses OutputDirRedirected info. // Returns True if Lazarus installation directory is write protected. Now uses OutputDirRedirected info.
begin begin
fProfile:=Profile; fProfile:=Profile;
CalcTargets([]); if CalcTargets([])<>mrOk then exit(false);
Result:=fOutputDirRedirected; Result:=fOutputDirRedirected;
end; end;
@ -883,9 +882,11 @@ var
fs: TFileStreamUTF8; fs: TFileStreamUTF8;
OptionsAsText: String; OptionsAsText: String;
begin begin
Result:=mrCancel;
fProfile:=Profile; fProfile:=Profile;
fExtraOptions:=''; if CalcTargets(Flags)<>mrOk then exit;
Result:=CreateIDEMakeOptions(Flags);
Result:=PrepareTargetDir(Flags);
if Result<>mrOk then exit; if Result<>mrOk then exit;
Filename:=GetMakeIDEConfigFilename; Filename:=GetMakeIDEConfigFilename;
try try