Rework the build system a bit
[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 script
52
53 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
54 # See "MSys Note 3" in compiler/Makefile
55 INPLACE_SCRIPT=ghc-pkg-inplace.bat
56 all::
57         $(RM) -f $(INPLACE_SCRIPT)
58         echo '@call $(subst /,\,$(FPTOOLS_TOP_ABS_PLATFORM)/utils/ghc-pkg/$(HS_PROG)) --global-conf $(FPTOOLS_TOP_ABS_PLATFORM)/driver/package.conf.inplace %*' >> $(INPLACE_SCRIPT)
59         $(EXECUTABLE_FILE) $(INPLACE_SCRIPT)
60 else
61 INPLACE_SCRIPT=ghc-pkg-inplace
62 all::
63         $(RM) -f $(INPLACE_SCRIPT)
64         echo "#!$(SHELL)"                                                      >> $(INPLACE_SCRIPT)
65         echo "GHCPKGBIN=$(FPTOOLS_TOP_ABS)/utils/ghc-pkg/$(HS_PROG)"           >> $(INPLACE_SCRIPT)
66         echo "PKGCONF=$(FPTOOLS_TOP_ABS_PLATFORM)/driver/package.conf.inplace" >> $(INPLACE_SCRIPT)
67         echo 'exec $$GHCPKGBIN --global-conf $$PKGCONF $${1+"$$@"}'            >> $(INPLACE_SCRIPT)
68         $(EXECUTABLE_FILE) $(INPLACE_SCRIPT)
69 endif
70 CLEAN_FILES += $(INPLACE_SCRIPT)
71
72 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
73 LINK = ghc-pkg
74 LINK_TARGET = $(LINK)-$(ProjectVersion)
75 INSTALLED_SCRIPT=$(bindir)/$(LINK_TARGET)
76 install::
77         $(RM) -f $(INSTALLED_SCRIPT)
78         echo "#!$(SHELL)"                                           >> $(INSTALLED_SCRIPT)
79         echo "GHCPKGBIN=$(libexecdir)/$(HS_PROG)"                   >> $(INSTALLED_SCRIPT)
80         echo "PKGCONF=$(libdir)/package.conf"                       >> $(INSTALLED_SCRIPT)
81         echo 'exec $$GHCPKGBIN --global-conf $$PKGCONF $${1+"$$@"}' >> $(INSTALLED_SCRIPT)
82         $(EXECUTABLE_FILE) $(INSTALLED_SCRIPT)
83 endif
84
85 # ghc-pkg is needed to boot in rts/ and library dirs
86 # Do a recursive 'make all' after generating dependencies, because this
87 # will work with 'make -j'.
88 ifneq "$(BootingFromHc)" "YES"
89 boot :: depend
90         $(MAKE) all
91 endif
92
93 include $(TOP)/mk/target.mk