FIX #1839, #1463, by supporting ghc-pkg bulk queries with substring matching
[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 HS_PROG           = ghc-pkg.bin
39 INSTALL_LIBEXECS += $(HS_PROG)
40 NOGLOB_O          =
41 endif
42
43 # -----------------------------------------------------------------------------
44 # Create the Version.hs file
45
46 VERSION_HS = Version.hs
47 EXTRA_SRCS += $(VERSION_HS)
48
49 boot :: $(VERSION_HS)
50
51 Version.hs : Makefile $(TOP)/mk/config.mk
52         @$(RM) -f $(VERSION_HS)
53         @echo "Creating $(VERSION_HS) ... "
54         @echo "module Version where" >>$(VERSION_HS)
55         @echo "version, targetOS, targetARCH :: String" >>$(VERSION_HS)
56         @echo "version    = \"$(ProjectVersion)\"" >> $(VERSION_HS)
57         @echo "targetOS   = \"$(TargetOS_CPP)\"" >> $(VERSION_HS)
58         @echo "targetARCH = \"$(TargetArch_CPP)\"" >> $(VERSION_HS)
59
60 DIST_CLEAN_FILES += $(VERSION_HS)
61
62 # -----------------------------------------------------------------------------
63 # ghc-pkg and ghc-pkg-inplace scripts
64
65 # ghc-pkg-inplace used to be either a /bin/sh script, or a .bat script
66 # on Windows.  It is now a real binary, compiled from a tiny .hs
67 # file.  The problem with using scripts here was that the .bat script
68 # cannot be executed by /bin/sh on MSYS (it can on Cygwin), but the
69 # /bin/sh script cannot be executed by Cabal.  So we would have needed
70 # both.  A single binary is therefore simpler.
71
72 INPLACE_HS=ghc-pkg-inplace.hs
73 INPLACE_PROG=ghc-pkg-inplace
74 EXCLUDED_SRCS+=$(INPLACE_HS)
75
76 $(INPLACE_HS): Makefile $(FPTOOLS_TOP)/mk/config.mk $(NOGLOB_O)
77         echo "import System.Cmd; import System.Environment; import System.Exit" > $@
78         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" >> $@
79
80 $(INPLACE_PROG): $(INPLACE_HS)
81         $(HC) --make $< -o $@ $(LD_OPTS) $(NOGLOB_O)
82
83 all :: $(INPLACE_PROG)
84
85 CLEAN_FILES += $(INPLACE_HS) $(INPLACE_PROG)
86
87 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
88 LINK = ghc-pkg
89 LINK_TARGET = $(LINK)-$(ProjectVersion)
90 INSTALLED_SCRIPT=$(DESTDIR)$(bindir)/$(LINK_TARGET)
91 install::
92         $(INSTALL_DIR) $(DESTDIR)$(bindir)
93         $(RM) -f $(INSTALLED_SCRIPT)
94         echo "#!$(SHELL)"                                           >> $(INSTALLED_SCRIPT)
95         echo "GHCPKGBIN=$(libexecdir)/$(HS_PROG)"                   >> $(INSTALLED_SCRIPT)
96         echo "PKGCONF=$(libdir)/package.conf"                       >> $(INSTALLED_SCRIPT)
97         echo 'exec $$GHCPKGBIN --global-conf $$PKGCONF $${1+"$$@"}' >> $(INSTALLED_SCRIPT)
98         $(EXECUTABLE_FILE) $(INSTALLED_SCRIPT)
99 endif
100
101 # ghc-pkg is needed to boot in rts/ and library dirs
102 # Do a recursive 'make all' after generating dependencies, because this
103 # will work with 'make -j'.
104 ifneq "$(BootingFromHc)" "YES"
105 boot :: depend
106         $(MAKE) all
107 endif
108
109 binary-dist:
110         $(INSTALL_DIR)                $(BIN_DIST_DIR)/utils/ghc-pkg
111         $(INSTALL_DATA)    Makefile   $(BIN_DIST_DIR)/utils/ghc-pkg/
112         $(INSTALL_PROGRAM) $(HS_PROG) $(BIN_DIST_DIR)/utils/ghc-pkg/
113
114 include $(TOP)/mk/target.mk