Remove Cabal modules from compat
[ghc-hetmet.git] / utils / ghc-pkg / Makefile
1 TOP=../..
2 include $(TOP)/mk/boilerplate.mk
3
4 # -----------------------------------------------------------------------------
5 # ghc-pkg.bin
6
7 # Beyond stage 1, honour any Mac OS X depolyment target options.  If we use 
8 # these options in stage 1 we get a linker error if the bootstrap compiler is
9 #  for a more recent OS version
10 ifeq "$(stage)" "2"
11 SRC_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
12 SRC_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
13 SRC_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
14 endif
15
16 SRC_HC_OPTS += -cpp -Wall -fno-warn-name-shadowing -fno-warn-unused-matches
17
18 # This causes libghccompat.a to be used:
19 include $(GHC_COMPAT_DIR)/compat.mk
20
21 SRC_HC_OPTS += $(PACKAGE_CABAL)
22
23 # This is required because libghccompat.a must be built with
24 # $(GhcHcOpts) because it is linked to the compiler, and hence
25 # we must also build with $(GhcHcOpts) here:
26 SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
27
28 ifeq "$(Windows)" "NO"
29 SRC_HC_OPTS += -package unix
30 endif
31
32 ifeq "$(ghc_ge_607)" "YES"
33 SRC_HC_OPTS += -package containers
34 endif
35
36 SRC_HC_OPTS += -package Cabal
37
38 # On Windows, ghc-pkg is a standalone program
39 # ($bindir/ghc-pkg.exe), whereas on Unix it needs a wrapper script
40 # to pass the appropriate flag to the real binary
41 # ($libexecdir/ghc-pkg.bin) so that it can find package.conf.
42 # on Windows, we need to take control of filename globbing ourselves
43 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
44 HS_PROG           = ghc-pkg.exe
45 INSTALL_PROGS    += $(HS_PROG)
46 EXCLUDE_SRCS     += CRT_noglob.c
47 NOGLOB_O          = CRT_noglob.o
48 else
49
50 # We have two version: the inplace version compiled by the bootstrap compiler
51 # and the install version compiled by the stage 1 compiler.
52 # When creating or using bindists we always want the final binary, as built
53 # by the stage 1 compiler.
54 ifeq "$(DOING_BIN_DIST)" "YES"
55 HS_PROG           = ghc-pkg.bin
56 else
57 ifeq "$(stage)" "2"
58 HS_PROG           = ghc-pkg.bin
59 else
60 HS_PROG           = ghc-pkg-inplace.bin
61 endif
62 endif
63 INSTALL_LIBEXECS += $(HS_PROG)
64 NOGLOB_O          =
65
66 endif
67
68 # -----------------------------------------------------------------------------
69 # Create the Version.hs file
70
71 VERSION_HS = Version.hs
72 EXTRA_SRCS += $(VERSION_HS)
73
74 boot :: $(VERSION_HS)
75
76 Version.hs : Makefile $(TOP)/mk/config.mk
77         @$(RM) -f $(VERSION_HS)
78         @echo "Creating $(VERSION_HS) ... "
79         @echo "module Version where" >>$(VERSION_HS)
80         @echo "version, targetOS, targetARCH :: String" >>$(VERSION_HS)
81         @echo "version    = \"$(ProjectVersion)\"" >> $(VERSION_HS)
82         @echo "targetOS   = \"$(TargetOS_CPP)\"" >> $(VERSION_HS)
83         @echo "targetARCH = \"$(TargetArch_CPP)\"" >> $(VERSION_HS)
84
85 DIST_CLEAN_FILES += $(VERSION_HS)
86
87 # -----------------------------------------------------------------------------
88 # ghc-pkg and ghc-pkg-inplace scripts
89
90 # ghc-pkg-inplace used to be either a /bin/sh script, or a .bat script
91 # on Windows.  It is now a real binary, compiled from a tiny .hs
92 # file.  The problem with using scripts here was that the .bat script
93 # cannot be executed by /bin/sh on MSYS (it can on Cygwin), but the
94 # /bin/sh script cannot be executed by Cabal.  So we would have needed
95 # both.  A single binary is therefore simpler.
96
97 INPLACE_HS=ghc-pkg-inplace.hs
98 INPLACE_PROG=ghc-pkg-inplace
99 EXCLUDED_SRCS+=$(INPLACE_HS)
100
101 $(INPLACE_HS): Makefile $(FPTOOLS_TOP)/mk/config.mk $(NOGLOB_O)
102         echo "import System.Cmd; import System.Environment; import System.Exit" > $@
103         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" >> $@
104
105 $(INPLACE_PROG): $(INPLACE_HS)
106         $(HC) --make $< -o $@ $(LD_OPTS) $(NOGLOB_O)
107
108 all :: $(INPLACE_PROG)
109
110 CLEAN_FILES += $(INPLACE_HS) $(INPLACE_PROG)
111
112 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
113 LINK = ghc-pkg
114 LINK_TARGET = $(LINK)-$(ProjectVersion)
115 INSTALLED_SCRIPT=$(DESTDIR)$(bindir)/$(LINK_TARGET)
116 install::
117         $(INSTALL_DIR) $(DESTDIR)$(bindir)
118         $(RM) -f $(INSTALLED_SCRIPT)
119         echo "#!$(SHELL)"                                           >> $(INSTALLED_SCRIPT)
120         echo "GHCPKGBIN=$(libexecdir)/$(HS_PROG)"                   >> $(INSTALLED_SCRIPT)
121         echo "PKGCONF=$(libdir)/package.conf"                       >> $(INSTALLED_SCRIPT)
122         echo 'exec $$GHCPKGBIN --global-conf $$PKGCONF $${1+"$$@"}' >> $(INSTALLED_SCRIPT)
123         $(EXECUTABLE_FILE) $(INSTALLED_SCRIPT)
124 endif
125
126 # ghc-pkg is needed to boot in rts/ and library dirs
127 # Do a recursive 'make all' after generating dependencies, because this
128 # will work with 'make -j'.
129 ifneq "$(BootingFromHc)" "YES"
130 boot :: depend
131         $(MAKE) all
132 endif
133
134 binary-dist:
135         $(INSTALL_DIR)                $(BIN_DIST_DIR)/utils/ghc-pkg
136         $(INSTALL_DATA)    Makefile   $(BIN_DIST_DIR)/utils/ghc-pkg/
137         $(INSTALL_PROGRAM) $(HS_PROG) $(BIN_DIST_DIR)/utils/ghc-pkg/
138
139 include $(TOP)/mk/target.mk