Use DESTDIR when installing
[ghc-hetmet.git] / utils / ghc-pkg / Makefile
1 TOP=../..
2 include $(TOP)/mk/boilerplate.mk
3
4 # -----------------------------------------------------------------------------
5 # ghc-pkg.bin
6
7 SRC_HC_OPTS += -cpp -Wall -fno-warn-name-shadowing -fno-warn-unused-matches
8
9 # This causes libghccompat.a to be used:
10 include $(GHC_COMPAT_DIR)/compat.mk
11
12 SRC_HC_OPTS += $(PACKAGE_CABAL)
13
14 # This is required because libghccompat.a must be built with
15 # $(GhcHcOpts) because it is linked to the compiler, and hence
16 # we must also build with $(GhcHcOpts) here:
17 SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
18
19 ifeq "$(ghc_ge_607)" "YES"
20 SRC_HC_OPTS += -package containers
21 endif
22
23 # On Windows, ghc-pkg is a standalone program
24 # ($bindir/ghc-pkg.exe), whereas on Unix it needs a wrapper script
25 # to pass the appropriate flag to the real binary
26 # ($libexecdir/ghc-pkg.bin) so that it can find package.conf.
27 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
28 HS_PROG           = ghc-pkg.exe
29 INSTALL_PROGS    += $(HS_PROG)
30 else
31 HS_PROG           = ghc-pkg.bin
32 INSTALL_LIBEXECS += $(HS_PROG)
33 endif
34
35 # -----------------------------------------------------------------------------
36 # Create the Version.hs file
37
38 VERSION_HS = Version.hs
39 EXTRA_SRCS += $(VERSION_HS)
40
41 boot :: $(VERSION_HS)
42
43 Version.hs : Makefile $(TOP)/mk/config.mk
44         @$(RM) -f $(VERSION_HS)
45         @echo "Creating $(VERSION_HS) ... "
46         @echo "module Version where" >>$(VERSION_HS)
47         @echo "version, targetOS, targetARCH :: String" >>$(VERSION_HS)
48         @echo "version    = \"$(ProjectVersion)\"" >> $(VERSION_HS)
49         @echo "targetOS   = \"$(TargetOS_CPP)\"" >> $(VERSION_HS)
50         @echo "targetARCH = \"$(TargetArch_CPP)\"" >> $(VERSION_HS)
51
52 DIST_CLEAN_FILES += $(VERSION_HS)
53
54 # -----------------------------------------------------------------------------
55 # ghc-pkg and ghc-pkg-inplace scripts
56
57 # ghc-pkg-inplace used to be either a /bin/sh script, or a .bat script
58 # on Windows.  It is now a real binary, compiled from a tiny .hs
59 # file.  The problem with using scripts here was that the .bat script
60 # cannot be executed by /bin/sh on MSYS (it can on Cygwin), but the
61 # /bin/sh script cannot be executed by Cabal.  So we would have needed
62 # both.  A single binary is therefore simpler.
63
64 INPLACE_HS=ghc-pkg-inplace.hs
65 INPLACE_PROG=ghc-pkg-inplace
66 EXCLUDED_SRCS+=$(INPLACE_HS)
67
68 # FPTOOLS_TOP_ABS platform uses backslashes, at least on Cygwin, but that
69 # will go wrong when we use it in a Haskell string below.
70 TOP_ABS=$(subst \\,/,$(FPTOOLS_TOP_ABS_PLATFORM))
71
72 $(INPLACE_HS): Makefile $(FPTOOLS_TOP)/mk/config.mk
73         echo "import System.Cmd; import System.Environment; import System.Exit" > $@
74         echo "main = do args <- getArgs; rawSystem \"$(TOP_ABS)/$(GHC_PKG_DIR_REL)/$(HS_PROG)\" (\"--global-conf\":\"$(TOP_ABS)/driver/package.conf.inplace\":args) >>= exitWith" >> $@
75
76 $(INPLACE_PROG): $(INPLACE_HS)
77         $(HC) --make $< -o $@
78
79 all :: $(INPLACE_PROG)
80
81 CLEAN_FILES += $(INPLACE_HS) $(INPLACE_PROG)
82
83 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
84 LINK = ghc-pkg
85 LINK_TARGET = $(LINK)-$(ProjectVersion)
86 INSTALLED_SCRIPT=$(DESTDIR)$(bindir)/$(LINK_TARGET)
87 install::
88         $(RM) -f $(INSTALLED_SCRIPT)
89         echo "#!$(SHELL)"                                           >> $(INSTALLED_SCRIPT)
90         echo "GHCPKGBIN=$(libexecdir)/$(HS_PROG)"                   >> $(INSTALLED_SCRIPT)
91         echo "PKGCONF=$(libdir)/package.conf"                       >> $(INSTALLED_SCRIPT)
92         echo 'exec $$GHCPKGBIN --global-conf $$PKGCONF $${1+"$$@"}' >> $(INSTALLED_SCRIPT)
93         $(EXECUTABLE_FILE) $(INSTALLED_SCRIPT)
94 endif
95
96 # ghc-pkg is needed to boot in rts/ and library dirs
97 # Do a recursive 'make all' after generating dependencies, because this
98 # will work with 'make -j'.
99 ifneq "$(BootingFromHc)" "YES"
100 boot :: depend
101         $(MAKE) all
102 endif
103
104 binary-dist:
105         $(INSTALL_DIR)                $(BIN_DIST_DIR)/utils/ghc-pkg
106         $(INSTALL_DATA)    Makefile   $(BIN_DIST_DIR)/utils/ghc-pkg/
107         $(INSTALL_PROGRAM) $(HS_PROG) $(BIN_DIST_DIR)/utils/ghc-pkg/
108
109 include $(TOP)/mk/target.mk