Browse Source

* better package dep creation

peter 25 years ago
parent
commit
87d843fbbd
3 changed files with 763 additions and 773 deletions
  1. 336 331
      utils/fpcmake.inc
  2. 332 330
      utils/fpcmake.ini
  3. 95 112
      utils/fpcmake.pp

File diff suppressed because it is too large
+ 336 - 331
utils/fpcmake.inc


+ 332 - 330
utils/fpcmake.ini

@@ -170,137 +170,19 @@ endif
 # Pre Settings
 #####################################################################
 
+
 [usersettings]
 #####################################################################
 # User Settings
 #####################################################################
 
+
 [postsettings]
 #####################################################################
 # Post Settings
 #####################################################################
 
 
-[dir_default]
-#####################################################################
-# Default Directories
-#####################################################################
-
-# set the prefix directory where to install everything
-ifndef PREFIXINSTALLDIR
-ifdef inlinux
-PREFIXINSTALLDIR=/usr
-else
-PREFIXINSTALLDIR=/pp
-endif
-endif
-export PREFIXINSTALLDIR
-
-
-[dir_install]
-#####################################################################
-# Install Directories
-#####################################################################
-
-# set the base directory where to install everything
-ifndef BASEINSTALLDIR
-ifdef inlinux
-BASEINSTALLDIR=$(PREFIXINSTALLDIR)/lib/fpc/$(FPC_VERSION)
-else
-BASEINSTALLDIR=$(PREFIXINSTALLDIR)
-endif
-endif
-
-# set the directory where to install the binaries
-ifndef BININSTALLDIR
-ifdef inlinux
-BININSTALLDIR=$(PREFIXINSTALLDIR)/bin
-else
-BININSTALLDIR=$(BASEINSTALLDIR)/bin/$(OS_TARGET)
-endif
-endif
-
-# set the directory where to install the units.
-ifndef UNITINSTALLDIR
-UNITINSTALLDIR=$(BASEINSTALLDIR)/units/$(OS_TARGET)
-ifdef UNITSUBDIR
-UNITINSTALLDIR:=$(UNITINSTALLDIR)/$(UNITSUBDIR)
-endif
-endif
-
-# Where to install shared libraries
-ifndef LIBINSTALLDIR
-ifdef inlinux
-LIBINSTALLDIR=$(PREFIXINSTALLDIR)/lib
-else
-LIBINSTALLDIR=$(UNITINSTALLDIR)
-endif
-endif
-
-# Where the source files will be stored
-ifndef SOURCEINSTALLDIR
-ifdef inlinux
-SOURCEINSTALLDIR=$(PREFIXINSTALLDIR)/src/fpc-$(FPC_VERSION)
-else
-SOURCEINSTALLDIR=$(BASEINSTALLDIR)/source
-endif
-endif
-
-# Where the doc files will be stored
-ifndef DOCINSTALLDIR
-ifdef inlinux
-DOCINSTALLDIR=$(PREFIXINSTALLDIR)/doc/fpc-$(FPC_VERSION)
-else
-DOCINSTALLDIR=$(BASEINSTALLDIR)/doc
-endif
-endif
-
-# Where the some extra (data)files will be stored
-ifndef DATAINSTALLDIR
-DATAINSTALLDIR=$(BASEINSTALLDIR)
-endif
-
-
-[dir_gcclib]
-# On linux, try to find where libgcc.a is.
-ifdef inlinux
-ifndef GCCLIBDIR
-GCCLIBDIR:=$(shell dirname `(gcc -v 2>&1)| head -n 1| awk '{ print $$4 } '`)
-endif
-endif
-export GCCLIBDIR
-
-
-[dir_otherlib]
-# Where to find other libraries
-ifdef inlinux
-ifndef OTHERLIBDIR
-OTHERLIBDIR:=$(shell grep -v "^\#" /etc/ld.so.conf | awk '{ ORS=" "; print $1 }')
-endif
-endif
-export OTHERLIBDIR
-
-
-[redir]
-#####################################################################
-# Redirection
-#####################################################################
-
-# Release ? Then force OPT and don't use extra opts via commandline
-ifndef REDIRFILE
-REDIRFILE=log
-endif
-
-ifdef REDIR
-ifndef inlinux
-override FPC=redir -eo $(FPC)
-endif
-# set the verbosity to max
-override FPCOPT+=-va
-override REDIR:= >> $(REDIRFILE)
-endif
-
-
 [shelltools]
 #####################################################################
 # Shell tools
@@ -376,240 +258,102 @@ endif
 export ECHO COPY COPYTREE MOVE DEL DELTREE INSTALL INSTALLEXE MKDIR
 
 
-[command_begin]
+[tool_default]
 #####################################################################
-# Compiler Command Line
+# Default Tools
 #####################################################################
 
-# Load commandline OPTDEF and add FPC_CPU define
-override FPCOPTDEF:=-d$(CPU_TARGET)
-
-# Load commandline OPT and add target and unit dir to be sure
-ifneq ($(OS_TARGET),$(OS_SOURCE))
-override FPCOPT+=-T$(OS_TARGET)
+# assembler, redefine it if cross compiling
+ifndef AS
+AS=as
 endif
 
-[command_needopt]
-ifdef NEEDOPT
-override FPCOPT+=$(NEEDOPT)
+# linker, but probably not used
+ifndef LD
+LD=ld
 endif
 
-
-[command_needunit]
-ifdef NEEDUNITDIR
-override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
+# ppas.bat / ppas.sh
+ifdef inlinux
+PPAS=ppas.sh
+else
+ifdef inOS2
+PPAS=ppas.cmd
+else
+PPAS=ppas.bat
 endif
-
-
-[command_unitsdir]
-ifdef UNITSDIR
-override FPCOPT+=-Fu$(UNITSDIR)
 endif
 
-
-[command_needlib]
-ifdef NEEDLIBDIR
-override FPCOPT+=$(addprefix -Fl,$(NEEDLIBDIR))
+# also call ppas if with command option -s
+ifeq (,$(findstring -s ,$(COMPILER)))
+EXECPPAS=
+else
+EXECPPAS:=@$(PPAS)
 endif
 
-
-[command_needobj]
-ifdef NEEDOBJDIR
-override FPCOPT+=$(addprefix -Fo,$(NEEDOBJDIR))
+# ldconfig to rebuild .so cache
+ifdef inlinux
+LDCONFIG=ldconfig
+else
+LDCONFIG=
 endif
 
-
-[command_needinc]
-ifdef NEEDINCDIR
-override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
+[tool_ppdep]
+# ppdep
+ifndef PPDEP
+PPDEP:=$(strip $(wildcard $(addsuffix /ppdep$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(PPDEP),)
+PPDEP=
+else
+PPDEP:=$(firstword $(PPDEP))
 endif
-
-[command_gcclib]
-# Add GCC lib path if asked
-ifdef GCCLIBDIR
-override FPCOPT+=-Fl$(GCCLIBDIR)
 endif
+export PPDEP
 
-[command_otherlib]
-# Add Other dirs path if asked
-ifdef OTHERLIBDIR
-override FPCOPT+=$(addprefix -Fl,$(OTHERLIBDIR))
+[tool_ppumove]
+# ppumove
+ifndef PPUMOVE
+PPUMOVE:=$(strip $(wildcard $(addsuffix /ppumove$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUMOVE),)
+PPUMOVE=
+else
+PPUMOVE:=$(firstword $(PPUMOVE))
 endif
-
-[command_target]
-# Target dirs
-ifdef TARGETDIR
-override FPCOPT+=-FE$(TARGETDIR)
 endif
+export PPUMOVE
 
-[command_unittarget]
-ifdef UNITTARGETDIR
-override FPCOPT+=-FU$(UNITTARGETDIR)
+[tool_ppufiles]
+# ppufiles
+ifndef PPUFILES
+PPUFILES:=$(strip $(wildcard $(addsuffix /ppufiles$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUFILES),)
+PPUFILES=
+else
+PPUFILES:=$(firstword $(PPUFILES))
 endif
-
-[command_end]
-# Smartlinking
-ifdef SMARTLINK
-override FPCOPT+=-CX
 endif
+export PPUFILES
 
-# Debug
-ifdef DEBUG
-override FPCOPT+=-g -dDEBUG
+[tool_data2inc]
+# data2inc
+ifndef DATA2INC
+DATA2INC:=$(strip $(wildcard $(addsuffix /data2inc$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(DATA2INC),)
+DATA2INC=
+else
+DATA2INC:=$(firstword $(DATA2INC))
 endif
-
-# Release mode (strip, optimize and don't load ppc386.cfg)
-ifdef RELEASE
-override FPCOPT+=-Xs -OG2p3 -n
 endif
+export DATA2INC
 
-# Verbose settings (warning,note,info)
-ifdef VERBOSE
-override FPCOPT+=-vwni
-endif
-
-# Add commandline options
-ifdef OPT
-override FPCOPT+=$(OPT)
-endif
-ifdef UNITDIR
-override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
-endif
-ifdef LIBDIR
-override FPCOPT+=$(addprefix -Fl,$(LIBDIR))
-endif
-ifdef OBJDIR
-override FPCOPT+=$(addprefix -Fo,$(OBJDIR))
-endif
-ifdef INCDIR
-override FPCOPT+=$(addprefix -Fi,$(INCDIR))
-endif
-
-# Add defines from FPCOPTDEF to FPCOPT
-ifdef FPCOPTDEF
-override FPCOPT+=$(FPCOPTDEF)
-endif
-
-# Error file ?
-ifdef ERRORFILE
-override FPCOPT+=-Fr$(ERRORFILE)
-endif
-
-# Was a config file specified ?
-ifdef CFGFILE
-override FPCOPT+=@$(CFGFILE)
-endif
-
-# For win32 the options are passed using the file fpcext.cmd
-ifndef FPCEXTCMD
-FPCEXTCMD=fpcext.cmd
-endif
-ifeq ($(OS_SOURCE),win32)
-override TMPVAR:=$(shell "$(DEL) $(FPCEXTCMD)")
-override TMPVAR:=$(foreach A,$(FPCOPT),$(shell "$(ECHO) $(A) >> $(FPCEXTCMD)"))
-override FPCOPT:=@$(FPCEXTCMD)
-endif
-
-# Compiler commandline
-override COMPILER:=$(FPC) $(FPCOPT)
-
-
-[tool_default]
-#####################################################################
-# Default Tools
-#####################################################################
-
-# assembler, redefine it if cross compiling
-ifndef AS
-AS=as
-endif
-
-# linker, but probably not used
-ifndef LD
-LD=ld
-endif
-
-# ppas.bat / ppas.sh
-ifdef inlinux
-PPAS=ppas.sh
-else
-ifdef inOS2
-PPAS=ppas.cmd
-else
-PPAS=ppas.bat
-endif
-endif
-
-# also call ppas if with command option -s
-ifeq (,$(findstring -s ,$(COMPILER)))
-EXECPPAS=
-else
-EXECPPAS:=@$(PPAS)
-endif
-
-# ldconfig to rebuild .so cache
-ifdef inlinux
-LDCONFIG=ldconfig
-else
-LDCONFIG=
-endif
-
-[tool_ppdep]
-# ppdep
-ifndef PPDEP
-PPDEP:=$(strip $(wildcard $(addsuffix /ppdep$(EXEEXT),$(SEARCHPATH))))
-ifeq ($(PPDEP),)
-PPDEP=
-else
-PPDEP:=$(firstword $(PPDEP))
-endif
-endif
-export PPDEP
-
-[tool_ppumove]
-# ppumove
-ifndef PPUMOVE
-PPUMOVE:=$(strip $(wildcard $(addsuffix /ppumove$(EXEEXT),$(SEARCHPATH))))
-ifeq ($(PPUMOVE),)
-PPUMOVE=
-else
-PPUMOVE:=$(firstword $(PPUMOVE))
-endif
-endif
-export PPUMOVE
-
-[tool_ppufiles]
-# ppufiles
-ifndef PPUFILES
-PPUFILES:=$(strip $(wildcard $(addsuffix /ppufiles$(EXEEXT),$(SEARCHPATH))))
-ifeq ($(PPUFILES),)
-PPUFILES=
-else
-PPUFILES:=$(firstword $(PPUFILES))
-endif
-endif
-export PPUFILES
-
-[tool_data2inc]
-# data2inc
-ifndef DATA2INC
-DATA2INC:=$(strip $(wildcard $(addsuffix /data2inc$(EXEEXT),$(SEARCHPATH))))
-ifeq ($(DATA2INC),)
-DATA2INC=
-else
-DATA2INC:=$(firstword $(DATA2INC))
-endif
-endif
-export DATA2INC
-
-[tool_diff]
-# diff
-ifndef DIFF
-DIFF:=$(strip $(wildcard $(addsuffix /diff$(EXEEXT),$(SEARCHPATH))))
-ifeq ($(DIFF),)
-DIFF=
-else
-DIFF:=$(firstword $(DIFF))
+[tool_diff]
+# diff
+ifndef DIFF
+DIFF:=$(strip $(wildcard $(addsuffix /diff$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(DIFF),)
+DIFF=
+else
+DIFF:=$(firstword $(DIFF))
 endif
 endif
 export DIFF
@@ -790,6 +534,264 @@ PASEXT=.pas
 endif
 endif
 
+
+[dir_default]
+#####################################################################
+# Default Directories
+#####################################################################
+
+# set the prefix directory where to install everything
+ifndef PREFIXINSTALLDIR
+ifdef inlinux
+PREFIXINSTALLDIR=/usr
+else
+PREFIXINSTALLDIR=/pp
+endif
+endif
+export PREFIXINSTALLDIR
+
+
+[dir_install]
+#####################################################################
+# Install Directories
+#####################################################################
+
+# set the base directory where to install everything
+ifndef BASEINSTALLDIR
+ifdef inlinux
+BASEINSTALLDIR=$(PREFIXINSTALLDIR)/lib/fpc/$(FPC_VERSION)
+else
+BASEINSTALLDIR=$(PREFIXINSTALLDIR)
+endif
+endif
+
+# set the directory where to install the binaries
+ifndef BININSTALLDIR
+ifdef inlinux
+BININSTALLDIR=$(PREFIXINSTALLDIR)/bin
+else
+BININSTALLDIR=$(BASEINSTALLDIR)/bin/$(OS_TARGET)
+endif
+endif
+
+# set the directory where to install the units.
+ifndef UNITINSTALLDIR
+UNITINSTALLDIR=$(BASEINSTALLDIR)/units/$(OS_TARGET)
+ifdef UNITSUBDIR
+UNITINSTALLDIR:=$(UNITINSTALLDIR)/$(UNITSUBDIR)
+endif
+endif
+
+# Where to install shared libraries
+ifndef LIBINSTALLDIR
+ifdef inlinux
+LIBINSTALLDIR=$(PREFIXINSTALLDIR)/lib
+else
+LIBINSTALLDIR=$(UNITINSTALLDIR)
+endif
+endif
+
+# Where the source files will be stored
+ifndef SOURCEINSTALLDIR
+ifdef inlinux
+SOURCEINSTALLDIR=$(PREFIXINSTALLDIR)/src/fpc-$(FPC_VERSION)
+else
+SOURCEINSTALLDIR=$(BASEINSTALLDIR)/source
+endif
+endif
+
+# Where the doc files will be stored
+ifndef DOCINSTALLDIR
+ifdef inlinux
+DOCINSTALLDIR=$(PREFIXINSTALLDIR)/doc/fpc-$(FPC_VERSION)
+else
+DOCINSTALLDIR=$(BASEINSTALLDIR)/doc
+endif
+endif
+
+# Where the some extra (data)files will be stored
+ifndef DATAINSTALLDIR
+DATAINSTALLDIR=$(BASEINSTALLDIR)
+endif
+
+
+[dir_gcclib]
+# On linux, try to find where libgcc.a is.
+ifdef inlinux
+ifndef GCCLIBDIR
+GCCLIBDIR:=$(shell dirname `(gcc -v 2>&1)| head -n 1| awk '{ print $$4 } '`)
+endif
+endif
+export GCCLIBDIR
+
+
+[dir_otherlib]
+# Where to find other libraries
+ifdef inlinux
+ifndef OTHERLIBDIR
+OTHERLIBDIR:=$(shell grep -v "^\#" /etc/ld.so.conf | awk '{ ORS=" "; print $1 }')
+endif
+endif
+export OTHERLIBDIR
+
+
+[redir]
+#####################################################################
+# Redirection
+#####################################################################
+
+# Release ? Then force OPT and don't use extra opts via commandline
+ifndef REDIRFILE
+REDIRFILE=log
+endif
+
+ifdef REDIR
+ifndef inlinux
+override FPC=redir -eo $(FPC)
+endif
+# set the verbosity to max
+override FPCOPT+=-va
+override REDIR:= >> $(REDIRFILE)
+endif
+
+[command_begin]
+#####################################################################
+# Compiler Command Line
+#####################################################################
+
+# Load commandline OPTDEF and add FPC_CPU define
+override FPCOPTDEF:=-d$(CPU_TARGET)
+
+# Load commandline OPT and add target and unit dir to be sure
+ifneq ($(OS_TARGET),$(OS_SOURCE))
+override FPCOPT+=-T$(OS_TARGET)
+endif
+
+[command_needopt]
+ifdef NEEDOPT
+override FPCOPT+=$(NEEDOPT)
+endif
+
+
+[command_needunit]
+ifdef NEEDUNITDIR
+override FPCOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
+endif
+
+
+[command_unitsdir]
+ifdef UNITSDIR
+override FPCOPT+=-Fu$(UNITSDIR)
+endif
+
+
+[command_needlib]
+ifdef NEEDLIBDIR
+override FPCOPT+=$(addprefix -Fl,$(NEEDLIBDIR))
+endif
+
+
+[command_needobj]
+ifdef NEEDOBJDIR
+override FPCOPT+=$(addprefix -Fo,$(NEEDOBJDIR))
+endif
+
+
+[command_needinc]
+ifdef NEEDINCDIR
+override FPCOPT+=$(addprefix -Fi,$(NEEDINCDIR))
+endif
+
+[command_gcclib]
+# Add GCC lib path if asked
+ifdef GCCLIBDIR
+override FPCOPT+=-Fl$(GCCLIBDIR)
+endif
+
+[command_otherlib]
+# Add Other dirs path if asked
+ifdef OTHERLIBDIR
+override FPCOPT+=$(addprefix -Fl,$(OTHERLIBDIR))
+endif
+
+[command_target]
+# Target dirs
+ifdef TARGETDIR
+override FPCOPT+=-FE$(TARGETDIR)
+endif
+
+[command_unittarget]
+ifdef UNITTARGETDIR
+override FPCOPT+=-FU$(UNITTARGETDIR)
+endif
+
+[command_end]
+# Smartlinking
+ifdef SMARTLINK
+override FPCOPT+=-CX
+endif
+
+# Debug
+ifdef DEBUG
+override FPCOPT+=-g -dDEBUG
+endif
+
+# Release mode (strip, optimize and don't load ppc386.cfg)
+ifdef RELEASE
+override FPCOPT+=-Xs -OG2p3 -n
+endif
+
+# Verbose settings (warning,note,info)
+ifdef VERBOSE
+override FPCOPT+=-vwni
+endif
+
+# Add commandline options
+ifdef OPT
+override FPCOPT+=$(OPT)
+endif
+ifdef UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
+endif
+ifdef LIBDIR
+override FPCOPT+=$(addprefix -Fl,$(LIBDIR))
+endif
+ifdef OBJDIR
+override FPCOPT+=$(addprefix -Fo,$(OBJDIR))
+endif
+ifdef INCDIR
+override FPCOPT+=$(addprefix -Fi,$(INCDIR))
+endif
+
+# Add defines from FPCOPTDEF to FPCOPT
+ifdef FPCOPTDEF
+override FPCOPT+=$(FPCOPTDEF)
+endif
+
+# Error file ?
+ifdef ERRORFILE
+override FPCOPT+=-Fr$(ERRORFILE)
+endif
+
+# Was a config file specified ?
+ifdef CFGFILE
+override FPCOPT+=@$(CFGFILE)
+endif
+
+# For win32 the options are passed using the file fpcext.cmd
+ifndef FPCEXTCMD
+FPCEXTCMD=fpcext.cmd
+endif
+ifeq ($(OS_SOURCE),win32)
+override TMPVAR:=$(shell "$(DEL) $(FPCEXTCMD)")
+override TMPVAR:=$(foreach A,$(FPCOPT),$(shell "$(ECHO) $(A) >> $(FPCEXTCMD)"))
+override FPCOPT:=@$(FPCEXTCMD)
+endif
+
+# Compiler commandline
+override COMPILER:=$(FPC) $(FPCOPT)
+
+
 [standardrules]
 #####################################################################
 # Standard rules
@@ -902,7 +904,7 @@ fpc_test: examples
 $(FPCMADE): $(ALLTARGET)
         @$(ECHO) Compiled > $(FPCMADE)
 
-fpc_packages: $(addsuffix _package,$(COMPILEPACKAGES))
+fpc_packages: $(COMPILEPACKAGES)
 
 fpc_all: fpc_packages $(FPCMADE)
 
@@ -1046,7 +1048,7 @@ fpc_sourceinstall: clean
 # Temporary path to pack a file
 ifndef PACKDIR
 ifndef inlinux
-PACKDIR=pack_tmp
+PACKDIR=$(BASEDIR)/pack_tmp
 else
 PACKDIR=/tmp/fpc-pack
 endif

+ 95 - 112
utils/fpcmake.pp

@@ -609,60 +609,6 @@ var
       end;
   end;
 
-  procedure AddTargetsUnitDir(const packpre:string;var t:TTargetsString);
-  var
-    i,j,k : integer;
-    hs,pack,packdirvar,unitdirvar,unitdir,packdir : string;
-  begin
-    for i:=0 to targets do
-     if (t[i]<>'') then
-      begin
-        hs:=t[i];
-        repeat
-          j:=pos(' ',hs);
-          if j=0 then
-           j:=length(hs)+1;
-          pack:=Copy(hs,1,j-1);
-          packdirvar:='PACKAGEDIR_'+VarName(pack);
-          unitdirvar:='UNITDIR_'+VarName(pack);
-          packdir:=packpre+'/'+pack;
-          unitdir:='$(UNITSDIR)/'+pack;
-          for k:=1to specialdirs do
-           begin
-             if specialdir[k].dir=pack then
-              begin
-                packdir:=specialdir[k].packdir;
-                unitdir:=specialdir[k].unitdir;
-                break;
-              end;
-           end;
-          mf.Add('ifneq ($(wildcard '+packdir+'),)');
-          mf.Add('ifneq ($(wildcard '+packdir+'/$(OS_TARGET)),)');
-          mf.Add(packdirvar+'='+packdir+'/$(OS_TARGET)');
-          mf.Add('else');
-          mf.Add(packdirvar+'='+packdir);
-          mf.Add('endif');
-          mf.Add(unitdirvar+'=$('+packdirvar+')');
-          mf.Add('else');
-          mf.Add(packdirvar+'=');
-          mf.Add('ifneq ($(wildcard '+unitdir+'),)');
-          mf.Add('ifneq ($(wildcard '+unitdir+'/$(OS_TARGET)),)');
-          mf.Add(unitdirvar+'='+unitdir+'/$(OS_TARGET)');
-          mf.Add('else');
-          mf.Add(unitdirvar+'='+unitdir);
-          mf.Add('endif');
-          mf.Add('else');
-          mf.Add(unitdirvar+'=');
-          mf.Add('endif');
-          mf.Add('endif');
-          mf.Add('ifdef '+unitdirvar);
-          mf.Add('override NEEDUNITDIR+=$('+unitdirvar+')');
-          mf.Add('endif');
-          system.delete(hs,1,j);
-        until hs='';
-      end;
-  end;
-
   procedure AddTargetDir(const s:string);
   var
     j  : integer;
@@ -685,22 +631,6 @@ var
     mf.Add('endif');
   end;
 
-  procedure AddPackageDep(const s:string);
-  var
-    packagedir : string;
-  begin
-    packagedir:='$(PACKAGEDIR_'+VarName(s)+')';
-    mf.Add('ifdef PACKAGE'+VarName(s));
-    mf.Add('ifneq ($(wildcard '+packagedir+'),)');
-    mf.Add('override COMPILEPACKAGES+='+s);
-    mf.Add(s+'_package: '+packagedir+'/$(FPCMADE)');
-    mf.Add(packagedir+'/$(FPCMADE):');
-    mf.Add(#9'$(MAKE) -C '+packagedir+' all');
-    mf.Add('endif');
-    mf.Add('endif');
-    Phony:=Phony+' '+s+'_package';
-  end;
-
   function AddTargetDefines(const ts:TTargetsString;const prefix:string):string;
   var
     j,i : integer;
@@ -728,7 +658,61 @@ var
      AddTargetDefines:=hs2;
   end;
 
-  procedure AddTargetsPackageDep(const ts:TTargetsString);
+  procedure AddPackage(const path,pack:string);
+  var
+    k : integer;
+    packdirvar,unitdirvar,unitdir,packdir : string;
+  begin
+    mf.Add('ifdef PACKAGE'+VarName(pack));
+    { create needed variables }
+    packdirvar:='PACKAGEDIR_'+VarName(pack);
+    unitdirvar:='UNITDIR_'+VarName(pack);
+    packdir:=path+'/'+pack;
+    unitdir:='$(UNITSDIR)/'+pack;
+    for k:=1to specialdirs do
+     begin
+       if specialdir[k].dir=pack then
+        begin
+          packdir:=specialdir[k].packdir;
+          unitdir:=specialdir[k].unitdir;
+          break;
+        end;
+     end;
+    mf.Add('ifneq ($(wildcard '+packdir+'),)');
+    { Use Package dir, add build rules }
+    mf.Add('ifneq ($(wildcard '+packdir+'/$(OS_TARGET)),)');
+    mf.Add(packdirvar+'='+packdir+'/$(OS_TARGET)');
+    mf.Add('else');
+    mf.Add(packdirvar+'='+packdir);
+    mf.Add('endif');
+    mf.Add('ifeq ($(wildcard $('+packdirvar+')/$(FPCMADE)),)');
+    mf.Add('override COMPILEPACKAGES+=package_'+pack);
+    Phony:=Phony+'package_'+pack;
+    mf.Add('package_'+pack+':');
+    mf.Add(#9'$(MAKE) -C $('+packdirvar+') all');
+    mf.Add('endif');
+    mf.Add(unitdirvar+'=$('+packdirvar+')');
+    mf.Add('else');
+    { Package dir doesn''t exists, create unit dir }
+    mf.Add(packdirvar+'=');
+    mf.Add('ifneq ($(wildcard '+unitdir+'),)');
+    mf.Add('ifneq ($(wildcard '+unitdir+'/$(OS_TARGET)),)');
+    mf.Add(unitdirvar+'='+unitdir+'/$(OS_TARGET)');
+    mf.Add('else');
+    mf.Add(unitdirvar+'='+unitdir);
+    mf.Add('endif');
+    mf.Add('else');
+    mf.Add(unitdirvar+'=');
+    mf.Add('endif');
+    mf.Add('endif');
+    { Add Unit dir to the command line -Fu }
+    mf.Add('ifdef '+unitdirvar);
+    mf.Add('override NEEDUNITDIR+=$('+unitdirvar+')');
+    mf.Add('endif');
+    mf.Add('endif');
+  end;
+
+  procedure AddTargetsPackages(const path:string;const ts:TTargetsString);
   var
     Phony,hs : string;
     i  : integer;
@@ -737,12 +721,14 @@ var
      Phony:='';
      if not TargetStringEmpty(ts) then
       begin
+        AddHead(VarName(path)+' packages');
         hs:=AddTargetDefines(ts,'PACKAGE');
+        mf.Add('');
         repeat
           i:=pos(' ',hs);
           if i=0 then
            i:=length(hs)+1;
-          AddPackageDep(Copy(hs,1,i-1));
+          AddPackage(path,Copy(hs,1,i-1));
           system.delete(hs,1,i);
         until hs='';
         mf.Add('');
@@ -892,9 +878,15 @@ begin
 
    { Packages }
      AddHead('Packages');
+     Phony:='';
      AddTargets('PACKAGES',userini.Requirepackages,false);
      AddTargets('TOOLKITS',userini.Requiretoolkits,false);
      AddTargets('COMPONENTS',userini.Requirecomponents,false);
+     if Phony<>'' then
+      begin
+        Add('.PHONY: '+Phony);
+        Add('');
+      end;
 
    { Libs }
      AddHead('Libraries');
@@ -934,12 +926,35 @@ begin
         Add('');
       end;
 
+   { shell tools like copy,del,echo }
+     AddSection(userini.section[sec_command] or userini.section[sec_tools],'shelltools');
+
+   { write tools }
+     if userini.section[sec_tools] then
+      begin
+        AddSection(true,'tool_default');
+        AddSection(userini.toolsppdep,'tool_ppdep');
+        AddSection(userini.toolsppumove,'tool_ppumove');
+        AddSection(userini.toolsppufiles,'tool_ppufiles');
+        AddSection(userini.toolsdata2inc,'tool_data2inc');
+        AddSection(userini.toolsupx,'tool_upx');
+        AddSection(userini.toolssed,'tool_sed');
+        AddSection(userini.toolsdate,'tool_date');
+        AddSection(userini.toolszip,'tool_zip');
+        AddSection(userini.toolscmp,'tool_cmp');
+        AddSection(userini.toolsdiff,'tool_diff');
+      end;
+
+   { extensions }
+     if userini.section[sec_exts] then
+      AddSection(true,'extensions');
+
    { package/component dirs }
-     AddHead('Package/component dirs');
+     AddSection(true,'packagerequirerules');
      AddSection(userini.requirertl,'checkfpcdirsubs');
-     AddTargetsUnitDir('$(TOOLKITSDIR)',userini.Requiretoolkits);
-     AddTargetsUnitDir('$(PACKAGESDIR)',userini.Requirepackages);
-     AddTargetsUnitDir('$(COMPONENTSDIR)',userini.Requirecomponents);
+     AddTargetsPackages('$(PACKAGESDIR)',userini.Requirepackages);
+     AddTargetsPackages('$(TOOLKITSDIR)',userini.Requiretoolkits);
+     AddTargetsPackages('$(COMPONENTSDIR)',userini.Requirecomponents);
      Add('');
 
    { write dirs }
@@ -954,9 +969,6 @@ begin
    { redirection }
      AddSection(true,'redir');
 
-   { shell tools like copy,del,echo }
-     AddSection(userini.section[sec_command] or userini.section[sec_tools],'shelltools');
-
    { commandline }
      if userini.section[sec_command] then
       begin
@@ -980,26 +992,6 @@ begin
         AddSection(true,'command_end');
       end;
 
-   { write tools }
-     if userini.section[sec_tools] then
-      begin
-        AddSection(true,'tool_default');
-        AddSection(userini.toolsppdep,'tool_ppdep');
-        AddSection(userini.toolsppumove,'tool_ppumove');
-        AddSection(userini.toolsppufiles,'tool_ppufiles');
-        AddSection(userini.toolsdata2inc,'tool_data2inc');
-        AddSection(userini.toolsupx,'tool_upx');
-        AddSection(userini.toolssed,'tool_sed');
-        AddSection(userini.toolsdate,'tool_date');
-        AddSection(userini.toolszip,'tool_zip');
-        AddSection(userini.toolscmp,'tool_cmp');
-        AddSection(userini.toolsdiff,'tool_diff');
-      end;
-
-   { extensions }
-     if userini.section[sec_exts] then
-      AddSection(true,'extensions');
-
    { add default rules }
      AddSection(true,'standardrules');
      Phony:='';
@@ -1011,18 +1003,6 @@ begin
         Add('');
       end;
 
-   { Package requirements, must be before the other rules so it's done first }
-     AddSection(true,'packagerequirerules');
-     Phony:='';
-     AddTargetsPackageDep(userini.RequireToolkits);
-     AddTargetsPackageDep(userini.RequirePackages);
-     AddTargetsPackageDep(userini.RequireComponents);
-     if Phony<>'' then
-      begin
-        Add('.PHONY: '+Phony);
-        Add('');
-      end;
-
    { compile rules for making loaders/units/exes/examples }
      AddSection(not TargetStringEmpty(userini.targetloaders),'loaderrules');
      AddSection(not TargetStringEmpty(userini.targetunits),'unitrules');
@@ -1134,7 +1114,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.23  2000-01-12 23:20:37  peter
+  Revision 1.24  2000-01-13 11:34:26  peter
+    * better package dep creation
+
+  Revision 1.23  2000/01/12 23:20:37  peter
     * gecho support
     * use foreach to write fpcext.cmd
     * add fpcext.cmd to clean targets

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