📄 build.dpr
字号:
Continue; // this is not a valid version
if ed.IsValid then
begin
Result.Free;
Result := ed;
ed := nil;
end
else
begin
//WriteLn('Ignoring invalid installation or trial version of ', ed.MainName, ' ', ed.VersionStr, '.');
ed.Free;
ed := nil;
end;
end;
end;
finally
ed.Free;
end;
end;
end;
{******************************************************************************}
function GetNewestProductName: string;
var
ed: TProduct;
begin
ed := GetNewestProduct;
try
if ed <> nil then
Result := ed.Name
else
Result := '';
finally
ed.Free;
end;
end;
{******************************************************************************}
procedure AddNewestProduct;
begin
Products := nil;
AddProduct(GetNewestProductName);
end;
{******************************************************************************}
procedure Help;
var
I: Integer;
begin
AddAllProducts(True);
WriteLn('build.exe setups the environment for the given targets and executes the');
WriteLn('makefile that does the required actions.');
WriteLn;
WriteLn('build.exe [TARGET] [OPTIONS]');
WriteLn(' TARGETS:');
Write(' ');
for I := 0 to High(Products) - 1 do
Write(Products[I].Name, ', ');
if Length(Products) > 0 then
WriteLn(Products[High(Products)].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
AddAllProducts(False)
else if SameText(S, 'newest') then
begin
AddNewestProduct;
WriteLn('Using ', GetNewestProductName, ' for build process.');
WriteLn;
end
else if TargetIndexOfProduct(S) = -1 then
begin
WriteLn('Unknown version: ', S);
Halt(1);
end
else
AddProduct(S);
end;
Inc(i);
end;
if not HppPathSet then
SetEnvironmentVariable('HPPDIR', '$(ROOT)\Include\Vcl');
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;
{******************************************************************************}
procedure FixDcc32Cfg(Product: TProduct);
var
f: TextFile;
S: string;
FoundU, FoundLU: Boolean;
begin
AssignFile(f, Product.RootDir + '\bin\dcc32.cfg');
if not FileExists(Product.RootDir + '\bin\dcc32.cfg') then
begin
// Invalid Delphi/BCB installation or someone deleted the dcc32.cfg file.
{$I-}
Rewrite(f);
{$I+}
if IOResult = 0 then
begin
WriteLn(f, '-aWinTypes=Windows;WinProcs=Windows;DbiProcs=BDE;DbiTypes=BDE;DbiErrs=BDE');
if Product.Typ <> Delphi then
WriteLn(f, '-u"', Product.RootDir, '\lib";"', Product.RootDir, '\lib\obj"')
else
WriteLn(f, '-u"', Product.RootDir, '\lib"');
if (Product.Typ = BCB) and (Product.Version = 5) then
WriteLn(f, '-LUvcl50');
CloseFile(f);
end
else
begin
WriteLn('Cannot create missing default ', Product.RootDir, '\bin\dcc32.cfg');
Halt(0);
end;
end
else
begin
FoundU := False;
FoundLU := (Product.Typ <> BCB) and (Product.Version = 5);
Reset(f);
while not EOF(f) and not (FoundU and FoundLU) do
begin
ReadLn(f, S);
if Product.Typ = Delphi then
FoundU := FoundU or SameText(S, '-u"' + Product.RootDir + '\lib"') or
SameText(S, '-u"' + ExtractShortPathName(Product.RootDir) + '\lib"') or
SameText(S, '-u' + ExtractShortPathName(Product.RootDir) + '\lib')
else
FoundU := FoundU or SameText(S, '-u"' + Product.RootDir + '\lib";"' + Product.RootDir + '\lib\obj"') or
SameText(S, '-u"' + ExtractShortPathName(Product.RootDir) + '\lib";"' + ExtractShortPathName(Product.RootDir) + '\lib\obj"') or
SameText(S, '-u' + ExtractShortPathName(Product.RootDir) + '\lib;' + ExtractShortPathName(Product.RootDir) + '\lib\obj');
if (Product.Typ = BCB) and (Product.Version = 5) then
FoundLU := FoundLU or SameText(S, '-LUvcl50');
end;
CloseFile(f);
if not FoundU or not FoundLU then
begin
{$I-}
Append(f);
{$I+}
WriteLn(f);
if IOResult = 0 then
begin
if not FoundU then
begin
if Product.Typ <> Delphi then
WriteLn(f, '-u"', Product.RootDir, '\lib";"', Product.RootDir, '\lib\obj"')
else
WriteLn(f, '-u"', Product.RootDir, '\lib"');
end;
if not FoundLU and (Product.Typ = BCB) and (Product.Version = 5) then
WriteLn(f, '-LUvcl50');
CloseFile(f);
end
else
begin
WriteLn('You do not have the required permissions to alter the defect ', Product.RootDir, '\bin\dcc32.cfg');
Halt(0);
end;
end;
end;
end;
var
I: Integer;
UnitOutDir, Path: string;
Product: TProduct;
begin
LibraryRootDir := GetLibraryRootDir;
// 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(Products) = 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(Products) do
begin
ExtraUnitDirs := '';
Product := Products[I];
if Length(Products) > 1 then
WriteLn('################################ ' + Product.Name + ' #########################################');
// test for valid root directory/valid IDE installation
if not Force then
begin
if Product.RootDir = '' then
begin
WriteLn('Delphi/BCB version not installed or the registry value of ');
WriteLn('[HKLM\', Product.KeyName, ']\RootDir is empty.');
Continue;
end;
end
else
begin
if Product.RootDir = '' then
Product := GetNewestProduct;
if Product.RootDir = '' then
begin
WriteLn('Delphi/BCB version not installed or the registry value of ');
WriteLn('[HKLM\', Product.KeyName, ']\RootDir is empty.');
Continue;
end;
end;
// correct dcc32.cfg file if necessary
FixDcc32Cfg(Product);
UnitOutDir := LibraryRootDir + '\lib\' + Product.MainName;
if UserDcpDir = '' then
UserDcpDir := Product.DcpDir;
if UserBplDir = '' then
UserBplDir := Product.BplDir;
if UserLibDir = '' then
UserLibDir := Product.LibDir;
FindDxgettext(Product.Version);
// setup environment and execute make.exe
Path := GetWindowsDir + ';' + GetSystemDir + ';' + GetWindowsDir + '\Command';
if UserLibDir <> UserBplDir then
Path := ExtractShortPathName(Product.RootDir) + '\bin;' + ExtractShortPathName(UserBplDir) + ';' + ExtractShortPathName(UserLibDir) + ';' + Path
else
Path := ExtractShortPathName(Product.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(Product.BplDir);
SetEnvironmentVariable('PATH', Pointer(Path));
SetEnvironmentVariable('MAINBPLDIR', Pointer(Product.BplDir));
SetEnvironmentVariable('MAINDCPDIR', Pointer(Product.DcpDir));
SetEnvironmentVariable('BPLDIR', Pointer(UserBplDir));
SetEnvironmentVariable('DCPDIR', Pointer(UserDcpDir));
SetEnvironmentVariable('LIBDIR', Pointer(UserLibDir));
SetEnvironmentVariable('BPILIBDIR', Pointer(UserLibDir));
SetEnvironmentVariable('PERSONALProduct_OPTION', nil);
SetEnvironmentVariable('ROOT', PChar(Product.RootDir));
SetEnvironmentVariable('VERSION', PChar(Product.VersionStr));
SetEnvironmentVariable('UNITOUTDIR', PChar(UnitOutDir));
SetEnvironmentVariable('DCCOPT', Pointer(DccOpt));
SetEnvironmentVariable('DCC', PChar('"' + Product.RootDir + '\bin\dcc32.exe" ' + DccOpt));
if Product.IsPersonal then
begin
SetEnvironmentVariable('PERSONALProduct_OPTION', '-DDelphiPersonalProduct');
SetEnvironmentVariable('PKGDIR', PChar(Product.PkgDir));
SetEnvironmentVariable('EDITION', PChar(Product.MainName));
if Verbose then
Execute('"' + Product.RootDir + '\bin\make.exe" -f makefile.mak pg.exe')
else
Execute('"' + Product.RootDir + '\bin\make.exe" -s -f makefile.mak pg.exe');
end;
SetEnvironmentVariable('EDITION', PChar(Product.Name));
SetEnvironmentVariable('PKGDIR', PChar(Product.PkgDir));
if (ExtraUnitDirs <> '') and (ExtraUnitDirs[1] = ';') then
Delete(ExtraUnitDirs, 1, 1);
SetEnvironmentVariable('EXTRAUNITDIRS', Pointer(ExtraUnitDirs));
SetEnvironmentVariable('DXGETTEXTDIR', Pointer(DxgettextDir));
ExitCode := Execute('"' + Product.RootDir + '\bin\make.exe" ' + MakeOptions);
if ExitCode <> 0 then
begin
if ExitCode < 0 then
WriteLn('Failed: ', '"' + Product.RootDir + '\bin\make.exe" ' + MakeOptions);
WriteLn('Press ENTER to continue');
ReadLn;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -