📄 build.dpr
字号:
end;
end;
{******************************************************************************}
function GetNewestEdition: TEdition;
var
I: Integer;
ed: TEdition;
begin
Result := TEdition.Create('d5', '');
for I := High(Targets) downto 0 do
begin
ed := TEdition.Create(Targets[I].Name, Targets[I].PerDir);
try
if ed.Version >= Result.Version then
begin
if (Result.Version < ed.Version) or
{ prefer Delphi version instead of C++Builder version: }
((Result.Typ = BCB) and (ed.Typ <> BCB)) or
{ prefer the new version if the result is not valid (no root set) }
(Result.RootDir = '') then
begin
if ed.IsCLX then
Continue; // this is not a valid version
if (ed.RootDir <> '') and FileExists(ed.RootDir + '\bin\dcc32.exe') then
begin
Result.Free;
Result := ed;
ed := nil;
end
end;
end;
finally
ed.Free;
end;
end;
end;
{******************************************************************************}
function GetNewestEditionName: string;
var
ed: TEdition;
begin
ed := GetNewestEdition;
try
if ed <> nil then
Result := ed.Name
else
Result := '';
finally
ed.Free;
end;
end;
{******************************************************************************}
procedure AddNewestEdition;
begin
Editions := nil;
AddEdition(GetNewestEditionName);
end;
{******************************************************************************}
procedure Help;
var
I: Integer;
begin
AddAllEditions(True);
WriteLn('build.exe setups the environment for the given targets and executes the');
WriteLn('make file that does the required actions.');
WriteLn;
WriteLn('build.exe [TARGET] [OPTIONS]');
WriteLn(' TARGETS:');
Write(' ');
for I := 0 to High(Editions) - 1 do
Write(Editions[I].Name, ', ');
if Length(Editions) > 0 then
WriteLn(Editions[High(Editions)].Name);
//WriteLn(' c5, c6, c6p, d5, d5s, d6, d6p, d7, d7p, d7clx, d9');
WriteLn;
WriteLn(' OPTIONS:');
WriteLn(' --make=X X will be added to the make command line.');
WriteLn(' --dcc-opt=X sets the DCCOPT environment variable to X.');
WriteLn(' --bpl-path=X sets the BPLDIR and DCPDIR environment variable to X.');
WriteLn(' --lib-path=X sets the LIBDIR environment variable to X (BCB only).');
WriteLn(' --hpp-path=X sets the HPPDIR environment variable to X (BCB only).');
WriteLn(' Defaults to $(ROOT)\Include\Vcl');
WriteLn(' Set this to an empty string if you want the hpp files to');
WriteLn(' be left in the same directory as their source pas file.');
for I := 0 to High(ExtraOptions) do
if ExtraOptions[I].Name <> '' then
WriteLn(' --', ExtraOptions[I].Name, '=X sets the ', ExtraOptions[I].Env, ' environment variable to X.');
WriteLn(' --targets=X sets the TARGETS environment variable to X. Only these .bpl');
WriteLn(' files will be compiled.');
WriteLn(' (Example:');
WriteLn(' buildtarget "--targets=JvCoreD7R.bpl JvCoreD7R.bpl" )');
WriteLn;
WriteLn(' --build forces the Delphi compiler to build the targets.');
WriteLn(' --force Compile/Generate even if the target is not installed.');
WriteLn(' --verbose Show all commands that are executed.');
WriteLn;
end;
{******************************************************************************}
procedure ProcessArgs;
var
i, j, Count: Integer;
S: string;
HppPathSet: Boolean;
begin
i := 1;
Count := ParamCount;
HppPathSet := False;
while i <= Count do
begin
S := ParamStr(i);
if S[1] = '-' then
begin
if StartsText('--make=', S) then
begin
Delete(S, 1, 7);
if S <> '' then
if Pos(' ', S) > 0 then
MakeOptions := MakeOptions + ' "' + S + '"'
else
MakeOptions := MakeOptions + ' ' + S;
end
else if StartsText('--dcc-opt=', S) then
begin
Delete(S, 1, 10);
DccOpt := S;
end
else if StartsText('--bpl-path=', S) then
begin
Delete(S, 1, 11);
UserBplDir := S;
UserDcpDir := S;
end
else if StartsText('--lib-path=', S) then
begin
Delete(S, 1, 11);
UserLibDir := S;
end
else if StartsText('--hpp-path=', S) then
begin
Delete(S, 1, 11);
SetEnvironmentVariable('HPPDIR', Pointer(S));
HppPathSet := True;
end
else if StartsText('--targets=', S) then
begin
Delete(S, 1, 10);
SetEnvironmentVariable('TARGETS', Pointer(S));
end
else if SameText(S, '--build') then
begin
DccOpt := DccOpt + ' -B';
end
else if SameText('--force', S) then
begin
Force := True;
end
else if SameText('--verbose', S) then
begin
Verbose := True;
end
else
begin
for j := 0 to High(ExtraOptions) do
begin
if (ExtraOptions[I].Name <> '') and StartsText('--' + ExtraOptions[j].Name + '=', S) then
begin
Delete(S, 1, 2 + Length(ExtraOptions[j].Name) + 1);
SetEnvironmentVariable(PChar(ExtraOptions[j].Env), Pointer(S));
end;
end
end;
end
else
begin
if SameText(S, 'all') then
begin
AddAllEditions(False);
end
else if SameText(S, 'newest') then
begin
AddNewestEdition;
WriteLn('Using ', GetNewestEditionName, ' for build process.');
WriteLn;
end
else if TargetIndexOfEdition(S) = -1 then
begin
WriteLn('Unknown edition: ', S);
Halt(1);
end
else
AddEdition(S);
end;
Inc(i);
end;
if not HppPathSet then
SetEnvironmentVariable('HPPDIR', '$(ROOT)\Include\Vcl');
end;
{******************************************************************************}
procedure ClearEnvironment;
{ ClearEnvironment deletes almost all environment variables }
var
EnvP, P, StartP: PChar;
S: string;
begin
EnvP := GetEnvironmentStrings;
if EnvP <> nil then
begin
try
P := EnvP;
StartP := P;
repeat
while P^ <> #0 do
Inc(P);
if P^ = #0 then
begin
SetString(S, StartP, P - StartP);
S := Copy(S, 1, Pos('=', S) - 1);
if S <> '' then
begin
{ Delete the environment variable }
if not (
SameText(S, 'TEMP') or SameText(S, 'ComSpec') or SameText(S ,'OS') or
SameText(S, 'PATHEXT') or SameText(S, 'windir') or SameText(S, 'SystemRoot') or
SameText(S, 'SystemDrive') or
SameText(S, 'INSTALLOPTIONS') or SameText(S, 'LANG')
) then
SetEnvironmentVariable(PChar(S), nil);
end;
Inc(P);
if P^ = #0 then
Break; // finished
StartP := P;
end;
until False;
finally
FreeEnvironmentStrings(EnvP);
end;
end;
end;
{******************************************************************************}
function GetLibraryRootDir: string;
var
I: Integer;
begin
Result := ExtractFileDir(ParamStr(0));
for I := 1 to LibraryRootDirRelativeToBuild do
Result := ExtractFileDir(Result);
end;
{******************************************************************************}
function ExtractShortPathName(const Path: string): string;
begin
SetLength(Result, MAX_PATH);
SetLength(Result, GetShortPathName(PChar(Path), PChar(Result), Length(Result)));
end;
{******************************************************************************}
var
I: Integer;
UnitOutDir, Path: string;
Edition: TEdition;
begin
LibraryRootDir := GetLibraryRootDir;
// ClearEnvironment; // remove almost all environment variables for "make.exe long command line"
// ahuser (2005-01-22): make.exe fails only if a path with spaces is in the PATH envvar
// set ExtraOptions default values
for I := 0 to High(ExtraOptions) do
if ExtraOptions[I].Name <> '' then
SetEnvironmentVariable(PChar(ExtraOptions[I].Env), Pointer(ExtraOptions[I].Default));
SetEnvironmentVariable(PChar(LibraryName + 'ROOT'), PChar(LibraryRootDir));
UserBplDir := '';
UserDcpDir := '';
UserLibDir := '';
LoadTargetNames;
ProcessArgs;
if Length(Editions) = 0 then
begin
Help;
Halt(1);
end;
if not Verbose then
begin
MakeOptions := ' -s' + MakeOptions;
SetEnvironmentVariable('QUIET', '-s');
end
else
SetEnvironmentVariable('QUIET', nil);
for I := 0 to High(Editions) do
begin
ExtraUnitDirs := '';
Edition := Editions[I];
if Length(Editions) > 1 then
WriteLn('################################ ' + Edition.Name + ' #########################################');
// test for valid root directory/valid IDE installation
if not Force then
begin
if Edition.RootDir = '' then
begin
WriteLn('Delphi/BCB version not installed.');
Continue;
end;
end
else
begin
if Edition.RootDir = '' then
Edition := GetNewestEdition;
if Edition.RootDir = '' then
begin
WriteLn('No Delphi/BCB version installed.');
Continue;
end;
end;
UnitOutDir := LibraryRootDir + '\lib\' + Edition.MainName;
if UserDcpDir = '' then
UserDcpDir := Edition.DcpDir;
if UserBplDir = '' then
UserBplDir := Edition.BplDir;
if UserLibDir = '' then
UserLibDir := Edition.LibDir;
FindDxgettext(Edition.Version);
// setup environment and execute make.exe
Path := GetWindowsDir + ';' + GetSystemDir + ';' + GetWindowsDir + '\Command';
if UserLibDir <> UserBplDir then
Path := ExtractShortPathName(Edition.RootDir) + '\bin;' + ExtractShortPathName(UserBplDir) + ';' + ExtractShortPathName(UserLibDir) + ';' + Path
else
Path := ExtractShortPathName(Edition.RootDir) + '\bin;' + ExtractShortPathName(UserBplDir) + ';' + Path;
{ Add original BPL directory for "common" BPLs, but add it as the very last
path to prevent collisions between packages in TargetConfig.BplDir and
Target.BplDir. }
Path := Path + ';' + ExtractShortPathName(Edition.BplDir);
SetEnvironmentVariable('PATH', Pointer(Path));
SetEnvironmentVariable('MAINBPLDIR', Pointer(Edition.BplDir));
SetEnvironmentVariable('MAINDCPDIR', Pointer(Edition.DcpDir));
SetEnvironmentVariable('BPLDIR', Pointer(UserBplDir));
SetEnvironmentVariable('DCPDIR', Pointer(UserDcpDir));
SetEnvironmentVariable('LIBDIR', Pointer(UserLibDir));
SetEnvironmentVariable('BPILIBDIR', Pointer(UserLibDir));
SetEnvironmentVariable('PERSONALEDITION_OPTION', nil);
SetEnvironmentVariable('ROOT', PChar(Edition.RootDir));
SetEnvironmentVariable('VERSION', PChar(Edition.VersionStr));
SetEnvironmentVariable('UNITOUTDIR', PChar(UnitOutDir));
SetEnvironmentVariable('DCCOPT', Pointer(DccOpt));
SetEnvironmentVariable('DCC', PChar('"' + Edition.RootDir + '\bin\dcc32.exe" ' + DccOpt));
if Edition.IsPersonal then
begin
SetEnvironmentVariable('PERSONALEDITION_OPTION', '-DDelphiPersonalEdition');
SetEnvironmentVariable('PKGDIR', PChar(Edition.PkgDir));
SetEnvironmentVariable('EDITION', PChar(Edition.MainName));
if Verbose then
Execute('"' + Edition.RootDir + '\bin\make.exe" -f makefile.mak pg.exe')
else
Execute('"' + Edition.RootDir + '\bin\make.exe" -s -f makefile.mak pg.exe');
end;
SetEnvironmentVariable('EDITION', PChar(Edition.Name));
SetEnvironmentVariable('PKGDIR', PChar(Edition.PkgDir));
if (ExtraUnitDirs <> '') and (ExtraUnitDirs[1] = ';') then
Delete(ExtraUnitDirs, 1, 1);
SetEnvironmentVariable('EXTRAUNITDIRS', Pointer(ExtraUnitDirs));
SetEnvironmentVariable('DXGETTEXTDIR', Pointer(DxgettextDir));
ExitCode := Execute('"' + Edition.RootDir + '\bin\make.exe" ' + MakeOptions);
if ExitCode <> 0 then
begin
if ExitCode < 0 then
WriteLn('Failed: ', '"' + Edition.RootDir + '\bin\make.exe" ' + MakeOptions);
WriteLn('Press ENTER to continue');
ReadLn;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -