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