[project @ 2004-08-30 19:44:38 by sof]
[ghc-hetmet.git] / ghc / utils / ghc-pkg / Makefile
index 7c416f7..b2dc16c 100644 (file)
@@ -1,5 +1,4 @@
 # -----------------------------------------------------------------------------
-# $Id: Makefile,v 1.15 2002/02/12 16:55:22 simonmar Exp $
 
 TOP=../..
 include $(TOP)/mk/boilerplate.mk
@@ -7,27 +6,49 @@ include $(TOP)/mk/boilerplate.mk
 # hack for ghci-inplace script, see below
 INSTALLING=1
 
-# ghc-pkg is needed to boot in ghc/rts and library dirs
-ifneq "$(BootingFromHc)" "YES"
-boot :: depend all
-endif
-
 # -----------------------------------------------------------------------------
 # ghc-pkg.bin
 
-SRC_HC_OPTS      += -cpp -DPKG_TOOL -DWANT_PRETTY -package lang \
-                   -package util -package text
+ghc_ge_504 = $(shell if (test $(GhcCanonVersion) -ge 504); then echo YES; else echo NO; fi)
+ghc_eq_600 = $(shell if (test $(GhcCanonVersion) -eq 600); then echo YES; else echo NO; fi)
+ghc_lt_600 = $(shell if (test $(GhcCanonVersion) -lt 600); then echo YES; else echo NO; fi)
 
-ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-HS_PROG           = ghc-pkg.bin
-INSTALL_LIBEXECS += $(HS_PROG)
+SRC_HC_OPTS      += -cpp -DPKG_TOOL -DWANT_PRETTY
+
+# <= 6.0.x quotes arguments when invoking utils (using double quotes), hence
+# the need to escape the double quotes. >= 6.2.x does not.
+# ..but apparently 5.04.x on non-win32 platforms doesn't, so catch this (and
+# assume pre-5.04 behave similarly.)
+ifeq "$(ghc_lt_600)" "YES"
+ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32YES"
+SRC_HC_OPTS += -D'GHC_PKG_VERSION=\"$(ProjectVersion)\"'
+else
+SRC_HC_OPTS += -D'GHC_PKG_VERSION="$(ProjectVersion)"'
+endif
 else
+ifeq "$(ghc_eq_600)" "YES"
+SRC_HC_OPTS += -D'GHC_PKG_VERSION=\"$(ProjectVersion)\"'
+else
+SRC_HC_OPTS += -D'GHC_PKG_VERSION="$(ProjectVersion)"'
+endif
+endif
+
+ifeq "$(ghc_ge_504)" "NO"
+SRC_HC_OPTS +=  -package lang -package util -package text
+endif
+
+# On Windows, ghc-pkg is a standalone program
+# ($bindir/ghc-pkg.exe), whereas on Unix it needs a wrapper script
+# to pass the appropriate flag to the real binary
+# ($libexecdir/ghc-pkg.bin) so that it can find package.conf.
+ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
 HS_PROG           = ghc-pkg.exe
 INSTALL_PROGS    += $(HS_PROG)
-SRC_HC_OPTS      += -package win32
+else
+HS_PROG           = ghc-pkg.bin
+INSTALL_LIBEXECS += $(HS_PROG)
 endif
 
-
 # -----------------------------------------------------------------------------
 # ghc-pkg script
 
@@ -41,10 +62,10 @@ PKGCONF=$(libdir)/package.conf
 endif # BIN_DIST
 else
 GHCPKGBIN=$(FPTOOLS_TOP_ABS)/ghc/utils/ghc-pkg/$(HS_PROG)
-PKGCONF=$(FPTOOLS_TOP_ABS)/ghc/driver/package.conf.inplace
+PKGCONF=$(FPTOOLS_TOP_ABS_PLATFORM)/ghc/driver/package.conf.inplace
 endif
 
-ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
+ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
 INSTALLED_SCRIPT_PROG  = ghc-pkg-$(ProjectVersion)
 endif
 INPLACE_SCRIPT_PROG    = ghc-pkg-inplace
@@ -52,14 +73,14 @@ INPLACE_SCRIPT_PROG    = ghc-pkg-inplace
 SCRIPT_OBJS      = ghc-pkg.sh
 INTERP           = $(SHELL)
 SCRIPT_SUBST_VARS = GHCPKGBIN PKGCONFOPT
-ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
+ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
 INSTALL_SCRIPTS  += $(SCRIPT_PROG)
 endif
 PKGCONFOPT       = -f $(PKGCONF)
 
 ifeq "$(INSTALLING)" "1"
 SCRIPT_PROG    =  $(INSTALLED_SCRIPT_PROG)
-ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
+ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
 LINK           =  ghc-pkg
 endif
 else
@@ -70,8 +91,18 @@ endif
 # don't recurse on 'make install'
 #
 ifeq "$(INSTALLING)" "1"
-all clean distclean maintainer-clean ::
+all :: $(HS_PROG)
+       $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
+clean distclean maintainer-clean ::
        $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
 endif
 
+# ghc-pkg is needed to boot in ghc/rts and library dirs
+# Do a recursive 'make all' after generating dependencies, because this
+# will work with 'make -j'.
+ifneq "$(BootingFromHc)" "YES"
+boot :: depend
+       $(MAKE) all
+endif
+
 include $(TOP)/mk/target.mk