* Allow to read extra targets from secondary file

This commit is contained in:
Michael VAN CANNEYT 2023-02-22 09:19:54 +01:00 committed by Michaël Van Canneyt
parent ed50a1941b
commit 548ab476f7
2 changed files with 53 additions and 13 deletions

View File

@ -37,6 +37,7 @@ program fpcmake;
var
ParaMode : TMode;
ParaVerboseLevel : TVerboseLevel;
paraExtra : string;
ParaTargets : string;
ParaOutputFileName : string;
ParaRecursive : boolean;
@ -83,7 +84,7 @@ program fpcmake;
Makefile output
*****************************************************************************}
procedure ProcessFile_Makefile(const fn:string; const aOutputfile : string);
procedure ProcessFile_Makefile(const fn:string; const aOutputfile : string; aextra: string);
var
CurrFPCMake : TFPCMakeConsole;
CurrMakefile : TMakefileWriter;
@ -98,6 +99,7 @@ program fpcmake;
{$endif NOEXCEPT}
{ Load Makefile.fpc }
CurrFPCMake:=TFPCMakeConsole.Create(fn);
CurrFPCMake.ExtraTargetsFile:=aExtra;
if ParaTargets<>'' then
CurrFPCMake.SetTargets(ParaTargets);
CurrFPCMake.LoadMakefileFPC;
@ -156,7 +158,7 @@ program fpcmake;
s:=GetToken(subdirs,' ');
if s='' then
break;
ProcessFile_Makefile(ExtractFilePath(fn)+s+'/Makefile.fpc',aOutputFile);
ProcessFile_Makefile(ExtractFilePath(fn)+s+'/Makefile.fpc',aOutputFile, paraExtra);
until false;
end;
@ -166,7 +168,7 @@ program fpcmake;
Package.fpc output
*****************************************************************************}
procedure ProcessFile_PackageFpc(const fn:string; const aOutputFile : string);
procedure ProcessFile_PackageFpc(const fn:string; const aOutputFile : string; aExtra : String);
var
CurrFPCMake : TFPCMakeConsole;
CurrPackageFpc : TPackageFpcWriter;
@ -180,6 +182,7 @@ program fpcmake;
CurrFPCMake:=TFPCMakeConsole.Create(fn);
if ParaTargets<>'' then
CurrFPCMake.SetTargets(ParaTargets);
CurrFPCMake.ExtraTargetsFile:=aExtra;
CurrFPCMake.LoadMakefileFPC;
// CurrFPCMake.Print;
@ -200,7 +203,7 @@ program fpcmake;
end;
procedure ProcessFile(const fn:string; const aOutputFile : string);
procedure ProcessFile(const fn:string; const aOutputFile : string; const aExtra : string);
var
ofn : String;
@ -215,14 +218,14 @@ program fpcmake;
ofn:=aOutputFile;
if ofn='' then
ofn:='Makefile';
ProcessFile_Makefile(fn,ofn);
ProcessFile_Makefile(fn,ofn,aExtra);
end;
m_PackageFpc :
begin
ofn:=aOutputFile;
if ofn='' then
ofn:='Package.fpc';
ProcessFile_PackageFpc(fn,ofn);
ProcessFile_PackageFpc(fn,ofn,aextra);
end;
end;
end;
@ -236,7 +239,7 @@ begin
fn:='Makefile.fpc'
else
fn:='makefile.fpc';
ProcessFile(fn,ParaOutputFilename);
ProcessFile(fn,ParaOutputFilename, paraExtra);
end;
@ -245,7 +248,7 @@ var
i : integer;
begin
for i:=OptInd to ParamCount do
ProcessFile(ParamStr(i),ParaOutputFilename);
ProcessFile(ParamStr(i),ParaOutputFilename,ParaExtra);
end;
@ -269,6 +272,7 @@ begin
writeln(' -s Skip writing package name');
writeln(' -q Be quiet');
writeln(' -h This help screen');
writeln(' -x file Read extra target definitions from file.');
Halt(0);
end;
@ -285,7 +289,7 @@ Procedure ProcessOpts;
Process command line opions, and checks if command line options OK.
}
const
ShortOpts = 'pwqrvh?VsT:o:';
ShortOpts = 'pwqrvh?VsT:o:x:';
var
C : char;
begin
@ -307,6 +311,7 @@ begin
's' : ParaSkipPackageInfo:=True;
'v' : ParaVerboseLevel:=v_verbose;
'T' : ParaTargets:=OptArg;
'x' : ParaExtra:=OptArg;
'?' : Usage;
'h' : Usage;
'V' : printVersion;

View File

@ -227,6 +227,7 @@ interface
FRequireList : TTargetRequireList;
FVariables : TKeyValue;
FIncludeTargets : TTargetSet;
FExtraTargetsFile : String;
procedure Init;
procedure ParseSec(p:TDictionaryItem);
procedure PrintSec(p:TDictionaryItem);
@ -244,6 +245,7 @@ interface
destructor Destroy;override;
procedure Verbose(lvl:TFPCMakeVerbose;const s:string);virtual;
procedure SetTargets(const s:string);
procedure AddExtraTargets(const aFileName : String; aList : TStrings);
procedure LoadSections;
procedure LoadMakefileFPC;
procedure LoadPackageSection;
@ -272,6 +274,7 @@ interface
property CommentChars:TSysCharSet read FCommentChars write FCommentChars;
property EmptyLines:Boolean read FEmptyLines write FEmptyLines;
property IncludeTargets:TTargetSet read FIncludeTargets write FIncludeTargets;
Property ExtraTargetsFile : String Read FExtraTargetsFile Write FExtraTargetsFile;
end;
function posidx(const substr,s : string;idx:integer):integer;
@ -678,21 +681,50 @@ implementation
end;
procedure TFPCMake.AddExtraTargets(const aFileName : string; aList : TStrings);
var
Xtra : TStringList;
begin
Xtra:=TstringList.Create;
try
Xtra.LoadFromFile(aFileName);
aList.AddStrings(Xtra);
finally
Xtra.Free;
end;
end;
procedure TFPCMake.LoadSections;
var
SLInput : TStringList;
SLInput, slExtra : TStringList;
i,j,n : integer;
s,
SecName : string;
CurrSec : TFPCMakeSection;
begin
CurrSec:=nil;
slExtra:=Nil;
SLInput:=TStringList.Create;
try
CurrSec:=nil;
SLInput:=TStringList.Create;
// We do this first
if ExtraTargetsFile<>'' then
begin
slExtra:=TStringList.Create;
AddExtraTargets(ExtraTargetsFile,slExtra);
end;
if assigned(FStream) then
SLInput.LoadFromStream(FStream)
else
SLInput.LoadFromFile(FFileName);
if Assigned(SLExtra) then
begin
slExtra.AddStrings(slInput);
slInput.Free;
slInput:=slExtra;
slExtra:=nil;
end;
{ Load Input into sections list }
n:=SLInput.Count;
i:=0;
@ -711,13 +743,14 @@ implementation
SecName:=Copy(s,2,j-2);
CurrSec:=TFPCMakeSection(FSections[SecName]);
if CurrSec=nil then
CurrSec:=TFPCMakeSection(FSections.Insert(TFPCMakeSection.Create(SecName)));
CurrSec:=TFPCMakeSection(FSections.Insert(TFPCMakeSection.Create(SecName)))
end
else
begin
if CurrSec=nil then
raise Exception.Create(Format(s_err_no_section,[FFileName,i+1]));
{ Insert string without spaces stripped }
// Writeln('Appending: ',SLInput[i]);
CurrSec.AddLine(SLInput[i]);
end;
end;
@ -725,6 +758,7 @@ implementation
end;
finally
SLInput.Free;
slExtra.Free;
end;
end;
@ -1550,6 +1584,7 @@ implementation
function TFPCMake.GetTargetVariable(c:TCPU;t:TOS;const inivar:string;dosubst:boolean):string;
begin
result:=Trim(GetVariable(inivar,dosubst)+' '+
GetVariable(inivar+cpusuffix[c],dosubst)+' '+
GetVariable(inivar+OSSuffix[t],dosubst)+' '+