Use a real binary instead of scripts for ghc-inplace
[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 # On Windows, ghc-pkg is a standalone program
20 # ($bindir/ghc-pkg.exe), whereas on Unix it needs a wrapper script
21 # to pass the appropriate flag to the real binary
22 # ($libexecdir/ghc-pkg.bin) so that it can find package.conf.
23 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
24 HS_PROG           = ghc-pkg.exe
25 INSTALL_PROGS    += $(HS_PROG)
26 else
27 HS_PROG           = ghc-pkg.bin
28 INSTALL_LIBEXECS += $(HS_PROG)
29 endif
30
31 # -----------------------------------------------------------------------------
32 # Create the Version.hs file
33
34 VERSION_HS = Version.hs
35 EXTRA_SRCS += $(VERSION_HS)
36
37 boot :: $(VERSION_HS)
38
39 Version.hs : Makefile $(TOP)/mk/config.mk
40         @$(RM) -f $(VERSION_HS)
41         @echo "Creating $(VERSION_HS) ... "
42         @echo "module Version where" >>$(VERSION_HS)
43         @echo "version, targetOS, targetARCH :: String" >>$(VERSION_HS)
44         @echo "version    = \"$(ProjectVersion)\"" >> $(VERSION_HS)
45         @echo "targetOS   = \"$(TargetOS_CPP)\"" >> $(VERSION_HS)
46         @echo "targetARCH = \"$(TargetArch_CPP)\"" >> $(VERSION_HS)
47
48 DIST_CLEAN_FILES += $(VERSION_HS)
49
50 # -----------------------------------------------------------------------------
51 # ghc-pkg and ghc-pkg-inplace scripts
52
53 # ghc-pkg-inplace used to be either a /bin/sh script, or a .bat script
54 # on Windows.  It is now a real binary, compiled from a tiny .hs
55 # file.  The problem with using scripts here was that the .bat script
56 # cannot be executed by /bin/sh on MSYS (it can on Cygwin), but the
57 # /bin/sh script cannot be executed by Cabal.  So we would have needed
58 # both.  A single binary is therefore simpler.
59
60 INPLACE_HS=ghc-pkg-inplace.hs
61 INPLACE_PROG=ghc-pkg-inplace
62
63 $(INPLACE_HS): Makefile $(FPTOOLS_TOP)/mk/config.mk
64         echo "import System.Cmd; import System.Environment" > $@
65         echo "main = getArgs >>= \args -> rawSystem \"$(FPTOOLS_TOP_ABS_PLATFORM)/$(GHC_PKG_DIR_REL)/$(HS_PROG)\" (\"--global-conf\":\"$(FPTOOLS_TOP_ABS_PLATFORM)/driver/package.conf.inplace\":args)" >> $@
66
67 $(INPLACE_PROG): $(INPLACE_HS)
68         $(GHC) --make $< -o $@
69
70 all :: $(INPLACE_PROG)
71
72 CLEAN_FILES += $(INPLACE_HS) $(INPLACE_PROG)
73
74 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
75 LINK = ghc-pkg
76 LINK_TARGET = $(LINK)-$(ProjectVersion)
77 INSTALLED_SCRIPT=$(bindir)/$(LINK_TARGET)
78 install::
79         $(RM) -f $(INSTALLED_SCRIPT)
80         echo "#!$(SHELL)"                                           >> $(INSTALLED_SCRIPT)
81         echo "GHCPKGBIN=$(libexecdir)/$(HS_PROG)"                   >> $(INSTALLED_SCRIPT)
82         echo "PKGCONF=$(libdir)/package.conf"                       >> $(INSTALLED_SCRIPT)
83         echo 'exec $$GHCPKGBIN --global-conf $$PKGCONF $${1+"$$@"}' >> $(INSTALLED_SCRIPT)
84         $(EXECUTABLE_FILE) $(INSTALLED_SCRIPT)
85 endif
86
87 # ghc-pkg is needed to boot in rts/ and library dirs
88 # Do a recursive 'make all' after generating dependencies, because this
89 # will work with 'make -j'.
90 ifneq "$(BootingFromHc)" "YES"
91 boot :: depend
92         $(MAKE) all
93 endif
94
95 binary-dist:
96         $(INSTALL_DIR)                $(BIN_DIST_DIR)/utils/ghc-pkg
97         $(INSTALL_DATA)    Makefile   $(BIN_DIST_DIR)/utils/ghc-pkg/
98         $(INSTALL_PROGRAM) $(HS_PROG) $(BIN_DIST_DIR)/utils/ghc-pkg/
99
100 include $(TOP)/mk/target.mk