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