Browse Source

* readded makefile

peter 24 years ago
parent
commit
e8a328c8c7
1 changed files with 124 additions and 55 deletions
  1. 124 55
      fcl/tests/Makefile

+ 124 - 55
fcl/tests/Makefile

@@ -1,12 +1,12 @@
 #
 #
-# Makefile generated by fpcmake v0.99.15 [2000/07/02]
+# Makefile generated by fpcmake v1.00 [2000/10/27]
 #
 #
 
 
 defaultrule: all
 defaultrule: all
 
 
 #####################################################################
 #####################################################################
 # Autodetect OS (Linux or Dos or Windows NT)
 # Autodetect OS (Linux or Dos or Windows NT)
-# define inlinux when running under linux
+# define inUnix when running under Unix (Linux,FreeBSD)
 # define inWinNT when running under WinNT
 # define inWinNT when running under WinNT
 #####################################################################
 #####################################################################
 
 
@@ -23,22 +23,18 @@ nopwd:
 	@echo Get ftp://ftp.freepascal.org/pub/fpc/dist/go32v2/utilgo32.zip
 	@echo Get ftp://ftp.freepascal.org/pub/fpc/dist/go32v2/utilgo32.zip
 	@exit
 	@exit
 else
 else
-inlinux=1
+inUnix=1
 endif
 endif
 else
 else
 PWD:=$(firstword $(PWD))
 PWD:=$(firstword $(PWD))
 endif
 endif
 
 
 # Detect NT - NT sets OS to Windows_NT
 # Detect NT - NT sets OS to Windows_NT
-ifndef inlinux
+# Detect OS/2 - OS/2 has OS2_SHELL defined
+ifndef inUnix
 ifeq ($(OS),Windows_NT)
 ifeq ($(OS),Windows_NT)
 inWinNT=1
 inWinNT=1
-endif
-endif
-
-# Detect OS/2 - OS/2 has OS2_SHELL defined
-ifndef inlinux
-ifndef inWinNT
+else
 ifdef OS2_SHELL
 ifdef OS2_SHELL
 inOS2=1
 inOS2=1
 endif
 endif
@@ -46,14 +42,14 @@ endif
 endif
 endif
 
 
 # The extension of executables
 # The extension of executables
-ifdef inlinux
-EXEEXT=
+ifdef inUnix
+SRCEXEEXT=
 else
 else
-EXEEXT=.exe
+SRCEXEEXT=.exe
 endif
 endif
 
 
 # The path which is searched separated by spaces
 # The path which is searched separated by spaces
-ifdef inlinux
+ifdef inUnix
 SEARCHPATH=$(subst :, ,$(PATH))
 SEARCHPATH=$(subst :, ,$(PATH))
 else
 else
 SEARCHPATH=$(subst ;, ,$(PATH))
 SEARCHPATH=$(subst ;, ,$(PATH))
@@ -76,15 +72,11 @@ ifndef FPC
 ifdef PP
 ifdef PP
 FPC=$(PP)
 FPC=$(PP)
 else
 else
-ifdef inOS2
-FPC=ppos2
-else
 FPC=ppc386
 FPC=ppc386
 endif
 endif
 endif
 endif
-endif
-override FPC:=$(subst $(EXEEXT),,$(FPC))
-override FPC:=$(subst \,/,$(FPC))$(EXEEXT)
+override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
+override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)
 
 
 # Target OS
 # Target OS
 ifndef OS_TARGET
 ifndef OS_TARGET
@@ -141,7 +133,7 @@ endif
 
 
 # Detect FPCDIR
 # Detect FPCDIR
 ifeq ($(FPCDIR),wrong)
 ifeq ($(FPCDIR),wrong)
-ifdef inlinux
+ifdef inUnix
 override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION)
 override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION)
 ifeq ($(wildcard $(FPCDIR)/units),)
 ifeq ($(wildcard $(FPCDIR)/units),)
 override FPCDIR=/usr/lib/fpc/$(FPC_VERSION)
 override FPCDIR=/usr/lib/fpc/$(FPC_VERSION)
@@ -235,7 +227,7 @@ INFOTARGET=fpc_infocfg fpc_infoobjects fpc_infoinstall
 ifndef ECHO
 ifndef ECHO
 ECHO:=$(strip $(wildcard $(addsuffix /gecho$(EXEEXT),$(SEARCHPATH))))
 ECHO:=$(strip $(wildcard $(addsuffix /gecho$(EXEEXT),$(SEARCHPATH))))
 ifeq ($(ECHO),)
 ifeq ($(ECHO),)
-ECHO:=$(strip $(wildcard $(addsuffix /echo$(EXEEXT),$(SEARCHPATH))))
+ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH))))
 ifeq ($(ECHO),)
 ifeq ($(ECHO),)
 ECHO:=echo
 ECHO:=echo
 ECHOE:=echo
 ECHOE:=echo
@@ -276,8 +268,8 @@ endif
 
 
 # To install files
 # To install files
 ifndef INSTALL
 ifndef INSTALL
-ifdef inlinux
-INSTALL:=install -m 644
+ifdef inUnix
+INSTALL:=install -c -m 644
 else
 else
 INSTALL:=$(COPY)
 INSTALL:=$(COPY)
 endif
 endif
@@ -285,8 +277,8 @@ endif
 
 
 # To install programs
 # To install programs
 ifndef INSTALLEXE
 ifndef INSTALLEXE
-ifdef inlinux
-INSTALLEXE:=install -m 755
+ifdef inUnix
+INSTALLEXE:=install -c -m 755
 else
 else
 INSTALLEXE:=$(COPY)
 INSTALLEXE:=$(COPY)
 endif
 endif
@@ -294,7 +286,7 @@ endif
 
 
 # To make a directory.
 # To make a directory.
 ifndef MKDIR
 ifndef MKDIR
-ifdef inlinux
+ifdef inUnix
 MKDIR:=install -m 755 -d
 MKDIR:=install -m 755 -d
 else
 else
 MKDIR:=ginstall -m 755 -d
 MKDIR:=ginstall -m 755 -d
@@ -318,7 +310,7 @@ LD=ld
 endif
 endif
 
 
 # ppas.bat / ppas.sh
 # ppas.bat / ppas.sh
-ifdef inlinux
+ifdef inUnix
 PPAS=ppas.sh
 PPAS=ppas.sh
 else
 else
 ifdef inOS2
 ifdef inOS2
@@ -329,7 +321,7 @@ endif
 endif
 endif
 
 
 # ldconfig to rebuild .so cache
 # ldconfig to rebuild .so cache
-ifdef inlinux
+ifdef inUnix
 LDCONFIG=ldconfig
 LDCONFIG=ldconfig
 else
 else
 LDCONFIG=
 LDCONFIG=
@@ -337,7 +329,7 @@ endif
 
 
 # ppumove
 # ppumove
 ifndef PPUMOVE
 ifndef PPUMOVE
-PPUMOVE:=$(strip $(wildcard $(addsuffix /ppumove$(EXEEXT),$(SEARCHPATH))))
+PPUMOVE:=$(strip $(wildcard $(addsuffix /ppumove$(SRCEXEEXT),$(SEARCHPATH))))
 ifeq ($(PPUMOVE),)
 ifeq ($(PPUMOVE),)
 PPUMOVE=
 PPUMOVE=
 else
 else
@@ -348,7 +340,7 @@ export PPUMOVE
 
 
 # ppufiles
 # ppufiles
 ifndef PPUFILES
 ifndef PPUFILES
-PPUFILES:=$(strip $(wildcard $(addsuffix /ppufiles$(EXEEXT),$(SEARCHPATH))))
+PPUFILES:=$(strip $(wildcard $(addsuffix /ppufiles$(SRCEXEEXT),$(SEARCHPATH))))
 ifeq ($(PPUFILES),)
 ifeq ($(PPUFILES),)
 PPUFILES=
 PPUFILES=
 else
 else
@@ -367,7 +359,7 @@ ifeq ($(OS_TARGET),win32)
 UPXPROG:=1
 UPXPROG:=1
 endif
 endif
 ifdef UPXPROG
 ifdef UPXPROG
-UPXPROG:=$(strip $(wildcard $(addsuffix /upx$(EXEEXT),$(SEARCHPATH))))
+UPXPROG:=$(strip $(wildcard $(addsuffix /upx$(SRCEXEEXT),$(SEARCHPATH))))
 ifeq ($(UPXPROG),)
 ifeq ($(UPXPROG),)
 UPXPROG=
 UPXPROG=
 else
 else
@@ -381,7 +373,7 @@ export UPXPROG
 
 
 # ZipProg, you can't use Zip as the var name (PFV)
 # ZipProg, you can't use Zip as the var name (PFV)
 ifndef ZIPPROG
 ifndef ZIPPROG
-ZIPPROG:=$(strip $(wildcard $(addsuffix /zip$(EXEEXT),$(SEARCHPATH))))
+ZIPPROG:=$(strip $(wildcard $(addsuffix /zip$(SRCEXEEXT),$(SEARCHPATH))))
 ifeq ($(ZIPPROG),)
 ifeq ($(ZIPPROG),)
 ZIPPROG=
 ZIPPROG=
 else
 else
@@ -395,7 +387,7 @@ ZIPEXT=.zip
 
 
 # Tar
 # Tar
 ifndef TARPROG
 ifndef TARPROG
-TARPROG:=$(strip $(wildcard $(addsuffix /tar$(EXEEXT),$(SEARCHPATH))))
+TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH))))
 ifeq ($(TARPROG),)
 ifeq ($(TARPROG),)
 TARPROG=
 TARPROG=
 else
 else
@@ -418,6 +410,7 @@ endif
 
 
 # Default needed extensions (Go32v2,Linux)
 # Default needed extensions (Go32v2,Linux)
 LOADEREXT=.as
 LOADEREXT=.as
+EXEEXT=.exe
 PPLEXT=.ppl
 PPLEXT=.ppl
 PPUEXT=.ppu
 PPUEXT=.ppu
 OEXT=.o
 OEXT=.o
@@ -446,9 +439,18 @@ endif
 
 
 # Linux
 # Linux
 ifeq ($(OS_TARGET),linux)
 ifeq ($(OS_TARGET),linux)
+EXEEXT=
+HASSHAREDLIB=1
 FPCMADE=fpcmade.lnx
 FPCMADE=fpcmade.lnx
 endif
 endif
 
 
+# Linux
+ifeq ($(OS_TARGET),freebsd)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.freebsd
+endif
+
 # Win32
 # Win32
 ifeq ($(OS_TARGET),win32)
 ifeq ($(OS_TARGET),win32)
 PPUEXT=.ppw
 PPUEXT=.ppw
@@ -643,9 +645,30 @@ endif
 # Default Directories
 # Default Directories
 #####################################################################
 #####################################################################
 
 
+# Linux and freebsd use unix dirs with /usr/bin, /usr/lib
+# When zipping use the target as default, when normal install then
+# use the source os as default
+ifdef ZIPNAME
+# Zipinstall
+ifeq ($(OS_TARGET),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+UNIXINSTALLDIR=1
+endif
+else
+# Normal install
+ifeq ($(OS_SOURCE),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_SOURCE),freebsd)
+UNIXINSTALLDIR=1
+endif
+endif
+
 # set the prefix directory where to install everything
 # set the prefix directory where to install everything
 ifndef PREFIXINSTALLDIR
 ifndef PREFIXINSTALLDIR
-ifdef inlinux
+ifdef UNIXINSTALLDIR
 PREFIXINSTALLDIR=/usr
 PREFIXINSTALLDIR=/usr
 else
 else
 PREFIXINSTALLDIR=/pp
 PREFIXINSTALLDIR=/pp
@@ -665,7 +688,7 @@ export DESTZIPDIR
 
 
 # set the base directory where to install everything
 # set the base directory where to install everything
 ifndef BASEINSTALLDIR
 ifndef BASEINSTALLDIR
-ifdef inlinux
+ifdef UNIXINSTALLDIR
 BASEINSTALLDIR=$(PREFIXINSTALLDIR)/lib/fpc/$(FPC_VERSION)
 BASEINSTALLDIR=$(PREFIXINSTALLDIR)/lib/fpc/$(FPC_VERSION)
 else
 else
 BASEINSTALLDIR=$(PREFIXINSTALLDIR)
 BASEINSTALLDIR=$(PREFIXINSTALLDIR)
@@ -674,7 +697,7 @@ endif
 
 
 # set the directory where to install the binaries
 # set the directory where to install the binaries
 ifndef BININSTALLDIR
 ifndef BININSTALLDIR
-ifdef inlinux
+ifdef UNIXINSTALLDIR
 BININSTALLDIR=$(PREFIXINSTALLDIR)/bin
 BININSTALLDIR=$(PREFIXINSTALLDIR)/bin
 else
 else
 BININSTALLDIR=$(BASEINSTALLDIR)/bin/$(OS_TARGET)
 BININSTALLDIR=$(BASEINSTALLDIR)/bin/$(OS_TARGET)
@@ -691,7 +714,7 @@ endif
 
 
 # Where to install shared libraries
 # Where to install shared libraries
 ifndef LIBINSTALLDIR
 ifndef LIBINSTALLDIR
-ifdef inlinux
+ifdef UNIXINSTALLDIR
 LIBINSTALLDIR=$(PREFIXINSTALLDIR)/lib
 LIBINSTALLDIR=$(PREFIXINSTALLDIR)/lib
 else
 else
 LIBINSTALLDIR=$(UNITINSTALLDIR)
 LIBINSTALLDIR=$(UNITINSTALLDIR)
@@ -700,7 +723,7 @@ endif
 
 
 # Where the source files will be stored
 # Where the source files will be stored
 ifndef SOURCEINSTALLDIR
 ifndef SOURCEINSTALLDIR
-ifdef inlinux
+ifdef UNIXINSTALLDIR
 SOURCEINSTALLDIR=$(PREFIXINSTALLDIR)/src/fpc-$(FPC_VERSION)
 SOURCEINSTALLDIR=$(PREFIXINSTALLDIR)/src/fpc-$(FPC_VERSION)
 else
 else
 SOURCEINSTALLDIR=$(BASEINSTALLDIR)/source
 SOURCEINSTALLDIR=$(BASEINSTALLDIR)/source
@@ -712,7 +735,7 @@ endif
 
 
 # Where the doc files will be stored
 # Where the doc files will be stored
 ifndef DOCINSTALLDIR
 ifndef DOCINSTALLDIR
-ifdef inlinux
+ifdef UNIXINSTALLDIR
 DOCINSTALLDIR=$(PREFIXINSTALLDIR)/doc/fpc-$(FPC_VERSION)
 DOCINSTALLDIR=$(PREFIXINSTALLDIR)/doc/fpc-$(FPC_VERSION)
 else
 else
 DOCINSTALLDIR=$(BASEINSTALLDIR)/doc
 DOCINSTALLDIR=$(BASEINSTALLDIR)/doc
@@ -722,7 +745,7 @@ endif
 # Where to install the examples, under linux we use the doc dir
 # Where to install the examples, under linux we use the doc dir
 # because the copytree command will create a subdir itself
 # because the copytree command will create a subdir itself
 ifndef EXAMPLEINSTALLDIR
 ifndef EXAMPLEINSTALLDIR
-ifdef inlinux
+ifdef UNIXINSTALLDIR
 EXAMPLEINSTALLDIR=$(DOCINSTALLDIR)/examples
 EXAMPLEINSTALLDIR=$(DOCINSTALLDIR)/examples
 else
 else
 EXAMPLEINSTALLDIR=$(BASEINSTALLDIR)/examples
 EXAMPLEINSTALLDIR=$(BASEINSTALLDIR)/examples
@@ -746,7 +769,7 @@ REDIRFILE=log
 endif
 endif
 
 
 ifdef REDIR
 ifdef REDIR
-ifndef inlinux
+ifndef inUnix
 override FPC=redir -eo $(FPC)
 override FPC=redir -eo $(FPC)
 endif
 endif
 # set the verbosity to max
 # set the verbosity to max
@@ -793,7 +816,7 @@ endif
 
 
 # Debug
 # Debug
 ifdef DEBUG
 ifdef DEBUG
-override FPCOPT+=-g -dDEBUG
+override FPCOPT+=-gl -dDEBUG
 endif
 endif
 
 
 # Release mode (strip, optimize and don't load ppc386.cfg)
 # Release mode (strip, optimize and don't load ppc386.cfg)
@@ -833,9 +856,27 @@ ifdef UNITSDIR
 override FPCOPT+=-Fu$(UNITSDIR)
 override FPCOPT+=-Fu$(UNITSDIR)
 endif
 endif
 
 
-# Target dirs
+# Target dirs and the prefix to use for clean/install
 ifdef TARGETDIR
 ifdef TARGETDIR
 override FPCOPT+=-FE$(TARGETDIR)
 override FPCOPT+=-FE$(TARGETDIR)
+ifeq ($(TARGETDIR),.)
+override TARGETDIRPREFIX=
+else
+override TARGETDIRPREFIX=$(TARGETDIR)/
+endif
+endif
+ifdef UNITTARGETDIR
+override FPCOPT+=-FU$(UNITTARGETDIR)
+ifeq ($(UNITTARGETDIR),.)
+override UNITTARGETDIRPREFIX=
+else
+override UNITTARGETDIRPREFIX=$(TARGETDIR)/
+endif
+else
+ifdef TARGETDIR
+override UNITTARGETDIR=$(TARGETDIR)
+override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX)
+endif
 endif
 endif
 
 
 # Add commandline options last so they can override
 # Add commandline options last so they can override
@@ -869,11 +910,14 @@ endif
 override COMPILER:=$(FPC) $(FPCOPT)
 override COMPILER:=$(FPC) $(FPCOPT)
 
 
 # also call ppas if with command option -s
 # also call ppas if with command option -s
+# but only if the OS_SOURCE and OS_TARGE are equal
 ifeq (,$(findstring -s ,$(COMPILER)))
 ifeq (,$(findstring -s ,$(COMPILER)))
 EXECPPAS=
 EXECPPAS=
 else
 else
+ifeq ($(OS_SOURCE),$(OS_TARGET))
 EXECPPAS:=@$(PPAS)
 EXECPPAS:=@$(PPAS)
 endif
 endif
+endif
 
 
 #####################################################################
 #####################################################################
 # Standard rules
 # Standard rules
@@ -919,11 +963,12 @@ info: fpc_info
 
 
 ifdef EXEOBJECTS
 ifdef EXEOBJECTS
 override EXEFILES=$(addsuffix $(EXEEXT),$(EXEOBJECTS))
 override EXEFILES=$(addsuffix $(EXEEXT),$(EXEOBJECTS))
-override EXEOFILES=$(addsuffix $(OEXT),$(EXEOBJECTS))
+override EXEOFILES:=$(addsuffix $(OEXT),$(EXEOBJECTS)) $(addprefix $(LIBPREFIX),$(addsuffix $(STATICLIBEXT),$(EXEOBJECTS)))
 
 
 override ALLTARGET+=fpc_exes
 override ALLTARGET+=fpc_exes
 override INSTALLEXEFILES+=$(EXEFILES)
 override INSTALLEXEFILES+=$(EXEFILES)
 override CLEANEXEFILES+=$(EXEFILES) $(EXEOFILES)
 override CLEANEXEFILES+=$(EXEFILES) $(EXEOFILES)
+
 endif
 endif
 
 
 fpc_exes: $(EXEFILES)
 fpc_exes: $(EXEFILES)
@@ -954,6 +999,11 @@ fpc_all: fpc_packages $(FPCMADE)
 fpc_debug:
 fpc_debug:
 	$(MAKE) all DEBUG=1
 	$(MAKE) all DEBUG=1
 
 
+# Search paths for .ppu if targetdir is set
+ifdef UNITTARGETDIR
+vpath %$(PPUEXT) $(UNITTARGETDIR)
+endif
+
 # General compile rules, available for both possible PASEXT
 # General compile rules, available for both possible PASEXT
 
 
 .SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp
 .SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp
@@ -995,7 +1045,7 @@ fpc_smart:
 	$(MAKE) all LINKSMART=1 CREATESMART=1
 	$(MAKE) all LINKSMART=1 CREATESMART=1
 
 
 fpc_shared: all
 fpc_shared: all
-ifdef inlinux
+ifdef HASSHAREDLIB
 ifndef LIBNAME
 ifndef LIBNAME
 	@$(ECHO) "LIBNAME not set"
 	@$(ECHO) "LIBNAME not set"
 else
 else
@@ -1016,11 +1066,17 @@ override INSTALLPPUFILES+=$(addsuffix $(PPUEXT),$(EXTRAINSTALLUNITS))
 endif
 endif
 
 
 ifdef INSTALLPPUFILES
 ifdef INSTALLPPUFILES
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
 ifdef PPUFILES
 ifdef PPUFILES
 INSTALLPPULINKFILES:=$(shell $(PPUFILES) -S -O $(INSTALLPPUFILES))
 INSTALLPPULINKFILES:=$(shell $(PPUFILES) -S -O $(INSTALLPPUFILES))
 else
 else
-INSTALLPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)))
+INSTALLPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES))))
 endif
 endif
+override INSTALLPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPULINKFILES))
+endif
+
+ifdef INSTALLEXEFILES
+override INSTALLEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(INSTALLEXEFILES))
 endif
 endif
 
 
 fpc_showinstall: $(SHOWINSTALLTARGET)
 fpc_showinstall: $(SHOWINSTALLTARGET)
@@ -1034,7 +1090,7 @@ ifneq ($(INSTALLPPULINKFILES),)
 endif
 endif
 ifneq ($(wildcard $(LIBFULLNAME)),)
 ifneq ($(wildcard $(LIBFULLNAME)),)
 	@$(ECHO) $(LIBINSTALLDIR)/$(LIBFULLNAME)
 	@$(ECHO) $(LIBINSTALLDIR)/$(LIBFULLNAME)
-ifdef inlinux
+ifdef HASSHAREDLIB
 	@$(ECHO) $(LIBINSTALLDIR)/$(LIBNAME)
 	@$(ECHO) $(LIBINSTALLDIR)/$(LIBNAME)
 endif
 endif
 endif
 endif
@@ -1062,7 +1118,7 @@ endif
 ifneq ($(wildcard $(LIBFULLNAME)),)
 ifneq ($(wildcard $(LIBFULLNAME)),)
 	$(MKDIR) $(LIBINSTALLDIR)
 	$(MKDIR) $(LIBINSTALLDIR)
 	$(INSTALL) $(LIBFULLNAME) $(LIBINSTALLDIR)
 	$(INSTALL) $(LIBFULLNAME) $(LIBINSTALLDIR)
-ifdef inlinux
+ifdef inUnix
 	ln -sf $(LIBFULLNAME) $(LIBINSTALLDIR)/$(LIBNAME)
 	ln -sf $(LIBFULLNAME) $(LIBINSTALLDIR)/$(LIBNAME)
 endif
 endif
 endif
 endif
@@ -1123,7 +1179,7 @@ endif
 
 
 # Temporary path to pack a file
 # Temporary path to pack a file
 ifndef PACKDIR
 ifndef PACKDIR
-ifndef inlinux
+ifndef inUnix
 PACKDIR=$(BASEDIR)/pack_tmp
 PACKDIR=$(BASEDIR)/pack_tmp
 else
 else
 PACKDIR=/tmp/fpc-pack
 PACKDIR=/tmp/fpc-pack
@@ -1139,7 +1195,7 @@ endif
 
 
 # Use tar by default under linux
 # Use tar by default under linux
 ifndef USEZIP
 ifndef USEZIP
-ifdef inlinux
+ifdef inUnix
 USETAR=1
 USETAR=1
 endif
 endif
 endif
 endif
@@ -1152,7 +1208,7 @@ else
 	$(MAKE) $(ZIPTARGET) PREFIXINSTALLDIR=$(PACKDIR)
 	$(MAKE) $(ZIPTARGET) PREFIXINSTALLDIR=$(PACKDIR)
 ifdef USETAR
 ifdef USETAR
 	$(DEL) $(DESTZIPDIR)/$(ZIPNAME)$(TAREXT)
 	$(DEL) $(DESTZIPDIR)/$(ZIPNAME)$(TAREXT)
-	cd $(PACKDIR) ; $(TARPROG) c$(TAROPT) --file $(DESTZIPDIR)/$(ZIPNAME)$(TAREXT) * ; cd $(BASEDIR)
+	cd $(PACKDIR) ; $(TARPROG) cf$(TAROPT) $(DESTZIPDIR)/$(ZIPNAME)$(TAREXT) * ; cd $(BASEDIR)
 else
 else
 	$(DEL) $(DESTZIPDIR)/$(ZIPNAME)$(ZIPEXT)
 	$(DEL) $(DESTZIPDIR)/$(ZIPNAME)$(ZIPEXT)
 	cd $(PACKDIR) ; $(ZIPPROG) -Dr $(ZIPOPT) $(DESTZIPDIR)/$(ZIPNAME)$(ZIPEXT) * ; cd $(BASEDIR)
 	cd $(PACKDIR) ; $(ZIPPROG) -Dr $(ZIPOPT) $(DESTZIPDIR)/$(ZIPNAME)$(ZIPEXT) * ; cd $(BASEDIR)
@@ -1176,16 +1232,23 @@ fpc_zipexampleinstall:
 
 
 .PHONY: fpc_clean fpc_cleanall fpc_distclean
 .PHONY: fpc_clean fpc_cleanall fpc_distclean
 
 
+ifdef EXEFILES
+override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
+endif
+
 ifdef EXTRACLEANUNITS
 ifdef EXTRACLEANUNITS
 override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(EXTRACLEANUNITS))
 override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(EXTRACLEANUNITS))
 endif
 endif
 
 
 ifdef CLEANPPUFILES
 ifdef CLEANPPUFILES
+override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPUFILES))
+# Get the .o and .a files created for the units
 ifdef PPUFILES
 ifdef PPUFILES
 CLEANPPULINKFILES:=$(shell $(PPUFILES) $(CLEANPPUFILES))
 CLEANPPULINKFILES:=$(shell $(PPUFILES) $(CLEANPPUFILES))
 else
 else
-CLEANPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)))
+CLEANPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES))))
 endif
 endif
+override CLEANPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPULINKFILES))
 endif
 endif
 
 
 fpc_clean: $(CLEANTARGET)
 fpc_clean: $(CLEANTARGET)
@@ -1199,7 +1262,7 @@ ifneq ($(CLEANPPULINKFILES),)
 	-$(DEL) $(CLEANPPULINKFILES)
 	-$(DEL) $(CLEANPPULINKFILES)
 endif
 endif
 ifdef CLEANRSTFILES
 ifdef CLEANRSTFILES
-	-$(DEL) $(CLEANRSTFILES)
+	-$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
 endif
 endif
 ifdef EXTRACLEANFILES
 ifdef EXTRACLEANFILES
 	-$(DEL) $(EXTRACLEANFILES)
 	-$(DEL) $(EXTRACLEANFILES)
@@ -1211,7 +1274,13 @@ endif
 
 
 fpc_distclean: fpc_clean
 fpc_distclean: fpc_clean
 
 
-fpc_cleanall: $(CLEANTARGET)
+# Also run clean first if targetdir is set. Unittargetdir is always
+# set if targetdir or unittargetdir is specified
+ifdef UNITTARGETDIR
+TARGETDIRCLEAN=fpc_clean
+endif
+
+fpc_cleanall: $(CLEANTARGET) $(TARGETDIRCLEAN)
 ifdef CLEANEXEFILES
 ifdef CLEANEXEFILES
 	-$(DEL) $(CLEANEXEFILES)
 	-$(DEL) $(CLEANEXEFILES)
 endif
 endif