2
0
Эх сурвалжийг харах

* -T<target> support
* better error reporting for not found dirs
* some cleanups and nicer strings

peter 24 жил өмнө
parent
commit
18660be258

+ 54 - 55
utils/fpcm/fpcmake.inc

@@ -1014,8 +1014,8 @@ const fpcmakeini : array[0..125,1..240] of char=(
   '# a safety check is done if Makefile.fpc is available'#010+
   'ifdef PACKAGE_VERSION'#010+
   'ifneq ($(wildcard Makefile.fpc),)'#010+
-  '        $(FPCMAKE) -p Makefile.fpc'#010+
-  '        $(MKDIR) $(IN','STALL_UNITDIR)'#010+
+  '        $(FPCMAKE) -p -T$(OS_TARGET) Makefile.fpc'#010+
+  '      ','  $(MKDIR) $(INSTALL_UNITDIR)'#010+
   '        $(INSTALL) Package.fpc $(INSTALL_UNITDIR)'#010+
   'endif'#010+
   'endif'#010+
@@ -1024,14 +1024,14 @@ const fpcmakeini : array[0..125,1..240] of char=(
   'ifdef INSTALLPPUFILES'#010+
   '        $(MKDIR) $(INSTALL_UNITDIR)'#010+
   '        $(INSTALL) $(INSTALLPPUFILES) $(INSTALL_UNITDIR)'#010+
-  'ifneq ($(INSTALLPPULINKFILES),)'#010+
-  '    ','    $(INSTALL) $(INSTALLPPULINKFILES) $(INSTALL_UNITDIR)'#010+
+  'ifneq ($(INSTALLPPULI','NKFILES),)'#010+
+  '        $(INSTALL) $(INSTALLPPULINKFILES) $(INSTALL_UNITDIR)'#010+
   'endif'#010+
   'ifneq ($(wildcard $(LIB_FULLNAME)),)'#010+
   '        $(MKDIR) $(INSTALL_LIBDIR)'#010+
   '        $(INSTALL) $(LIB_FULLNAME) $(INSTALL_LIBDIR)'#010+
   'ifdef inUnix'#010+
-  '        ln -sf $(LIB_FULLNAME) $(INSTAL','L_LIBDIR)/$(LIB_NAME)'#010+
+  '        ln -sf $(LIB_FUL','LNAME) $(INSTALL_LIBDIR)/$(LIB_NAME)'#010+
   'endif'#010+
   'endif'#010+
   'endif'#010+
@@ -1041,15 +1041,15 @@ const fpcmakeini : array[0..125,1..240] of char=(
   'endif'#010+
   #010+
   'fpc_sourceinstall: distclean'#010+
-  '        $(MKDIR) $(INSTALL_SOURCEDIR)'#010+
-  '        $(COPYT','REE) $(BASEDIR) $(INSTALL_SOURCEDIR)'#010+
+  '        $(MKDIR) $(INSTALL_SOURCEDIR)'#010,
+  '        $(COPYTREE) $(BASEDIR) $(INSTALL_SOURCEDIR)'#010+
   #010+
   'fpc_exampleinstall: $(addsuffix _distclean,$(TARGET_EXAMPLEDIRS))'#010+
   'ifdef HASEXAMPLES'#010+
   '        $(MKDIR) $(INSTALL_EXAMPLEDIR)'#010+
   'endif'#010+
   'ifdef EXAMPLESOURCEFILES'#010+
-  '        $(COPY) $(EXAMPLESOURCEFILES) $(INSTALL_','EXAMPLEDIR)'#010+
+  '        $(COPY) $(EXAMPLESOURCEFI','LES) $(INSTALL_EXAMPLEDIR)'#010+
   'endif'#010+
   'ifdef TARGET_EXAMPLEDIRS'#010+
   '        $(COPYTREE) $(addsuffix /*,$(TARGET_EXAMPLEDIRS)) $(INSTALL_EX'+
@@ -1058,9 +1058,8 @@ const fpcmakeini : array[0..125,1..240] of char=(
   #010+
   '[distinstallrules]'#010+
   '#####################################################################'#010+
-  '# Dist Install'#010+
-  '######','##############################################################'+
-  '#'#010+
+  '# Dist',' Install'#010+
+  '#####################################################################'#010+
   #010+
   '.PHONY: fpc_distinstall'#010+
   #010+
@@ -1069,14 +1068,13 @@ const fpcmakeini : array[0..125,1..240] of char=(
   #010+
   '[zipinstallrules]'#010+
   '#####################################################################'#010+
-  '# Zip'#010+
-  '##############','######################################################'+
-  '#'#010+
+  '# Zip',#010+
+  '#####################################################################'#010+
   #010+
   '.PHONY: fpc_zipinstall fpc_zipsourceinstall fpc_zipexampleinstall'#010+
   #010+
   '# Temporary path to pack a file, can only use a single deep'#010+
-  '# subdir, because the deltree can'#039't see the whole tree t','o remove'+
+  '# subdir, because the deltree can'#039't see t','he whole tree to remove'+
   #010+
   'ifndef PACKDIR'#010+
   'ifndef inUnix'#010+
@@ -1091,7 +1089,7 @@ const fpcmakeini : array[0..125,1..240] of char=(
   'ifdef DIST_ZIPNAME'#010+
   'ZIPNAME=$(DIST_ZIPNAME)'#010+
   'else'#010+
-  'ZIPNAME=$(ZIPPREFIX)','$(PACKAGE_NAME)$(ZIPSUFFIX)'#010+
+  'ZIPNA','ME=$(ZIPPREFIX)$(PACKAGE_NAME)$(ZIPSUFFIX)'#010+
   'endif'#010+
   'endif'#010+
   #010+
@@ -1108,10 +1106,10 @@ const fpcmakeini : array[0..125,1..240] of char=(
   'ifndef USEZIP'#010+
   'ifdef inUnix'#010+
   'USETAR=1'#010+
-  'endif'#010+
+  'endi','f'#010+
   'endif'#010+
   #010+
-  '# Use ','a wrapper script by default for Os/2'#010+
+  '# Use a wrapper script by default for Os/2'#010+
   'ifndef inUnix'#010+
   'USEZIPWRAPPER=1'#010+
   'endif'#010+
@@ -1120,7 +1118,7 @@ const fpcmakeini : array[0..125,1..240] of char=(
   '# the path separator'#010+
   'ifdef USEZIPWRAPPER'#010+
   'ZIPPATHSEP=$(PATHSEP)'#010+
-  'ZIPWRAPPER=$(subst /,$(PATHSEP),$(DIST_DESTDIR)/fp','czip$(BATCHEXT))'#010+
+  'ZIPWRAPPER=$(subst /,$(PATHSEP),$(D','IST_DESTDIR)/fpczip$(BATCHEXT))'#010+
   'else'#010+
   'ZIPPATHSEP=/'#010+
   'endif'#010+
@@ -1129,7 +1127,7 @@ const fpcmakeini : array[0..125,1..240] of char=(
   'ZIPCMD_CDPACK:=cd $(subst /,$(ZIPPATHSEP),$(PACKDIR))'#010+
   'ZIPCMD_CDBASE:=cd $(subst /,$(ZIPPATHSEP),$(BASEDIR))'#010+
   'ifdef USETAR'#010+
-  'ZIPDESTFILE:=$(DIST_DESTDIR)/$(Z','IPNAME)$(TAREXT)'#010+
+  'ZIPDESTFILE:=$(DI','ST_DESTDIR)/$(ZIPNAME)$(TAREXT)'#010+
   'ZIPCMD_ZIP:=$(TARPROG) cf$(TAROPT) $(ZIPDESTFILE) *'#010+
   'else'#010+
   'ZIPDESTFILE:=$(DIST_DESTDIR)/$(ZIPNAME)$(ZIPEXT)'#010+
@@ -1137,13 +1135,13 @@ const fpcmakeini : array[0..125,1..240] of char=(
   'TFILE) *'#010+
   'endif'#010+
   #010+
-  'fpc_zipinstall:'#010+
-  '        $(MAKE)',' $(ZIPTARGET) INSTALL_PREFIX=$(PACKDIR) ZIPINSTALL=1'#010+
+  'fpc_zipinstall:'#010,
+  '        $(MAKE) $(ZIPTARGET) INSTALL_PREFIX=$(PACKDIR) ZIPINSTALL=1'#010+
   '        $(DEL) $(ZIPDESTFILE)'#010+
   'ifdef USEZIPWRAPPER'#010+
   '# Handle gecho separate as we need to espace \ with \\'#010+
   'ifneq ($(ECHOREDIR),echo)'#010+
-  '        $(ECHOREDIR) -e "$(subst \,\\,$(ZIPCMD_CDPACK))"',' > $(ZIPWRAP'+
+  '        $(ECHOREDIR) -e "$(subst \,\\,$(Z','IPCMD_CDPACK))" > $(ZIPWRAP'+
   'PER)'#010+
   '        $(ECHOREDIR) -e "$(subst \,\\,$(ZIPCMD_ZIP))" >> $(ZIPWRAPPER)'+
   #010+
@@ -1151,7 +1149,7 @@ const fpcmakeini : array[0..125,1..240] of char=(
   'ER)'#010+
   'else'#010+
   '        echo $(ZIPCMD_CDPACK) > $(ZIPWRAPPER)'#010+
-  '        echo $(ZIPCMD_ZIP) ','>> $(ZIPWRAPPER)'#010+
+  '        echo',' $(ZIPCMD_ZIP) >> $(ZIPWRAPPER)'#010+
   '        echo $(ZIPCMD_CDBASE) >> $(ZIPWRAPPER)'#010+
   'endif'#010+
   'ifdef inUnix'#010+
@@ -1161,7 +1159,7 @@ const fpcmakeini : array[0..125,1..240] of char=(
   'endif'#010+
   '        $(DEL) $(ZIPWRAPPER)'#010+
   'else'#010+
-  '        $(ZIPCMD_CDPACK) ; $(ZIPCMD_ZIP) ; $(ZIPCMD_CDBASE)'#010,
+  '        $(ZIPCMD_CDPACK) ; $(ZIPCMD_ZIP) ; $(','ZIPCMD_CDBASE)'#010+
   'endif'#010+
   '        $(DELTREE) $(PACKDIR)'#010+
   #010+
@@ -1170,7 +1168,8 @@ const fpcmakeini : array[0..125,1..240] of char=(
   #010+
   'fpc_zipexampleinstall:'#010+
   'ifdef HASEXAMPLES'#010+
-  '        $(MAKE) fpc_zipinstall ZIPTARGET=exampleinstall ZIPSUFFIX=exm'#010,
+  '        $(MAKE) fpc_zipinstall ZIPTARGET=exampleinstall',' ZIPSUFFIX=ex'+
+  'm'#010+
   'endif'#010+
   #010+
   'fpc_zipdistinstall:'#010+
@@ -1180,7 +1179,7 @@ const fpcmakeini : array[0..125,1..240] of char=(
   '[cleanrules]'#010+
   '#####################################################################'#010+
   '# Clean rules'#010+
-  '#############################################################','#######'+
+  '##############################################','######################'+
   '#'#010+
   #010+
   '.PHONY: fpc_clean fpc_cleanall fpc_distclean'#010+
@@ -1191,14 +1190,14 @@ const fpcmakeini : array[0..125,1..240] of char=(
   'endif'#010+
   #010+
   'ifdef CLEAN_UNITS'#010+
-  'override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS))'#010+
+  'override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UN','ITS))'#010+
   'endif'#010+
   #010+
-  'if','def CLEANPPUFILES'#010+
+  'ifdef CLEANPPUFILES'#010+
   'override CLEANPPULINKFILES:=$(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)'+
   ') $(addprefix $(STATICLIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(C'+
   'LEANPPUFILES)))'#010+
-  'override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEAN','PP'+
+  'override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIR','PREFIX),$(CLEANPP'+
   'UFILES))'#010+
   'override CLEANPPULINKFILES:=$(wildcard $(addprefix $(UNITTARGETDIRPREF'+
   'IX),$(CLEANPPULINKFILES)))'#010+
@@ -1209,7 +1208,7 @@ const fpcmakeini : array[0..125,1..240] of char=(
   '        -$(DEL) $(CLEANEXEFILES)'#010+
   'endif'#010+
   'ifdef CLEANPPUFILES'#010+
-  '        -$(DEL) $(CL','EANPPUFILES)'#010+
+  '     ','   -$(DEL) $(CLEANPPUFILES)'#010+
   'endif'#010+
   'ifneq ($(CLEANPPULINKFILES),)'#010+
   '        -$(DEL) $(CLEANPPULINKFILES)'#010+
@@ -1218,8 +1217,8 @@ const fpcmakeini : array[0..125,1..240] of char=(
   '        -$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))'#010+
   'endif'#010+
   'ifdef CLEAN_FILES'#010+
-  '        -$(DEL) $(CLEAN_FILES)'#010+
-  'endi','f'#010+
+  '        -$(DEL) $(CL','EAN_FILES)'#010+
+  'endif'#010+
   'ifdef LIB_NAME'#010+
   '        -$(DEL) $(LIB_NAME) $(LIB_FULLNAME)'#010+
   'endif'#010+
@@ -1228,7 +1227,7 @@ const fpcmakeini : array[0..125,1..240] of char=(
   #010+
   'fpc_distclean: clean'#010+
   #010+
-  '# Also run clean first if targetdir is set. Unittargetdir is always',#010+
+  '# Also run clean first if targetdir is set. Unittarg','etdir is always'#010+
   '# set if targetdir or unittargetdir is specified'#010+
   'ifdef COMPILER_UNITTARGETDIR'#010+
   'TARGETDIRCLEAN=fpc_clean'#010+
@@ -1238,17 +1237,17 @@ const fpcmakeini : array[0..125,1..240] of char=(
   'ifdef CLEANEXEFILES'#010+
   '        -$(DEL) $(CLEANEXEFILES)'#010+
   'endif'#010+
-  '        -$(DEL) *$(OEXT',') *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICL'+
+  '        ','-$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICL'+
   'IBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)'#010+
   '        -$(DELTREE) *$(SMARTEXT)'#010+
   '        -$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)'+
   #010+
   'ifdef AOUTEXT'#010+
-  '        -$(DEL) *$(AOUTEXT)'#010+
+  '        -$(DEL) *$(AOUTEXT)',#010+
   'endif'#010+
   #010+
   #010+
-  '[infor','ules]'#010+
+  '[inforules]'#010+
   '#####################################################################'#010+
   '# Info rules'#010+
   '#####################################################################'#010+
@@ -1257,76 +1256,76 @@ const fpcmakeini : array[0..125,1..240] of char=(
   #010+
   'fpc_info:'#010+
   '        @$(ECHO)'#010+
-  '        @$(ECHO)  == Package info =','='#010+
+  '        @$(ECHO)  ==',' Package info =='#010+
   '        @$(ECHO)  Package Name..... $(PACKAGE_NAME)'#010+
   '        @$(ECHO)  Package Version.. $(PACKAGE_VERSION)'#010+
   '        @$(ECHO)'#010+
   '        @$(ECHO)  == Configuration info =='#010+
   '        @$(ECHO)'#010+
-  '        @$(ECHO)  FPC.......... $(FPC)'#010+
-  '        @$(ECHO',')  FPC Version.. $(FPC_VERSION)'#010+
+  '        @$(ECHO)  FPC.......... $(FPC)'#010,
+  '        @$(ECHO)  FPC Version.. $(FPC_VERSION)'#010+
   '        @$(ECHO)  Source CPU... $(CPU_SOURCE)'#010+
   '        @$(ECHO)  Target CPU... $(CPU_TARGET)'#010+
   '        @$(ECHO)  Source OS.... $(OS_SOURCE)'#010+
   '        @$(ECHO)  Target OS.... $(OS_TARGET)'#010+
-  '        @$(ECHO)'#010+
-  '        @','$(ECHO)  == Directory info =='#010+
+  '        @$(','ECHO)'#010+
+  '        @$(ECHO)  == Directory info =='#010+
   '        @$(ECHO)'#010+
   '        @$(ECHO)  Basedir......... $(BASEDIR)'#010+
   '        @$(ECHO)  FPCDir.......... $(FPCDIR)'#010+
   '        @$(ECHO)  UnitsDir........ $(UNITSDIR)'#010+
-  '        @$(ECHO)  PackagesDir..... $(PACKAGESDIR)'#010+
-  '     ','   @$(ECHO)'#010+
+  '        @$(ECHO)  PackagesDir..... $(PAC','KAGESDIR)'#010+
+  '        @$(ECHO)'#010+
   '        @$(ECHO)  GCC library..... $(GCCLIBDIR)'#010+
   '        @$(ECHO)  Other library... $(OTHERLIBDIR)'#010+
   '        @$(ECHO)'#010+
   '        @$(ECHO)  == Tools info =='#010+
   '        @$(ECHO)'#010+
   '        @$(ECHO)  Pwd....... $(PWD)'#010+
-  '        @$(ECHO)  Mv.....','... $(MVPROG)'#010+
+  '        @$','(ECHO)  Mv........ $(MVPROG)'#010+
   '        @$(ECHO)  Cp........ $(CPPROG)'#010+
   '        @$(ECHO)  Rm........ $(RMPROG)'#010+
   '        @$(ECHO)  GInstall.. $(GINSTALL)'#010+
   '        @$(ECHO)  Echo...... $(ECHO)'#010+
   '        @$(ECHO)  Date...... $(DATE)'#010+
-  '        @$(ECHO)  FPCMake... $(FP','CMAKE)'#010+
+  '        @$(ECHO)  ','FPCMake... $(FPCMAKE)'#010+
   '        @$(ECHO)  PPUMove... $(PPUMOVE)'#010+
   '        @$(ECHO)  Upx....... $(UPXPROG)'#010+
   '        @$(ECHO)  Zip....... $(ZIPPROG)'#010+
   '        @$(ECHO)'#010+
   '        @$(ECHO)  == Object info =='#010+
   '        @$(ECHO)'#010+
-  '        @$(ECHO)  Target Loaders...... $(TA','RGET_LOADERS)'#010+
+  '        @$(ECHO)  Target Loa','ders...... $(TARGET_LOADERS)'#010+
   '        @$(ECHO)  Target Units........ $(TARGET_UNITS)'#010+
   '        @$(ECHO)  Target Programs..... $(TARGET_PROGRAMS)'#010+
   '        @$(ECHO)  Target Dirs......... $(TARGET_DIRS)'#010+
-  '        @$(ECHO)  Target Examples..... $(TARGET_EXAMPLES)'#010+
-  ' ','       @$(ECHO)  Target ExampleDirs.. $(TARGET_EXAMPLEDIRS)'#010+
+  '        @$(ECHO)  Target Examples..... $(TAR','GET_EXAMPLES)'#010+
+  '        @$(ECHO)  Target ExampleDirs.. $(TARGET_EXAMPLEDIRS)'#010+
   '        @$(ECHO)'#010+
   '        @$(ECHO)  Clean Units......... $(CLEAN_UNITS)'#010+
   '        @$(ECHO)  Clean Files......... $(CLEAN_FILES)'#010+
   '        @$(ECHO)'#010+
-  '        @$(ECHO)  Install Units.......',' $(INSTALL_UNITS)'#010+
+  '        @$(ECHO)  Insta','ll Units....... $(INSTALL_UNITS)'#010+
   '        @$(ECHO)  Install Files....... $(INSTALL_FILES)'#010+
   '        @$(ECHO)'#010+
   '        @$(ECHO)  == Install info =='#010+
   '        @$(ECHO)'#010+
   '        @$(ECHO)  DateStr.............. $(DATESTR)'#010+
-  '        @$(ECHO)  ZipPrefix............ $(ZI','PPREFIX)'#010+
+  '        @$(ECHO)  ZipPrefix..','.......... $(ZIPPREFIX)'#010+
   '        @$(ECHO)  ZipSuffix............ $(ZIPSUFFIX)'#010+
   '        @$(ECHO)  Install FPC Package.. $(INSTALL_FPCPACKAGE)'#010+
   '        @$(ECHO)'#010+
   '        @$(ECHO)  Install base dir..... $(INSTALL_BASEDIR)'#010+
-  '        @$(ECHO)  Install binary dir... ','$(INSTALL_BINDIR)'#010+
+  '        @$(ECHO)  Install',' binary dir... $(INSTALL_BINDIR)'#010+
   '        @$(ECHO)  Install library dir.. $(INSTALL_LIBDIR)'#010+
   '        @$(ECHO)  Install units dir.... $(INSTALL_UNITDIR)'#010+
   '        @$(ECHO)  Install source dir... $(INSTALL_SOURCEDIR)'#010+
-  '        @$(ECHO)  Install doc dir...... $(IN','STALL_DOCDIR)'#010+
+  '        @$(ECHO)  Install doc',' dir...... $(INSTALL_DOCDIR)'#010+
   '        @$(ECHO)  Install example dir.. $(INSTALL_EXAMPLEDIR)'#010+
   '        @$(ECHO)  Install data dir..... $(INSTALL_DATADIR)'#010+
   '        @$(ECHO)'#010+
   '        @$(ECHO)  Dist destination dir. $(DIST_DESTDIR)'#010+
-  '        @$(ECHO)  Dist zip name.','....... $(DIST_ZIPNAME)'#010+
+  '        @$(ECHO) ',' Dist zip name........ $(DIST_ZIPNAME)'#010+
   '        @$(ECHO)'#010+
   #010+
   '[localmakefile]'#010+
@@ -1334,7 +1333,7 @@ const fpcmakeini : array[0..125,1..240] of char=(
   '# Local Makefile'#010+
   '#####################################################################'#010+
   #010+
-  'ifneq ($(wildcard fpcmak','e.loc),)'#010+
+  'ifneq ($(','wildcard fpcmake.loc),)'#010+
   'include fpcmake.loc'#010+
   'endif'#010+
   #010+

+ 1 - 1
utils/fpcm/fpcmake.ini

@@ -974,7 +974,7 @@ ifdef FPCMAKE
 # a safety check is done if Makefile.fpc is available
 ifdef PACKAGE_VERSION
 ifneq ($(wildcard Makefile.fpc),)
-        $(FPCMAKE) -p Makefile.fpc
+        $(FPCMAKE) -p -T$(OS_TARGET) Makefile.fpc
         $(MKDIR) $(INSTALL_UNITDIR)
         $(INSTALL) Package.fpc $(INSTALL_UNITDIR)
 endif

+ 55 - 31
utils/fpcm/fpcmake.pp

@@ -16,6 +16,9 @@
 {$H+}
 program fpcmake;
 
+{ Define to not catch exceptions and output backtraces }
+{ define NOEXCEPT}
+
     uses
       getopts,
       sysutils,
@@ -33,8 +36,9 @@ program fpcmake;
       end;
 
     var
-      Mode : TMode;
-      VerboseLevel : TVerboseLevel;
+      ParaMode : TMode;
+      ParaVerboseLevel : TVerboseLevel;
+      ParaTargets : string;
 
 
 {*****************************************************************************
@@ -43,7 +47,7 @@ program fpcmake;
 
     procedure Show(lvl:TVerboseLevel;const s:string);
       begin
-        if VerboseLevel>=lvl then
+        if ParaVerboseLevel>=lvl then
          Writeln(s);
       end;
 
@@ -88,9 +92,13 @@ program fpcmake;
       begin
         Show(V_Default,'Processing '+fn);
         CurrFPCMake:=nil;
-//        try
+{$ifndef NOEXCEPT}
+        try
+{$endif NOEXCEPT}
           { Load Makefile.fpc }
           CurrFPCMake:=TFPCMakeConsole.Create(fn);
+          if ParaTargets<>'' then
+           CurrFPCMake.SetTargets(ParaTargets);
           CurrFPCMake.LoadMakefileFPC;
 //          CurrFPCMake.Print;
 
@@ -105,13 +113,17 @@ program fpcmake;
           CurrMakefile.WriteGenericMakefile;
           CurrMakefile.Free;
 
-//        except
-//          on e : exception do
-//           begin
-//             Error(e.message);
-//             Subdirs:='';
-//           end;
-//        end;
+{$ifndef NOEXCEPT}
+        except
+          on e : exception do
+           begin
+             Error(e.message);
+  {$ifdef SUBDIRS}
+             Subdirs:='';
+  {$endif SUBDIRS}
+           end;
+        end;
+{$endif NOEXCEPT}
         CurrFPCMake.Free;
 
 {$ifdef SUBDIRS}
@@ -138,9 +150,13 @@ program fpcmake;
       begin
         Show(V_Default,'Processing '+fn);
         CurrFPCMake:=nil;
-//        try
+{$ifndef NOEXCEPT}
+        try
+{$endif NOEXCEPT}
           { Load Makefile.fpc }
           CurrFPCMake:=TFPCMakeConsole.Create(fn);
+          if ParaTargets<>'' then
+           CurrFPCMake.SetTargets(ParaTargets);
           CurrFPCMake.LoadMakefileFPC;
 //          CurrFPCMake.Print;
 
@@ -149,20 +165,21 @@ program fpcmake;
           CurrPackageFpc.WritePackageFpc;
           CurrPackageFpc.Free;
 
-//        except
-//          on e : exception do
-//           begin
-//             Error(e.message);
-//             Subdirs:='';
-//           end;
-//        end;
+{$ifndef NOEXCEPT}
+        except
+          on e : exception do
+           begin
+             Error(e.message);
+           end;
+        end;
+{$endif NOEXCEPT}
         CurrFPCMake.Free;
       end;
 
 
     procedure ProcessFile(const fn:string);
       begin
-        case Mode of
+        case ParaMode of
           m_None :
             Error('No operation specified, see -h for help');
           m_Makefile :
@@ -205,9 +222,10 @@ begin
   writeln(' -w  Write Makefile');
   writeln('');
   writeln('Options:');
-  writeln(' -v  Be more verbose');
-  writeln(' -q  Be quiet');
-  writeln(' -h  This help screen');
+  writeln(' -T<target>[,target]   Support only specified targets');
+  writeln(' -v                    Be more verbose');
+  writeln(' -q                    Be quiet');
+  writeln(' -h                    This help screen');
   Halt(0);
 end;
 
@@ -218,23 +236,24 @@ Procedure ProcessOpts;
   Process command line opions, and checks if command line options OK.
 }
 const
-  ShortOpts = 'pwqvh';
+  ShortOpts = 'pwqvhT:';
 var
   C : char;
 begin
   if paramcount=0 then
    usage;
 { Reset }
-  Mode:=m_none;
-  VerboseLevel:=v_default;
+  ParaMode:=m_none;
+  ParaVerboseLevel:=v_default;
   repeat
     c:=Getopt (ShortOpts);
     Case C of
       EndOfOptions : break;
-      'p' : Mode:=m_PackageFpc;
-      'w' : Mode:=m_Makefile;
-      'q' : VerboseLevel:=v_quiet;
-      'v' : VerboseLevel:=v_verbose;
+      'p' : ParaMode:=m_PackageFpc;
+      'w' : ParaMode:=m_Makefile;
+      'q' : ParaVerboseLevel:=v_quiet;
+      'v' : ParaVerboseLevel:=v_verbose;
+      'T' : ParaTargets:=OptArg;
       '?' : Usage;
       'h' : Usage;
     end;
@@ -251,7 +270,12 @@ begin
 end.
 {
   $Log$
-  Revision 1.5  2001-07-13 21:01:59  peter
+  Revision 1.6  2001-08-02 20:50:29  peter
+    * -T<target> support
+    * better error reporting for not found dirs
+    * some cleanups and nicer strings
+
+  Revision 1.5  2001/07/13 21:01:59  peter
     * cygdrive support
     * fixed cygwin detection
     * fixed some duplicate and extraeous spaces

+ 117 - 32
utils/fpcm/fpcmmain.pp

@@ -30,8 +30,8 @@ interface
       fpcmdic;
 
     const
-      Version='v1.99.0';
-      Title='fpcmake '+Version;
+      Version='1.1';
+      Title='FPCMake Version '+Version;
       TitleDate=Title+' ['+{$ifdef fpc}{$i %DATE}{$else}'n/a'{$endif}+']';
 
     type
@@ -107,7 +107,8 @@ interface
         FExportSec      : TFPCMakeSection;
         FIsPackage      : boolean;
         FPackageName,
-        FPackageVersion : string;
+        FPackageVersion,
+        FPackageTargets : string;
         FRequireList    : TTargetRequireList;
         FVariables      : TKeyValue;
         FIncludeTargets : TTargetSet;
@@ -127,6 +128,7 @@ interface
         constructor CreateFromStream(s:TStream;const AFileName:string);
         destructor  Destroy;override;
         procedure Verbose(lvl:TFPCMakeVerbose;const s:string);virtual;
+        procedure SetTargets(const s:string);
         procedure LoadSections;
         procedure LoadMakefileFPC;
         procedure LoadPackageSection;
@@ -153,7 +155,8 @@ interface
       end;
 
     function posidx(const substr,s : string;idx:integer):integer;
-    function GetToken(var s:string):string;
+    function GetToken(var s:string;sep:char):string;
+    procedure AddToken(var s:string;const tok:string;sep:char);
 
 
 implementation
@@ -167,6 +170,15 @@ implementation
       s_no_package_name='No package name set';
       s_no_package_version='No package version set';
       s_err_require_format='Wrong require format "%s"';
+      s_wrong_package_name='Package name "%s" expected, but "%s" found';
+      s_wrong_package_version='Package version "%s" expected, but version "%s" found';
+      s_directory_not_found='Directory "%s" not found';
+      s_makefilefpc_not_found='No Makefile.fpc found in directory "%s"';
+      s_package_not_found='Package "%s" not found';
+      s_fpcmake_version_required='FPCMake version "%s" is required';
+      s_no_targets_set='No targets set';
+      s_targets_info='Targets: "%s"';
+      s_globals='Globals:';
 
 
 {****************************************************************************
@@ -218,12 +230,12 @@ implementation
       end;
 
 
-    function GetToken(var s:string):string;
+    function GetToken(var s:string;sep:char):string;
       var
         i : integer;
       begin
         s:=Trim(s);
-        i:=pos(' ',s);
+        i:=pos(sep,s);
         if i=0 then
          begin
            Result:=s;
@@ -237,6 +249,17 @@ implementation
       end;
 
 
+    procedure AddToken(var s:string;const tok:string;sep:char);
+      begin
+        if tok='' then
+         exit;
+        if s<>'' then
+         s:=s+sep+tok
+        else
+         s:=tok;
+      end;
+
+
 {****************************************************************************
                                TKeyValueItem
 ****************************************************************************}
@@ -390,10 +413,7 @@ implementation
            p:=TKeyValueItem(FDictionary.Search(NewKey));
            { Concat values if key already exists }
            if assigned(p) then
-            begin
-              if Value<>'' then
-               p.Value:=p.Value+' '+Value
-            end
+            AddToken(p.FValue,Value,' ')
            else
             FDictionary.Add(NewKey,Value);
            inc(i);
@@ -579,9 +599,39 @@ implementation
       end;
 
 
+    procedure TFPCMake.SetTargets(const s:string);
+      var
+        hslst : string;
+        hs : string;
+        t  : TTarget;
+      begin
+        FIncludeTargets:=[];
+        hslst:=s;
+        repeat
+          hs:=LowerCase(GetToken(hslst,','));
+          if hs='' then
+           break;
+          for t:=low(TTarget) to high(TTarget) do
+           if hs=TargetStr[t] then
+            include(FIncludeTargets,t);
+        until false;
+        if FIncludeTargets=[] then
+         raise Exception.Create(s_no_targets_set)
+        else
+         begin
+           hs:='';
+           for t:=low(TTarget) to high(TTarget) do
+            if t in FIncludeTargets then
+             AddToken(hs,TargetStr[t],' ');
+           Verbose(FPCMakeDebug,Format(s_targets_info,[hs]));
+         end;
+      end;
+
+
     procedure TFPCMake.LoadPackageSection;
       var
-        s : string;
+        hs,s : string;
+        t : TTarget;
       begin
         { Get package info from package section }
         FPackageSec:=TFPCMakeSection(FSections['package']);
@@ -607,6 +657,20 @@ implementation
            if FPackageVersion='' then
             Raise Exception.Create(s_no_package_version);
            FIsPackage:=true;
+           { optional targets }
+           FPackageTargets:='';
+           s:=LowerCase(FPackageSec['targets']);
+           repeat
+             hs:=GetToken(s,' ');
+             if hs='' then
+              break;
+             for t:=low(TTarget) to high(TTarget) do
+              if hs=TargetStr[t] then
+               begin
+                 AddToken(FPackageTargets,hs,' ');
+                 break;
+               end;
+           until false;
            { Set the ExportSec }
            FExportSec:=TFPCMakeSection(FSections[Lowercase(FPackageName)]);
          end;
@@ -653,9 +717,9 @@ implementation
              ReqFPCMake.LoadPackageSection;
              { Check package name and version }
              if LowerCase(ReqFPCMake.PackageName)<>ReqName then
-              raise Exception.Create('s_wrong_package_name');
+              raise Exception.Create(Format(s_wrong_package_name,[ReqName,LowerCase(ReqFPCMake.PackageName)]));
              if (ReqVersion<>'') and (ReqFPCMake.PackageVersion<ReqVersion) then
-              raise Exception.Create('s_wrong_package_version');
+              raise Exception.Create(Format(s_wrong_package_version,[ReqVersion,ReqFPCMake.PackageVersion]));
              { First load the requirements of this package }
              LoadRequires(t,ReqFPCMake);
              { Get a copy of the package section }
@@ -684,7 +748,7 @@ implementation
         s:=SubstVariables('$(wildcard $(addsuffix /'+ReqName+'/Package.fpc,$(FPCDIR)) $(addsuffix /'+ReqName+'/Package.fpc,$(UNITSDIR)) $(addsuffix /'+ReqName+'/Package.fpc,$(REQUIRE_UNITSDIR)))');
         if TryFile(s) then
          exit;
-        Raise Exception.Create('s_package_not_found '+Reqname);
+        Raise Exception.Create(Format(s_package_not_found,[Reqname]));
       end;
 
 
@@ -694,9 +758,16 @@ implementation
           s : string;
         begin
           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');
+          s:=currdir+subdir;
+          Verbose(FPCMakeDebug,'Subdir: '+s+'/Makefile.fpc');
+          if not FileExists(s+'/Makefile.fpc') then
+           begin
+             { give better error what is wrong }
+             if not PathExists(s) then
+              Raise Exception.Create(Format(s_directory_not_found,[s]))
+             else
+              Raise Exception.Create(Format(s_makefilefpc_not_found,[s]));
+           end;
           { Process Makefile.fpc }
           ReqFPCMake:=TFPCMake.Create(currdir+subdir+'/Makefile.fpc');
           ReqFPCMake.LoadSections;
@@ -733,7 +804,7 @@ implementation
         s:=Trim(FromFPCMake.GetVariable('require_packages',true)+' '+FromFPCMake.GetVariable('require_packages'+TargetSuffix[t],true));
         Verbose(FPCMakeDebug,'Required packages for '+TargetStr[t]+': '+s);
         repeat
-          reqname:=GetToken(s);
+          reqname:=GetToken(s,' ');
           if reqname='' then
            break;
           i:=Pos('(',ReqName);
@@ -760,7 +831,7 @@ implementation
         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);
+          reqdir:=GetToken(s,' ');
           if reqdir='' then
            break;
           LoadRequiredDir(t,FromFPCMake.FPackageName,ExtractFilePath(FromFPCMake.FFileName),ReqDir)
@@ -795,6 +866,10 @@ implementation
         s : string;
         t : ttarget;
       begin
+        { Check FPCMake version }
+        s:=GetVariable('require_fpcmake',false);
+        if (s>version) then
+         raise Exception.Create(Format(s_fpcmake_version_required,[s]));
         { Maybe add an implicit rtl dependency if there is something
           to compile }
         s:=GetVariable('require_packages',false);
@@ -828,7 +903,7 @@ implementation
         begin
           s:=Sec['packages']+' '+Sec['packages'+TargetSuffix[t]];
           repeat
-            ReqName:=GetToken(s);
+            ReqName:=GetToken(s,' ');
             if ReqName='' then
              break;
             i:=Pos('(',ReqName);
@@ -852,7 +927,6 @@ implementation
         ReqSec:=TFPCMakeSection(FSections['require']);
         if assigned(ReqSec) then
          AddReqSec(t,ReqSec);
-        Verbose(FPCMakeInfo,TargetStr[t]+' requires: '+ReqList.CommaText);
         GetTargetRequires:=ReqList;
       end;
 
@@ -908,8 +982,17 @@ implementation
         if hs='' then
          begin
            s:=GetVariable('default_fpcdir',true);
+           { add the current subdir to relative paths }
            if s<>'' then
-            hs:=SubstVariables('$(wildcard $(addprefix '+s+'/,rtl units))');
+            begin
+{$ifdef UNIX}
+              if (s[1]<>'/') then
+{$else}
+              if (length(s)>2) and (s[2]<>':') then
+{$endif}
+               s:=ExtractFilePath(FFileName)+s;
+              hs:=SubstVariables('$(wildcard $(addprefix '+s+'/,rtl units))');
+            end
          end;
         { OS defaults }
         if hs='' then
@@ -962,7 +1045,7 @@ implementation
         if GetVariable('UNITSDIR',false)='' then
          SetVariable('UNITSDIR','$(FPCDIR)/units/$(TARGET)',false);
 
-        Verbose(FPCMakeDebug,'Globals:');
+        Verbose(FPCMakeDebug,s_globals);
         Variables.Foreach(@PrintDic);
       end;
 
@@ -1021,7 +1104,7 @@ implementation
                 Expect(s,')');
                 first:=true;
                 repeat
-                  tok:=GetToken(s1);
+                  tok:=GetToken(s1,' ');
                   if tok='' then
                    break;
                   if PathOrFileExists(tok) then
@@ -1046,7 +1129,7 @@ implementation
                  end;
                 first:=true;
                 repeat
-                  tok:=GetToken(s2);
+                  tok:=GetToken(s2,' ');
                   if tok='' then
                    break;
                   if not first then
@@ -1068,7 +1151,7 @@ implementation
                  end;
                 first:=true;
                 repeat
-                  tok:=GetToken(s2);
+                  tok:=GetToken(s2,' ');
                   if tok='' then
                    break;
                   if not first then
@@ -1160,11 +1243,8 @@ implementation
            p:=TKeyValueItem(Sec.Dictionary.Search(Key));
            if assigned(p) then
             begin
-              if Add and (p.Value<>'') then
-               begin
-                 if Value<>'' then
-                  p.Value:=p.Value+' '+Value;
-               end
+              if Add then
+               AddToken(p.FValue,Value,' ')
               else
                p.Value:=Value;
             end
@@ -1234,7 +1314,12 @@ implementation
 end.
 {
   $Log$
-  Revision 1.10  2001-07-31 22:02:32  peter
+  Revision 1.11  2001-08-02 20:50:29  peter
+    * -T<target> support
+    * better error reporting for not found dirs
+    * some cleanups and nicer strings
+
+  Revision 1.10  2001/07/31 22:02:32  peter
     * install Package.fpc
 
   Revision 1.9  2001/07/24 09:06:40  pierre

+ 70 - 56
utils/fpcm/fpcmwr.pp

@@ -323,7 +323,8 @@ implementation
            exit;
          end;
         for t:=low(TTarget) to high(TTarget) do
-         if FInput.GetVariable(IniVar+TargetSuffix[t],false)<>'' then
+         if (t in FInput.IncludeTargets) and
+            (FInput.GetVariable(IniVar+TargetSuffix[t],false)<>'') then
           begin
             result:=true;
             exit;
@@ -346,15 +347,16 @@ implementation
         if s<>'' then
          FOutput.Add('override '+FixVariable(IniVar)+'+='+s);
         for t:=low(TTarget) to high(TTarget) do
-         begin
-           s:=FInput.GetVariable(IniVar+TargetSuffix[t],false);
-           if s<>'' then
-            begin
-              FOutput.Add('ifeq ($(OS_TARGET),'+TargetStr[t]+')');
-              FOutput.Add('override '+FixVariable(IniVar)+'+='+s);
-              FOutput.Add('endif');
-            end;
-         end;
+         if t in FInput.IncludeTargets then
+          begin
+            s:=FInput.GetVariable(IniVar+TargetSuffix[t],false);
+            if s<>'' then
+             begin
+               FOutput.Add('ifeq ($(OS_TARGET),'+TargetStr[t]+')');
+               FOutput.Add('override '+FixVariable(IniVar)+'+='+s);
+               FOutput.Add('endif');
+             end;
+          end;
       end;
 
 
@@ -378,7 +380,7 @@ implementation
         result:='';
         s:=FInput.GetVariable(IniVar,false);
         repeat
-          name:=GetToken(s);
+          name:=GetToken(s,' ');
           if Name='' then
            break;
           { Remove (..) }
@@ -395,31 +397,32 @@ implementation
           AddStrNoDup(result,name);
         until false;
         for t:=low(TTarget) to high(TTarget) do
-         begin
-           s:=FInput.GetVariable(IniVar+TargetSuffix[t],false);
-           if s<>'' then
-            begin
-              FOutput.Add('ifeq ($(OS_TARGET),'+TargetStr[t]+')');
-              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);
-              until false;
-              FOutput.Add('endif');
-            end;
-         end;
+         if t in FInput.IncludeTargets then
+          begin
+            s:=FInput.GetVariable(IniVar+TargetSuffix[t],false);
+            if s<>'' then
+             begin
+               FOutput.Add('ifeq ($(OS_TARGET),'+TargetStr[t]+')');
+               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);
+               until false;
+               FOutput.Add('endif');
+             end;
+          end;
       end;
 
 
@@ -457,7 +460,7 @@ implementation
       begin
         hs:=FInput.GetVariable(inivar,false);
         repeat
-          Tool:=GetToken(hs);
+          Tool:=GetToken(hs,' ');
           if Tool='' then
            break;
           AddTool(FixVariable(Tool),Tool,'');
@@ -566,7 +569,7 @@ implementation
         prefix:=FixVariable(inivar)+'_';
         hs:=AddTargetDefines(inivar,prefix);
         repeat
-          Dir:=GetToken(hs);
+          Dir:=GetToken(hs,' ');
           if Dir='' then
            break;
           AddTargetDir(Dir,prefix);
@@ -629,23 +632,26 @@ implementation
         reqs:='';
         { Add target defines }
         for t:=low(ttarget) to high(ttarget) do
-         begin
-           sl:=FInput.GetTargetRequires(t);
-           if sl.count>0 then
-            begin
-              FOutput.Add('ifeq ($(OS_TARGET),'+TargetStr[t]+')');
-              for i:=0 to sl.count-1 do
-               begin
-                 FOutput.Add(prefix+VarName(sl[i])+'=1');
-                 AddStrNoDup(reqs,sl[i]);
-               end;
-              FOutput.Add('endif');
-            end;
-           sl.Free;
-         end;
+         if t in FInput.IncludeTargets then
+          begin
+            sl:=FInput.GetTargetRequires(t);
+            { show info }
+            FInput.Verbose(FPCMakeInfo,TargetStr[t]+' requires: '+sl.CommaText);
+            if sl.count>0 then
+             begin
+               FOutput.Add('ifeq ($(OS_TARGET),'+TargetStr[t]+')');
+               for i:=0 to sl.count-1 do
+                begin
+                  FOutput.Add(prefix+VarName(sl[i])+'=1');
+                  AddStrNoDup(reqs,sl[i]);
+                end;
+               FOutput.Add('endif');
+             end;
+            sl.Free;
+          end;
         { Add all require packages }
         repeat
-          req:=GetToken(reqs);
+          req:=GetToken(reqs,' ');
           if Req='' then
            break;
           AddPackage(req,prefix);
@@ -716,8 +722,10 @@ implementation
               (not CheckTargetVariable('install_files')) and
               (not CheckTargetVariable('install_createpackagefpc')) then
             FHasSection[sec_install]:=false;
+           { Package.fpc also needs to be cleaned }
            if (not CheckTargetVariable('clean_units')) and
-              (not CheckTargetVariable('clean_files')) then
+              (not CheckTargetVariable('clean_files')) and
+              (not CheckTargetVariable('install_createpackagefpc')) then
             FHasSection[sec_clean]:=false;
          end;
       end;
@@ -763,6 +771,7 @@ implementation
            { Package }
            AddVariable('package_name');
            AddVariable('package_version');
+           AddVariable('package_targets');
            { First add the required packages sections }
 //           for i:=0 to FInput.RequireList.Count-1 do
 //            AddCustomSection(FInput.Requirelist[i]);
@@ -789,7 +798,7 @@ implementation
            AddVariable('install_basedir');
            AddVariable('install_datadir');
            AddVariable('install_fpcpackage');
-	   AddVariable('install_createpackagefpc');
+           AddVariable('install_createpackagefpc');
            { Dist }
            AddVariable('dist_zipname');
            AddVariable('dist_ziptarget');
@@ -865,7 +874,12 @@ implementation
 end.
 {
   $Log$
-  Revision 1.14  2001-07-31 22:02:32  peter
+  Revision 1.15  2001-08-02 20:50:29  peter
+    * -T<target> support
+    * better error reporting for not found dirs
+    * some cleanups and nicer strings
+
+  Revision 1.14  2001/07/31 22:02:32  peter
     * install Package.fpc
 
   Revision 1.13  2001/07/13 21:01:59  peter