Browse Source

* fpcdir detection added
* fixed loading of variables in fpcmake itself

peter 24 years ago
parent
commit
76fcd52b4f
6 changed files with 568 additions and 352 deletions
  1. 95 11
      utils/fpcm/Makefile
  2. 167 176
      utils/fpcm/fpcmake.inc
  3. 4 10
      utils/fpcm/fpcmake.ini
  4. 35 11
      utils/fpcm/fpcmake.pp
  5. 237 113
      utils/fpcm/fpcmmain.pp
  6. 30 31
      utils/fpcm/fpcmwr.pp

+ 95 - 11
utils/fpcm/Makefile

@@ -1,5 +1,5 @@
 #
-# Don't edit, this file is generated by fpcmake v1.99.0 [2001/02/20]
+# Don't edit, this file is generated by fpcmake v1.99.0 [2001/02/22]
 #
 default: all
 override PATH:=$(subst \,/,$(PATH))
@@ -84,11 +84,9 @@ endif
 export FPC OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FPC_VERSION
 ifdef FPCDIR
 override FPCDIR:=$(subst \,/,$(FPCDIR))
-ifeq ($(wildcard $(FPCDIR)/rtl),)
-ifeq ($(wildcard $(FPCDIR)/units),)
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
 override FPCDIR=wrong
 endif
-endif
 else
 override FPCDIR=wrong
 endif
@@ -109,18 +107,14 @@ endif
 else
 override FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))))
 override FPCDIR:=$(FPCDIR)/..
-ifeq ($(wildcard $(FPCDIR)/rtl),)
-ifeq ($(wildcard $(FPCDIR)/units),)
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
 override FPCDIR:=$(FPCDIR)/..
-ifeq ($(wildcard $(FPCDIR)/rtl),)
-ifeq ($(wildcard $(FPCDIR)/units),)
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
 override FPCDIR=c:/pp
 endif
 endif
 endif
 endif
-endif
-endif
 UNITSDIR=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
 PACKAGESDIR=$(wildcard $(FPCDIR) $(FPCDIR)/packages)
 override TARGET_PROGRAMS+=fpcmake
@@ -432,26 +426,62 @@ endif
 export GCCLIBDIR OTHERLIB
 endif
 ifeq ($(OS_TARGET),linux)
+REQUIRE_PACKAGES_RTL=1
 REQUIRE_PACKAGES_PASZLIB=1
 REQUIRE_PACKAGES_INET=1
 REQUIRE_PACKAGES_FCL=1
+REQUIRE_PACKAGES_MYSQL=1
+REQUIRE_PACKAGES_IBASE=1
 endif
 ifeq ($(OS_TARGET),go32v2)
+REQUIRE_PACKAGES_RTL=1
 REQUIRE_PACKAGES_PASZLIB=1
 REQUIRE_PACKAGES_FCL=1
 endif
 ifeq ($(OS_TARGET),win32)
+REQUIRE_PACKAGES_RTL=1
 REQUIRE_PACKAGES_PASZLIB=1
 REQUIRE_PACKAGES_FCL=1
+REQUIRE_PACKAGES_MYSQL=1
+REQUIRE_PACKAGES_IBASE=1
 endif
 ifeq ($(OS_TARGET),os2)
+REQUIRE_PACKAGES_RTL=1
 REQUIRE_PACKAGES_PASZLIB=1
 REQUIRE_PACKAGES_FCL=1
 endif
 ifeq ($(OS_TARGET),freebsd)
+REQUIRE_PACKAGES_RTL=1
 REQUIRE_PACKAGES_PASZLIB=1
 REQUIRE_PACKAGES_FCL=1
 endif
+ifdef REQUIRE_PACKAGES_RTL
+PACKAGEDIR_RTL:=$(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /rtl/Makefile.fpc,$(PACKAGESDIR)))))
+ifneq ($(PACKAGEDIR_RTL),)
+PACKAGEDIR_RTL:=$(firstword $(PACKAGEDIR_RTL))
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=package_rtl
+package_rtl:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+ifneq ($(wildcard $(PACKAGEDIR_RTL)/$(OS_TARGET)),)
+UNITDIR_RTL=$(PACKAGEDIR_RTL)/$(OS_TARGET)
+else
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+endif
+else
+PACKAGEDIR_RTL=
+UNITDIR_RTL:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /rtl/Package.fpc,$(UNITSDIR)))))
+ifneq ($(UNITDIR_RTL),)
+UNITDIR_RTL:=$(firstword $(UNITDIR_RTL))
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override COMPILER_UNITDIR+=$(UNITDIR_RTL)
+endif
+endif
 ifdef REQUIRE_PACKAGES_PASZLIB
 PACKAGEDIR_PASZLIB:=$(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /paszlib/Makefile.fpc,$(PACKAGESDIR)))))
 ifneq ($(PACKAGEDIR_PASZLIB),)
@@ -533,7 +563,61 @@ ifdef UNITDIR_FCL
 override COMPILER_UNITDIR+=$(UNITDIR_FCL)
 endif
 endif
-.PHONY: package_paszlib package_inet package_fcl
+ifdef REQUIRE_PACKAGES_MYSQL
+PACKAGEDIR_MYSQL:=$(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /mysql/Makefile.fpc,$(PACKAGESDIR)))))
+ifneq ($(PACKAGEDIR_MYSQL),)
+PACKAGEDIR_MYSQL:=$(firstword $(PACKAGEDIR_MYSQL))
+ifeq ($(wildcard $(PACKAGEDIR_MYSQL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=package_mysql
+package_mysql:
+	$(MAKE) -C $(PACKAGEDIR_MYSQL) all
+endif
+ifneq ($(wildcard $(PACKAGEDIR_MYSQL)/$(OS_TARGET)),)
+UNITDIR_MYSQL=$(PACKAGEDIR_MYSQL)/$(OS_TARGET)
+else
+UNITDIR_MYSQL=$(PACKAGEDIR_MYSQL)
+endif
+else
+PACKAGEDIR_MYSQL=
+UNITDIR_MYSQL:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /mysql/Package.fpc,$(UNITSDIR)))))
+ifneq ($(UNITDIR_MYSQL),)
+UNITDIR_MYSQL:=$(firstword $(UNITDIR_MYSQL))
+else
+UNITDIR_MYSQL=
+endif
+endif
+ifdef UNITDIR_MYSQL
+override COMPILER_UNITDIR+=$(UNITDIR_MYSQL)
+endif
+endif
+ifdef REQUIRE_PACKAGES_IBASE
+PACKAGEDIR_IBASE:=$(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /ibase/Makefile.fpc,$(PACKAGESDIR)))))
+ifneq ($(PACKAGEDIR_IBASE),)
+PACKAGEDIR_IBASE:=$(firstword $(PACKAGEDIR_IBASE))
+ifeq ($(wildcard $(PACKAGEDIR_IBASE)/$(FPCMADE)),)
+override COMPILEPACKAGES+=package_ibase
+package_ibase:
+	$(MAKE) -C $(PACKAGEDIR_IBASE) all
+endif
+ifneq ($(wildcard $(PACKAGEDIR_IBASE)/$(OS_TARGET)),)
+UNITDIR_IBASE=$(PACKAGEDIR_IBASE)/$(OS_TARGET)
+else
+UNITDIR_IBASE=$(PACKAGEDIR_IBASE)
+endif
+else
+PACKAGEDIR_IBASE=
+UNITDIR_IBASE:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /ibase/Package.fpc,$(UNITSDIR)))))
+ifneq ($(UNITDIR_IBASE),)
+UNITDIR_IBASE:=$(firstword $(UNITDIR_IBASE))
+else
+UNITDIR_IBASE=
+endif
+endif
+ifdef UNITDIR_IBASE
+override COMPILER_UNITDIR+=$(UNITDIR_IBASE)
+endif
+endif
+.PHONY: package_rtl package_paszlib package_inet package_fcl package_mysql package_ibase
 override FPCOPTDEF=$(CPU_TARGET)
 ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)

File diff suppressed because it is too large
+ 167 - 176
utils/fpcm/fpcmake.inc


+ 4 - 10
utils/fpcm/fpcmake.ini

@@ -5,7 +5,7 @@
 [osdetect]
 #####################################################################
 # Autodetect OS (Linux or Dos or Windows NT or OS/2)
-# define inUnix when running under Unix environment
+# define inUnix when running under Unix like environment
 #               (Linux,FreeBSD,Cygwin)
 # define inWinNT when running under WinNT
 # define inOS2 when running under OS/2
@@ -137,11 +137,9 @@ export FPC OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FPC_VERSION
 # Test FPCDIR to look if the RTL dir exists
 ifdef FPCDIR
 override FPCDIR:=$(subst \,/,$(FPCDIR))
-ifeq ($(wildcard $(FPCDIR)/rtl),)
-ifeq ($(wildcard $(FPCDIR)/units),)
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
 override FPCDIR=wrong
 endif
-endif
 else
 override FPCDIR=wrong
 endif
@@ -158,18 +156,14 @@ endif
 else
 override FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))))
 override FPCDIR:=$(FPCDIR)/..
-ifeq ($(wildcard $(FPCDIR)/rtl),)
-ifeq ($(wildcard $(FPCDIR)/units),)
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
 override FPCDIR:=$(FPCDIR)/..
-ifeq ($(wildcard $(FPCDIR)/rtl),)
-ifeq ($(wildcard $(FPCDIR)/units),)
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
 override FPCDIR=c:/pp
 endif
 endif
 endif
 endif
-endif
-endif
 
 # Units dir
 UNITSDIR=$(wildcard $(FPCDIR)/units/$(OS_TARGET))

+ 35 - 11
utils/fpcm/fpcmake.pp

@@ -17,7 +17,7 @@
 program fpcmake;
 
     uses
-      dos,sysutils,
+      sysutils,
       fpcmmain,fpcmwr;
 
     procedure Verbose(s:string);
@@ -37,31 +37,51 @@ program fpcmake;
       var
         CurrFPCMake : TFPCMake;
         CurrMakefile : TMakefileWriter;
-        s : string;
+{$ifdef SUBDIRS}
+        s,Subdirs : string;
+        t : ttarget;
+{$endif SUBDIRS}
       begin
         CurrFPCMake:=nil;
 //        try
           writeln('Processing ',fn);
+          { Load Makefile.fpc }
           CurrFPCMake:=TFPCMake.Create(fn);
-          s:=GetEnv('FPCDIR');
-          if s<>'' then
-           CurrFPCMake.Variables.Add('FPCDIR',s)
-          else
-           CurrFPCMake.Variables.Add('FPCDIR','c:/pp');
-          CurrFPCMake.Variables.Add('UNITSDIR','$(FPCDIR)/units');
-          CurrFPCMake.Variables.Add('PACKAGESDIR','$(FPCDIR)/packages');
           CurrFPCMake.LoadMakefileFPC;
 //          CurrFPCMake.Print;
 
+{$ifdef SUBDIRS}
+          subdirs:=CurrFPCMake.GetVariable('target_dirs',true);
+          for t:=low(ttarget) to high(ttarget) do
+           subdirs:=subdirs+' '+CurrFPCMake.GetVariable('target_dirs'+targetsuffix[t],true);
+{$endif SUBDIRS}
+
+          { Write Makefile }
           CurrMakefile:=TMakefileWriter.Create(CurrFPCMake,ExtractFilePath(fn)+'Makefile');
           CurrMakefile.WriteGenericMakefile;
+          { Free }
           CurrMakefile.Free;
 
 //        except
 //          on e : exception do
-//           Error(e.message);
+//           begin
+//             Error(e.message);
+//             Subdirs:='';
+//           end;
 //        end;
         CurrFPCMake.Free;
+
+{$ifdef SUBDIRS}
+        { Process subdirs }
+        writeln('Subdirs found: ',subdirs);
+        repeat
+          s:=GetToken(subdirs);
+          if s='' then
+           break;
+          ProcessFile(ExtractFilePath(fn)+s+'/Makefile.fpc');
+        until false;
+{$endif SUBDIRS}
+
       end;
 
 
@@ -94,7 +114,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.2  2001-01-29 21:49:10  peter
+  Revision 1.3  2001-02-22 21:11:24  peter
+    * fpcdir detection added
+    * fixed loading of variables in fpcmake itself
+
+  Revision 1.2  2001/01/29 21:49:10  peter
     * lot of updates
 
   Revision 1.1  2001/01/24 21:59:36  peter

+ 237 - 113
utils/fpcm/fpcmmain.pp

@@ -18,6 +18,14 @@ unit fpcmmain;
 interface
 
     uses
+      dos,
+{$ifdef Unix}
+  {$ifdef VER1_0}
+      linux,
+  {$else}
+      unix,
+  {$endif}
+{$endif}
       sysutils,classes,
       fpcmdic;
 
@@ -25,6 +33,7 @@ interface
       Version='v1.99.0';
       Title='fpcmake '+Version;
       TitleDate=Title+' ['+{$ifdef fpc}{$i %DATE}{$else}'n/a'{$endif}+']';
+
     type
       TTarget=(
         t_linux,t_go32v2,t_win32,t_os2,t_freebsd
@@ -61,7 +70,6 @@ interface
       private
         FList       : TStringList;
         FDictionary : TKeyValue;
-        procedure PrintDic(p:TDictionaryItem);
         procedure BuildIniDic(p:TDictionaryItem);
         procedure BuildMakefileDic(p:TDictionaryItem);
         function GetKey(const k:string):string;
@@ -74,7 +82,6 @@ interface
         procedure ParseIni;
         procedure BuildIni;
         procedure BuildMakefile;
-        procedure Print;
         property Key[const s:string]:string read GetKey;default;
         property List:TStringList read FList;
         property Dictionary:TKeyValue read FDictionary;
@@ -82,6 +89,8 @@ interface
 
       TTargetRequireList = array[ttarget] of TStringList;
 
+      TFPCMakeVerbose = (FPCMakeError, FPCMakeInfo, FPCMakeDebug);
+
       TFPCMake = class
       private
         FStream         : TStream;
@@ -99,11 +108,15 @@ interface
         procedure Init;
         procedure ParseSec(p:TDictionaryItem);
         procedure PrintSec(p:TDictionaryItem);
+        procedure PrintDic(p:TDictionaryItem);
         function  GetSec(const AName:string):TDictionaryItem;
         procedure LoadRequiredPackage(t:TTarget;const ReqName,ReqVersion:string);
         procedure LoadRequiredDir(t:TTarget;const MainPack,currdir,subdir:string);
         procedure LoadRequires(t:Ttarget;FromFPCMake:TFPCMake);
         function  CopySection(Sec:TFPCMakeSection;Secname:string):TFPCMakeSection;
+      protected
+        VerboseIdent : string;
+        procedure Verbose(lvl:TFPCMakeVerbose;const s:string);
       public
         constructor Create(const AFileName:string);
         constructor CreateFromStream(s:TStream;const AFileName:string);
@@ -115,8 +128,9 @@ interface
         function  GetTargetRequires(t:TTarget):TStringList;
         function  CheckLibcRequire:boolean;
         procedure CreateExportSection;
+        procedure AddDefaultVariables;
         function  SubstVariables(const s:string):string;
-        function  GetVariable(const inivar:string):string;
+        function  GetVariable(const inivar:string;dosubst:boolean):string;
         function  SetVariable(const inivar,value:string;add:boolean):string;
         procedure Print;
         property Section[const s:string]:TDictionaryItem read GetSec;default;
@@ -143,16 +157,10 @@ implementation
       s_err_section_start='%s:%d: Wrong section start';
       s_err_not_key_value='Parse error key=value excepted: "%s"';
       s_err_no_section='%s:%d: Entries without section';
-      s_no_package_section='No package section found';
       s_no_package_name='No package name set';
       s_no_package_version='No package version set';
       s_err_require_format='Wrong require format "%s"';
 
-    type
-      tspecialdir=record
-        dir,unitdir,packdir : string;
-      end;
-
 
 {****************************************************************************
                                  Helpers
@@ -170,6 +178,18 @@ implementation
       end;
 
 
+    Function PathOrFileExists ( F : String) : Boolean;
+      Var
+        Info : Dos.SearchRec;
+      begin
+        if F[Length(f)] in ['/','\'] then
+         Delete(f,length(f),1);
+        dos.findfirst(f,fareadonly+faarchive+fahidden+fadirectory,info);
+        PathOrFileExists:=(Doserror=0);
+        dos.findclose(Info);
+      end;
+
+
     function posidx(const substr,s : string;idx:integer):integer;
       var
         i,j : integer;
@@ -298,15 +318,6 @@ implementation
       end;
 
 
-    procedure TFPCMakeSection.PrintDic(p:TDictionaryItem);
-      begin
-        with TKeyValueItem(p) do
-         begin
-           writeln('   ',name,' = "',value,'"');
-         end;
-      end;
-
-
     function TFPCMakeSection.GetKey(const k:string):string;
       begin
         if FDictionary=nil then
@@ -315,27 +326,6 @@ implementation
       end;
 
 
-    procedure TFPCMakeSection.Print;
-      var
-        i : integer;
-      begin
-        writeln('[',Name,']');
-        if assigned(FList) then
-         begin
-           writeln('  List:');
-           for i:=0 to FList.Count-1 do
-            Writeln('   "'+FList[i],'"');
-           if assigned(FDictionary) then
-            writeln('');
-         end;
-        if assigned(FDictionary) then
-         begin
-           writeln('  Dictionary:');
-           FDictionary.Foreach(@PrintDic);
-         end;
-      end;
-
-
     procedure TFPCMakeSection.ParseIni;
       var
         p : TKeyValueItem;
@@ -470,6 +460,7 @@ implementation
         FPackageVersion:='';
         FPackageSec:=nil;
         FExportSec:=nil;
+        VerboseIdent:='';
       end;
 
 
@@ -555,12 +546,20 @@ implementation
         LoadSections;
         { Parse all sections }
         FSections.Foreach(@ParseSec);
+        { Add some default variables like FPCDIR, UNITSDIR }
+        AddDefaultVariables;
         { Load package section }
         LoadPackageSection;
         LoadRequireSection;
       end;
 
 
+    procedure TFPCMake.Verbose(lvl:TFPCMakeVerbose;const s:string);
+      begin
+        writeln(VerboseIdent,s);
+      end;
+
+
     procedure TFPCMake.LoadPackageSection;
       var
         s : string;
@@ -575,7 +574,7 @@ implementation
         s:=FPackageSec['main'];
         if s<>'' then
          begin
-           SetVariable('package.name',s,false);
+           SetVariable('package_name',s,false);
            FPackageName:=s;
          end
         else
@@ -627,7 +626,8 @@ implementation
           TryFile:=false;
           if FileExists(fn) then
            begin
-             writeln('Package ',ReqName,': ',fn);
+             VerboseIdent:=VerboseIdent+'  ';
+             Verbose(FPCMakeDebug,'Package '+ReqName+': '+fn);
 
              ReqFPCMake:=TFPCMake.Create(fn);
              ReqFPCMake.LoadSections;
@@ -647,6 +647,7 @@ implementation
              CopySection(TFPCMakeSection(ReqFPCMake['require']),ReqName+'_require');
              { Free }
              ReqFPCMake.Free;
+             Delete(VerboseIdent,1,2);
              TryFile:=true;
            end;
         end;
@@ -666,27 +667,31 @@ implementation
           ReqFPCMake : TFPCMake;
           s : string;
         begin
-          writeln('Subdir: ',currdir+subdir+'/Makefile.fpc');
+          VerboseIdent:=VerboseIdent+'  ';
+          Verbose(FPCMakeDebug,'Subdir: '+currdir+subdir+'/Makefile.fpc');
           if not FileExists(currdir+subdir+'/Makefile.fpc') then
            Raise Exception.Create('s_no_makefile.fpc_found');
+          { Process Makefile.fpc }
           ReqFPCMake:=TFPCMake.Create(currdir+subdir+'/Makefile.fpc');
           ReqFPCMake.LoadSections;
           ReqFPCMake.LoadPackageSection;
           { Are we a subpackage? }
-          if (ReqFPCMake.GetVariable('package.name')<>MainPack) then
+          if (ReqFPCMake.GetVariable('package_name',false)<>MainPack) then
            begin
              ReqFPCMake.Free;
+             Delete(VerboseIdent,1,2);
              exit;
            end;
           { Load the requirements of this package }
           LoadRequires(t,ReqFPCMake);
           { Add the current requirements to our parents requirements }
-          s:=ReqFPCMake.GetVariable('require.packages')+' '+ReqFPCMake.GetVariable('require.packages'+targetsuffix[t]);
-          SetVariable('require.packages'+targetsuffix[t],s,true);
-          if ReqFPCMake.GetVariable('require.libc')<>'' then
-           SetVariable('require.libc','y',false);
+          s:=ReqFPCMake.GetVariable('require_packages',true)+' '+ReqFPCMake.GetVariable('require_packages'+targetsuffix[t],true);
+          SetVariable('require_packages'+targetsuffix[t],s,true);
+          if ReqFPCMake.GetVariable('require_libc',false)<>'' then
+           SetVariable('require_libc','y',false);
           { Free }
           ReqFPCMake.Free;
+          Delete(VerboseIdent,1,2);
         end;
 
 
@@ -697,51 +702,43 @@ implementation
         ReqName,
         ReqVersion : string;
         i,j : integer;
-        Sec : TFPCMakeSection;
       begin
-        Sec:=TFPCMakeSection(FromFPCMake['require']);
-        if assigned(Sec) then
-         begin
-           Sec.ParseIni;
-               s:=Sec['packages']+' '+Sec['packages'+TargetSuffix[t]];
-               repeat
-                 reqname:=GetToken(s);
-                 if reqname='' then
-                  break;
-                 i:=Pos('(',ReqName);
-                 if i>0 then
-                  begin
-                    j:=Pos(')',ReqName);
-                    if (i=1) or (j=0) then
-                     Raise Exception.Create(Format(s_err_require_format,[ReqName]));
-                    ReqVersion:=Copy(ReqName,i+1,j-i-1);
-                    ReqName:=Copy(ReqName,1,i-1);
-                  end
-                 else
-                  ReqVersion:='';
-                 { We only use lowercase names }
-                 ReqName:=Lowercase(ReqName);
-                 { Already loaded ? }
-                 if (RequireList[t].IndexOf(ReqName)=-1) then
-                  begin
-                    LoadRequiredPackage(t,ReqName,ReqVersion);
-                    RequireList[t].Add(ReqName);
-                  end;
-               until false;
-         end;
-        { target.dirs }
-        Sec:=TFPCMakeSection(FromFPCMake['target']);
-        if assigned(Sec) then
-         begin
-           Sec.ParseIni;
-               s:=Sec['dirs']+' '+Sec['dirs'+TargetSuffix[t]];
-               repeat
-                 reqdir:=GetToken(s);
-                 if reqdir='' then
-                  break;
-                 LoadRequiredDir(t,FromFPCMake.FPackageName,ExtractFilePath(FromFPCMake.FFileName),ReqDir)
-               until false;
-         end;
+        { packages }
+        s:=FromFPCMake.GetVariable('require_packages',true)+' '+FromFPCMake.GetVariable('require_packages'+TargetSuffix[t],true);
+        Verbose(FPCMakeDebug,'Required packages for '+TargetStr[t]+': '+s);
+        repeat
+          reqname:=GetToken(s);
+          if reqname='' then
+           break;
+          i:=Pos('(',ReqName);
+          if i>0 then
+           begin
+             j:=Pos(')',ReqName);
+             if (i=1) or (j=0) then
+              Raise Exception.Create(Format(s_err_require_format,[ReqName]));
+             ReqVersion:=Copy(ReqName,i+1,j-i-1);
+             ReqName:=Copy(ReqName,1,i-1);
+           end
+         else
+           ReqVersion:='';
+          { We only use lowercase names }
+          ReqName:=Lowercase(ReqName);
+          { Already loaded ? }
+         if (RequireList[t].IndexOf(ReqName)=-1) then
+           begin
+             LoadRequiredPackage(t,ReqName,ReqVersion);
+             RequireList[t].Add(ReqName);
+           end;
+        until false;
+        { sub dirs }
+        s:=FromFPCMake.GetVariable('target_dirs',true)+' '+FromFPCMake.GetVariable('target_dirs'+TargetSuffix[t],true);
+        Verbose(FPCMakeDebug,'Required dirs for '+TargetStr[t]+': '+s);
+        repeat
+          reqdir:=GetToken(s);
+          if reqdir='' then
+           break;
+          LoadRequiredDir(t,FromFPCMake.FPackageName,ExtractFilePath(FromFPCMake.FFileName),ReqDir)
+        until false;
       end;
 
 
@@ -752,14 +749,14 @@ implementation
           t : ttarget;
         begin
           result:=false;
-          if GetVariable(s)<>'' then
+          if GetVariable(s,false)<>'' then
            begin
              result:=true;
              exit;
            end;
           for t:=low(ttarget) to high(ttarget) do
            begin
-             if GetVariable(s+targetsuffix[t])<>'' then
+             if GetVariable(s+targetsuffix[t],false)<>'' then
               begin
                 result:=true;
                 exit;
@@ -773,15 +770,15 @@ implementation
       begin
         { Maybe add an implicit rtl dependency if there is something
           to compile }
-        s:=GetVariable('require.packages');
-        if (GetVariable('require.nortl')='') and
-           (CheckVar('target.programs') or
-            CheckVar('target.units') or
-            CheckVar('target.examples')) and
+        s:=GetVariable('require_packages',false);
+        if (GetVariable('require_nortl',false)='') and
+           (CheckVar('target_programs') or
+            CheckVar('target_units') or
+            CheckVar('target_examples')) and
            (Pos('rtl(',s)=0) then
          begin
            s:='rtl '+s;
-           SetVariable('require.packages',s,false);
+           SetVariable('require_packages',s,false);
          end;
         { Load recursively all required packages starting with this Makefile.fpc }
         for t:=low(TTarget) to high(TTarget) do
@@ -827,6 +824,7 @@ implementation
         ReqSec:=TFPCMakeSection(FSections['require']);
         if assigned(ReqSec) then
          AddReqSec(t,ReqSec);
+        Verbose(FPCMakeInfo,TargetStr[t]+' requires: '+ReqList.CommaText);
         GetTargetRequires:=ReqList;
       end;
 
@@ -838,27 +836,108 @@ implementation
         t : ttarget;
       begin
         Result:=false;
-        if GetVariable('require.libc')<>'' then
+        if GetVariable('require_libc',false)<>'' then
          begin
            Result:=true;
            exit;
          end;
         for t:=low(ttarget) to high(ttarget) do
-        for i:=0 to RequireList[t].Count-1 do
          begin
-           RSec:=TFPCMakeSection(FSections[RequireList[t][i]+'_require']);
-           if assigned(RSec) then
+           for i:=0 to RequireList[t].Count-1 do
             begin
-              if RSec['libc']<>'' then
+              RSec:=TFPCMakeSection(FSections[RequireList[t][i]+'_require']);
+              if assigned(RSec) then
                begin
-                 Result:=true;
-                 exit;
+                 if RSec['libc']<>'' then
+                  begin
+                    Result:=true;
+                    exit;
+                  end;
                end;
             end;
          end;
       end;
 
 
+    procedure TFPCMake.AddDefaultVariables;
+      var
+        hs,s : string;
+      begin
+        { Already set FPCDIR }
+        hs:='';
+        s:=GetVariable('FPCDIR',false);
+        if s<>'' then
+         hs:=SubstVariables('$(wildcard $(addprefix '+s+'/,rtl units))');
+        { Load from environment }
+        if hs='' then
+         begin
+           s:=GetEnv('FPCDIR');
+           if s<>'' then
+            hs:=SubstVariables('$(wildcard $(addprefix '+s+'/,rtl units))');
+         end;
+        { default_fpcdir }
+        if hs='' then
+         begin
+           s:=GetVariable('default_fpcdir',true);
+           if s<>'' then
+            hs:=SubstVariables('$(wildcard $(addprefix '+s+'/,rtl units))');
+         end;
+        { OS defaults }
+        if hs='' then
+         begin
+{$ifdef UNIX}
+           if FileExists('/usr/local/bin/ppc386') then
+            begin
+              s:=ExtractFilePath(ReadLink('/usr/local/bin/ppc386'));
+              if s<>'' then
+               begin
+                 if s[length(s)]='/' then
+                  delete(s,length(s),1);
+                 hs:=SubstVariables('$(wildcard $(addprefix '+s+'/,rtl units))');
+               end;
+            end;
+           if hs='' then
+            begin
+              if FileExists('/usr/bin/ppc386') then
+               begin
+                 s:=ExtractFilePath(ReadLink('/usr/bin/ppc386'));
+                 if s<>'' then
+                  begin
+                    if s[length(s)]='/' then
+                     delete(s,length(s),1);
+                    hs:=SubstVariables('$(wildcard $(addprefix '+s+'/,rtl units))');
+                  end;
+               end;
+            end;
+{$else UNIX}
+           hs:=ExtractFilePath(FSearch('ppc386.exe',getenv('PATH')));
+           if hs<>'' then
+            begin
+              s:=hs+'/..';
+              hs:=SubstVariables('$(wildcard $(addprefix '+s+'/,rtl units))');
+              if hs='' then
+               begin
+                 s:=s+'/..';
+                 hs:=SubstVariables('$(wildcard $(addprefix '+s+'/,rtl units))');
+               end;
+            end;
+           if hs='' then
+            s:='c:/pp';
+{$endif UNIX}
+         end;
+        SetVariable('FPCDIR',s,false);
+        { PACKAGESDIR }
+        if GetVariable('PACKAGESDIR',false)='' then
+         SetVariable('PACKAGESDIR','$(FPCDIR)/packages',false);
+        { UNITSDIR }
+        if GetVariable('UNITSDIR',false)='' then
+         SetVariable('UNITSDIR','$(FPCDIR)/units',false);
+
+        Verbose(FPCMakeDebug,'Globals:');
+        Variables.Foreach(@PrintDic);
+      end;
+
+
     function TFPCMake.SubstVariables(const s:string):string;
 
       function Expect(var s:string;c:char):boolean;
@@ -870,7 +949,7 @@ implementation
          end
         else
          begin
-           writeln('Error "',c,'" expected');
+           Verbose(FPCMakeError,'Error "'+c+'" expected');
            Result:=false;
          end;
       end;
@@ -904,18 +983,19 @@ implementation
            begin
              { It's a function }
              Func:=Copy(s,1,i-1);
+//writeln('func: ',func);
+             { $(wildcard(<list>) }
              if Func='wildcard' then
               begin
                 Delete(s,1,9);
                 s1:=GetVar(s,')');
                 Expect(s,')');
-writeln('$(wildcard ',s1,')');
                 first:=true;
                 repeat
                   tok:=GetToken(s1);
                   if tok='' then
                    break;
-                  if FileExists(tok) then
+                  if PathOrFileExists(tok) then
                    begin
                      if not first then
                       Result:=Result+' '
@@ -925,6 +1005,7 @@ writeln('$(wildcard ',s1,')');
                    end;
                 until false;
               end
+             { $(addprefix(<suffix>,<list>) }
              else if Func='addprefix' then
               begin
                 Delete(s,1,10);
@@ -946,6 +1027,7 @@ writeln('$(wildcard ',s1,')');
                   Result:=Result+s1+tok;
                 until false;
               end
+             { $(addsuffix(<suffix>,<list>) }
              else if Func='addsuffix' then
               begin
                 Delete(s,1,10);
@@ -995,13 +1077,14 @@ writeln('$(wildcard ',s1,')');
       var
         s1 : string;
       begin
+//writeln('S: ',s);
         s1:=s;
         Result:=GetVar(s1,#0);
-writeln('R: ',result);
+//writeln('R: ',result);
       end;
 
 
-    function TFPCMake.GetVariable(const inivar:string):string;
+    function TFPCMake.GetVariable(const inivar:string;dosubst:boolean):string;
       var
         Sec : TFPCMakeSection;
         Dic : TKeyValue;
@@ -1014,6 +1097,8 @@ writeln('R: ',result);
            Sec:=TFPCMakeSection(FSections[Copy(Inivar,1,i-1)]);
            if assigned(Sec) then
             begin
+              if not assigned(Sec.Dictionary) then
+               Sec.ParseIni;
               Dic:=TKeyValue(Sec.Dictionary);
               Result:=Dic[Copy(IniVar,i+1,Length(IniVar)-i)];
             end
@@ -1022,6 +1107,9 @@ writeln('R: ',result);
          end
         else
          Result:=Variables[IniVar];
+        { Substition asked ? }
+        if dosubst then
+         Result:=SubstVariables(Result);
       end;
 
 
@@ -1063,13 +1151,45 @@ writeln('R: ',result);
 
 
     procedure TFPCMake.PrintSec(p:TDictionaryItem);
+      var
+        i : integer;
       begin
-        TFPCMakeSection(p).Print;
+        with TFPCMakeSection(p) do
+         begin
+           Verbose(FPCMakeDebug,'['+Name+']');
+           if assigned(FList) then
+            begin
+              Verbose(FPCMakeDebug,'  List:');
+              for i:=0 to FList.Count-1 do
+               Verbose(FPCMakeDebug,'   "'+FList[i]+'"');
+              if assigned(FDictionary) then
+               Verbose(FPCMakeDebug,'');
+            end;
+           if assigned(FDictionary) then
+            begin
+              Verbose(FPCMakeDebug,'  Dictionary:');
+              FDictionary.Foreach(@PrintDic);
+            end;
+         end;
+      end;
+
+
+    procedure TFPCMake.PrintDic(p:TDictionaryItem);
+      begin
+        with TKeyValueItem(p) do
+         begin
+           Verbose(FPCMakeDebug,'   '+name+' = "'+value+'"');
+         end;
       end;
 
 
     procedure TFPCMake.Print;
       begin
+        { global variables }
+        Verbose(FPCMakeDebug,'[global variables]');
+        Verbose(FPCMakeDebug,'  Dictionary:');
+        Variables.Foreach(@PrintDic);
+        { sections }
         FSections.Foreach(@PrintSec);
       end;
 
@@ -1082,7 +1202,11 @@ writeln('R: ',result);
 end.
 {
   $Log$
-  Revision 1.4  2001-02-05 20:44:56  peter
+  Revision 1.5  2001-02-22 21:11:24  peter
+    * fpcdir detection added
+    * fixed loading of variables in fpcmake itself
+
+  Revision 1.4  2001/02/05 20:44:56  peter
     * variable substition like GNU Make. wildcard,addprefix,addsuffix
       already implemented
 

+ 30 - 31
utils/fpcm/fpcmwr.pp

@@ -314,13 +314,13 @@ implementation
         t : TTarget;
       begin
         result:=false;
-        if FInput.GetVariable(IniVar)<>'' then
+        if FInput.GetVariable(IniVar,false)<>'' then
          begin
            result:=true;
            exit;
          end;
         for t:=low(TTarget) to high(TTarget) do
-         if FInput.GetVariable(IniVar+TargetSuffix[t])<>'' then
+         if FInput.GetVariable(IniVar+TargetSuffix[t],false)<>'' then
           begin
             result:=true;
             exit;
@@ -330,7 +330,7 @@ implementation
 
     function TMakefileWriter.CheckVariable(const inivar:string):boolean;
       begin
-        Result:=(FInput.GetVariable(IniVar)<>'');
+        Result:=(FInput.GetVariable(IniVar,false)<>'');
       end;
 
 
@@ -339,12 +339,12 @@ implementation
         s : string;
         T : TTarget;
       begin
-        s:=FInput.GetVariable(IniVar);
+        s:=FInput.GetVariable(IniVar,false);
         if s<>'' then
          FOutput.Add('override '+FixVariable(IniVar)+'+='+s);
         for t:=low(TTarget) to high(TTarget) do
          begin
-           s:=FInput.GetVariable(IniVar+TargetSuffix[t]);
+           s:=FInput.GetVariable(IniVar+TargetSuffix[t],false);
            if s<>'' then
             begin
               FOutput.Add('ifeq ($(OS_TARGET),'+TargetStr[t]+')');
@@ -359,7 +359,7 @@ implementation
       var
         s : string;
       begin
-        s:=FInput.GetVariable(IniVar);
+        s:=FInput.GetVariable(IniVar,false);
         if s<>'' then
          FOutput.Add('override '+FixVariable(IniVar)+'='+s)
       end;
@@ -373,27 +373,27 @@ implementation
         k1,k2 : integer;
       begin
         result:='';
-        s:=FInput.GetVariable(IniVar);
+        s:=FInput.GetVariable(IniVar,false);
         repeat
           name:=GetToken(s);
           if Name='' then
            break;
-                { Remove (..) }
-                k1:=pos('(',name);
-                if k1>0 then
-                 begin
-                   k2:=PosIdx(')',name,k1);
-                   if k2=0 then
-                    k2:=length(name)+1;
-                   Delete(Name,k1,k2);
-                 end;
-                FOutput.Add(prefix+VarName(name)+'=1');
-                { add to the list of dirs without duplicates }
-                AddStrNoDup(result,name);
+          { Remove (..) }
+          k1:=pos('(',name);
+          if k1>0 then
+           begin
+             k2:=PosIdx(')',name,k1);
+             if k2=0 then
+              k2:=length(name)+1;
+             Delete(Name,k1,k2);
+           end;
+          FOutput.Add(prefix+VarName(name)+'=1');
+          { add to the list of dirs without duplicates }
+          AddStrNoDup(result,name);
         until false;
         for t:=low(TTarget) to high(TTarget) do
          begin
-           s:=FInput.GetVariable(IniVar+TargetSuffix[t]);
+           s:=FInput.GetVariable(IniVar+TargetSuffix[t],false);
            if s<>'' then
             begin
               FOutput.Add('ifeq ($(OS_TARGET),'+TargetStr[t]+')');
@@ -444,7 +444,7 @@ implementation
       var
         hs,tool : string;
       begin
-        hs:=FInput.GetVariable(inivar);
+        hs:=FInput.GetVariable(inivar,false);
         repeat
           Tool:=GetToken(hs);
           if Tool='' then
@@ -618,15 +618,12 @@ implementation
            sl:=FInput.GetTargetRequires(t);
            if sl.count>0 then
             begin
-              write(TargetStr[t]+' requires:');
               FOutput.Add('ifeq ($(OS_TARGET),'+TargetStr[t]+')');
               for i:=0 to sl.count-1 do
                begin
                  FOutput.Add(prefix+VarName(sl[i])+'=1');
-                 write(' ',sl[i]);
                  AddStrNoDup(reqs,sl[i]);
                end;
-              writeln;
               FOutput.Add('endif');
             end;
            sl.Free;
@@ -642,8 +639,6 @@ implementation
       end;
 
     procedure TMakefileWriter.WriteGenericMakefile;
-      var
-        i : integer;
       begin
         with FOutput do
          begin
@@ -655,23 +650,23 @@ implementation
            Add('# Don''t edit, this file is generated by '+TitleDate);
            Add('#');
            if CheckVariable('default_rule') then
-            Add('default: '+FInput.GetVariable('default_rule'))
+            Add('default: '+FInput.GetVariable('default_rule',false))
            else
             Add('default: all');
            { Add automatic detect sections }
            AddIniSection('osdetect');
            { Forced target }
            if CheckVariable('default_target') then
-            Add('override OS_TARGET='+FInput.GetVariable('default_target'));
+            Add('override OS_TARGET='+FInput.GetVariable('default_target',false));
            if CheckVariable('default_cpu') then
-            Add('override CPU_TARGET='+FInput.GetVariable('default_cpu'));
+            Add('override CPU_TARGET='+FInput.GetVariable('default_cpu',false));
            { FPC Detection }
            AddIniSection('fpcdetect');
            AddIniSection('fpcdircheckenv');
            if CheckVariable('default_fpcdir') then
             begin
               Add('ifeq ($(FPCDIR),wrong)');
-              Add('override FPCDIR='+FInput.GetVariable('default_fpcdir'));
+              Add('override FPCDIR='+FInput.GetVariable('default_fpcdir',false));
               Add('ifeq ($(wildcard $(FPCDIR)/rtl),)');
               Add('ifeq ($(wildcard $(FPCDIR)/units),)');
               Add('override FPCDIR=wrong');
@@ -779,7 +774,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.4  2001-02-20 21:49:31  peter
+  Revision 1.5  2001-02-22 21:11:24  peter
+    * fpcdir detection added
+    * fixed loading of variables in fpcmake itself
+
+  Revision 1.4  2001/02/20 21:49:31  peter
     * fixed change variable accessing using _ instead of .
 
   Revision 1.3  2001/02/01 22:00:10  peter

Some files were not shown because too many files changed in this diff