Sfoglia il codice sorgente

* Allow to read extra targets from secondary file

Michael VAN CANNEYT 2 anni fa
parent
commit
80947e18f8
3 ha cambiato i file con 54 aggiunte e 14 eliminazioni
  1. 14 9
      utils/fpcm/fpcmake.pp
  2. 39 4
      utils/fpcm/fpcmmain.pp
  3. 1 1
      utils/fpcm/revision.inc

+ 14 - 9
utils/fpcm/fpcmake.pp

@@ -37,6 +37,7 @@ program fpcmake;
     var
       ParaMode : TMode;
       ParaVerboseLevel : TVerboseLevel;
+      paraExtra : string;
       ParaTargets : string;
       ParaRecursive : boolean;
 
@@ -81,7 +82,7 @@ program fpcmake;
                              Makefile output
 *****************************************************************************}
 
-    procedure ProcessFile_Makefile(const fn:string);
+    procedure ProcessFile_Makefile(const fn, aextra:string);
       var
         CurrFPCMake : TFPCMakeConsole;
         CurrMakefile : TMakefileWriter;
@@ -96,6 +97,7 @@ program fpcmake;
 {$endif NOEXCEPT}
           { Load Makefile.fpc }
           CurrFPCMake:=TFPCMakeConsole.Create(fn);
+          CurrFPCMake.ExtraTargetsFile:=aExtra;
           if ParaTargets<>'' then
            CurrFPCMake.SetTargets(ParaTargets);
           CurrFPCMake.LoadMakefileFPC;
@@ -153,7 +155,7 @@ program fpcmake;
              s:=GetToken(subdirs,' ');
              if s='' then
               break;
-             ProcessFile_Makefile(ExtractFilePath(fn)+s+'/Makefile.fpc');
+             ProcessFile_Makefile(ExtractFilePath(fn)+s+'/Makefile.fpc',paraExtra);
            until false;
          end;
 
@@ -163,7 +165,7 @@ program fpcmake;
                              Package.fpc output
 *****************************************************************************}
 
-    procedure ProcessFile_PackageFpc(const fn:string);
+    procedure ProcessFile_PackageFpc(const fn,aExtra :string);
       var
         CurrFPCMake : TFPCMakeConsole;
         CurrPackageFpc : TPackageFpcWriter;
@@ -177,6 +179,7 @@ program fpcmake;
           CurrFPCMake:=TFPCMakeConsole.Create(fn);
           if ParaTargets<>'' then
            CurrFPCMake.SetTargets(ParaTargets);
+          CurrFPCMake.ExtraTargetsFile:=aExtra;
           CurrFPCMake.LoadMakefileFPC;
 //          CurrFPCMake.Print;
 
@@ -197,16 +200,16 @@ program fpcmake;
       end;
 
 
-    procedure ProcessFile(const fn:string);
+    procedure ProcessFile(const fn,aExtra:string);
       begin
         Show(V_Verbose,TitleDate);
         case ParaMode of
           m_None :
             Error('No operation specified, see -h for help');
           m_Makefile :
-            ProcessFile_Makefile(fn);
+            ProcessFile_Makefile(fn,aExtra);
           m_PackageFpc :
-            ProcessFile_PackageFpc(fn);
+            ProcessFile_PackageFpc(fn,aExtra);
         end;
       end;
 
@@ -219,7 +222,7 @@ begin
    fn:='Makefile.fpc'
   else
    fn:='makefile.fpc';
-  ProcessFile(fn);
+  ProcessFile(fn,paraExtra);
 end;
 
 
@@ -228,7 +231,7 @@ var
   i : integer;
 begin
   for i:=OptInd to ParamCount do
-   ProcessFile(ParamStr(i));
+   ProcessFile(ParamStr(i),ParaExtra);
 end;
 
 
@@ -250,6 +253,7 @@ begin
   writeln(' -v                  Be more verbose');
   writeln(' -q                  Be quiet');
   writeln(' -h                  This help screen');
+  writeln(' -x file             Read extra target definitions from file.');
   Halt(0);
 end;
 
@@ -266,7 +270,7 @@ Procedure ProcessOpts;
   Process command line opions, and checks if command line options OK.
 }
 const
-  ShortOpts = 'pwqrvh?VT:';
+  ShortOpts = 'pwqrvh?VT:x:';
 var
   C : char;
 begin
@@ -285,6 +289,7 @@ begin
       'r' : ParaRecursive:=true;
       'v' : ParaVerboseLevel:=v_verbose;
       'T' : ParaTargets:=OptArg;
+      'x' : ParaExtra:=OptArg;
       '?' : Usage;
       'h' : Usage;
       'V' : printVersion;

+ 39 - 4
utils/fpcm/fpcmmain.pp

@@ -228,6 +228,7 @@ interface
         FRequireList    : TTargetRequireList;
         FVariables      : TKeyValue;
         FIncludeTargets : TTargetSet;
+        FExtraTargetsFile : String;
         procedure Init;
         procedure ParseSec(p:TDictionaryItem);
         procedure PrintSec(p:TDictionaryItem);
@@ -245,6 +246,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;
@@ -274,6 +276,7 @@ interface
         property EmptyLines:Boolean read FEmptyLines write FEmptyLines;
         property IncludeTargets:TTargetSet read FIncludeTargets write FIncludeTargets;
         Property KnownArchitectures : TStrings Read FKnownArchitectures;
+        Property ExtraTargetsFile : String Read FExtraTargetsFile Write FExtraTargetsFile;
       end;
 
     function posidx(const substr,s : string;idx:integer):integer;
@@ -682,21 +685,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;
@@ -715,13 +747,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;
@@ -729,6 +762,7 @@ implementation
            end;
         finally
           SLInput.Free;
+          slExtra.Free;
         end;
       end;
 
@@ -1544,6 +1578,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)+' '+

+ 1 - 1
utils/fpcm/revision.inc

@@ -1 +1 @@
-'2023-05-17 hash b51e0a2cb1'
+'2023-02-08 hash d9a66d47c8'