Take 2 on the recursive-rule fix
[ghc-hetmet.git] / utils / ghc-pkg / Makefile
1 TOP=../..
2 include $(TOP)/mk/boilerplate.mk
3
4 # hack for ghci-inplace script, see below
5 INSTALLING=1
6
7 # -----------------------------------------------------------------------------
8 # ghc-pkg.bin
9
10 SRC_HC_OPTS += -cpp -Wall -fno-warn-name-shadowing -fno-warn-unused-matches
11
12 # This causes libghccompat.a to be used:
13 include $(GHC_COMPAT_DIR)/compat.mk
14
15 # This is required because libghccompat.a must be built with
16 # $(GhcHcOpts) because it is linked to the compiler, and hence
17 # we must also build with $(GhcHcOpts) here:
18 SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
19
20 ifeq "$(ghc_ge_504)" "NO"
21 SRC_HC_OPTS +=  -package lang -package util -package text
22 endif
23
24 # On Windows, ghc-pkg is a standalone program
25 # ($bindir/ghc-pkg.exe), whereas on Unix it needs a wrapper script
26 # to pass the appropriate flag to the real binary
27 # ($libexecdir/ghc-pkg.bin) so that it can find package.conf.
28 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
29 HS_PROG           = ghc-pkg.exe
30 INSTALL_PROGS    += $(HS_PROG)
31 else
32 HS_PROG           = ghc-pkg.bin
33 INSTALL_LIBEXECS += $(HS_PROG)
34 endif
35
36 # -----------------------------------------------------------------------------
37 # Create the Version.hs file
38
39 VERSION_HS = Version.hs
40 EXTRA_SRCS += $(VERSION_HS)
41
42 boot :: $(VERSION_HS)
43
44 Version.hs : Makefile $(TOP)/mk/config.mk
45         @$(RM) -f $(VERSION_HS)
46         @echo "Creating $(VERSION_HS) ... "
47         @echo "module Version where" >>$(VERSION_HS)
48         @echo "version, targetOS, targetARCH :: String" >>$(VERSION_HS)
49         @echo "version    = \"$(ProjectVersion)\"" >> $(VERSION_HS)
50         @echo "targetOS   = \"$(TargetOS_CPP)\"" >> $(VERSION_HS)
51         @echo "targetARCH = \"$(TargetArch_CPP)\"" >> $(VERSION_HS)
52
53 DIST_CLEAN_FILES += $(VERSION_HS)
54
55 # -----------------------------------------------------------------------------
56 # ghc-pkg script
57
58 ifeq "$(INSTALLING)" "1"
59 ifeq "$(BIN_DIST)"   "1"
60 GHCPKGBIN=$$\"\"libexecdir/$(HS_PROG)
61 PKGCONF=$$\"\"libdir/package.conf
62 else
63 GHCPKGBIN=$(libexecdir)/$(HS_PROG)
64 PKGCONF=$(libdir)/package.conf
65 endif # BIN_DIST
66 else
67 GHCPKGBIN=$(FPTOOLS_TOP_ABS)/utils/ghc-pkg/$(HS_PROG)
68 PKGCONF=$(FPTOOLS_TOP_ABS_PLATFORM)/driver/package.conf.inplace
69 endif
70
71 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
72 INSTALLED_SCRIPT_PROG  = ghc-pkg-$(ProjectVersion)
73 endif
74 INPLACE_SCRIPT_PROG    = ghc-pkg-inplace
75
76 SCRIPT_OBJS       = ghc-pkg.sh
77 INTERP            = $(SHELL)
78 SCRIPT_SUBST_VARS = GHCPKGBIN PKGCONFOPT
79 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
80 INSTALL_SCRIPTS  += $(SCRIPT_PROG)
81 endif
82 PKGCONFOPT        = --global-conf $(PKGCONF)
83
84 ifeq "$(INSTALLING)" "1"
85 SCRIPT_PROG     =  $(INSTALLED_SCRIPT_PROG)
86 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
87 LINK            =  ghc-pkg
88 endif
89 else
90 SCRIPT_PROG     =  $(INPLACE_SCRIPT_PROG)
91 endif
92
93 # -----------------------------------------------------------------------------
94 # don't recurse on 'make install'
95 #
96 ifeq "$(INSTALLING)" "1"
97 all :: $(HS_PROG)
98         $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
99 clean distclean maintainer-clean ::
100         $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
101 endif
102
103 # ghc-pkg is needed to boot in rts/ and library dirs
104 # Do a recursive 'make all' after generating dependencies, because this
105 # will work with 'make -j'.
106 ifneq "$(BootingFromHc)" "YES"
107 boot :: depend
108         $(MAKE) all
109 endif
110
111 include $(TOP)/mk/target.mk