b6e762530a50856f7c30df3efd3938849f7a2b4f
[ghc.git] / utils / ghc-pkg / ghc.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009 The University of Glasgow
4 #
5 # This file is part of the GHC build system.
6 #
7 # To understand how the build system works and how to modify it, see
8 # http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13 # -----------------------------------------------------------------------------
14 # Bootstrapping ghc-pkg
15
16 utils/ghc-pkg_dist_PROG = ghc-pkg$(exeext)
17
18 ifeq "$(BootingFromHc)" "YES"
19
20 inplace/bin/ghc-pkg : utils/ghc-pkg/dist-install/build/tmp/$(utils/ghc-pkg_dist_PROG)$(exeext)
21 ifeq "$(Windows)" "YES"
22 cp $< $@
23 else
24 $(call removeFiles,$@)
25 echo "#!/bin/sh" >>$@
26 echo "PKGCONF=$(TOP)/$(INPLACE_PACKAGE_CONF)" >>$@
27 echo '$(TOP)/$< --global-conf $$PKGCONF $${1+"$$@"}' >> $@
28 chmod +x $@
29 endif
30
31 else
32
33 $(GHC_PKG_INPLACE) : utils/ghc-pkg/dist/build/$(utils/ghc-pkg_dist_PROG)$(exeext) | $$(dir $$@)/. $(INPLACE_PACKAGE_CONF)/.
34 $(call removeFiles,$(wildcard $(INPLACE_PACKAGE_CONF)/*))
35 ifeq "$(Windows)" "YES"
36 cp $< $@
37 else
38 $(call removeFiles,$@)
39 echo "#!/bin/sh" >>$@
40 echo "PKGCONF=$(TOP)/$(INPLACE_PACKAGE_CONF)" >>$@
41 echo '$(TOP)/$< --global-conf $$PKGCONF $${1+"$$@"}' >> $@
42 chmod +x $@
43 endif
44
45 endif
46
47 # depend on ghc-cabal, otherwise we build Cabal twice when building in parallel.
48 # (ghc-cabal is an order-only dependency, we don't need to rebuild ghc-pkg
49 # if ghc-cabal is newer).
50 # The binary package is not warning-clean, so we need a few -fno-warns here.
51 #
52 # ToDo: we might want to do this using ghc-cabal instead.
53 #
54 utils/ghc-pkg/dist/build/$(utils/ghc-pkg_dist_PROG)$(exeext): utils/ghc-pkg/Main.hs utils/ghc-pkg/Version.hs | bootstrapping/. $$(dir $$@)/. $(GHC_CABAL_INPLACE)
55 "$(GHC)" $(SRC_HC_OPTS) --make utils/ghc-pkg/Main.hs -o $@ \
56 -no-user-package-conf \
57 -Wall -fno-warn-unused-imports -fno-warn-warnings-deprecations \
58 -DCABAL_VERSION=$(CABAL_VERSION) \
59 -DBOOTSTRAPPING \
60 -odir bootstrapping \
61 -hidir bootstrapping \
62 -iutils/ghc-pkg \
63 -XCPP -XExistentialQuantification -XDeriveDataTypeable \
64 -ilibraries/Cabal/Cabal \
65 -ilibraries/filepath \
66 -ilibraries/extensible-exceptions \
67 -ilibraries/hpc \
68 -ilibraries/binary/src \
69 -ilibraries/bin-package-db
70
71
72 utils/ghc-pkg/Version.hs: mk/project.mk
73 $(call removeFiles,$@)
74 echo "module Version where" >> $@
75 echo "version, targetOS, targetARCH :: String" >> $@
76 echo "version = \"$(ProjectVersion)\"" >> $@
77 echo "targetOS = \"$(TargetOS_CPP)\"" >> $@
78 echo "targetARCH = \"$(TargetArch_CPP)\"" >> $@
79
80 $(eval $(call clean-target,utils/ghc-pkg,dist,\
81 utils/ghc-pkg/dist \
82 utils/ghc-pkg/Version.hs))
83
84 # -----------------------------------------------------------------------------
85 # Building ghc-pkg with stage 1
86
87 utils/ghc-pkg_dist-install_USES_CABAL = YES
88 utils/ghc-pkg_PACKAGE = ghc-pkg
89
90 utils/ghc-pkg_dist-install_PROG = ghc-pkg
91 utils/ghc-pkg_dist-install_SHELL_WRAPPER = YES
92 utils/ghc-pkg_dist-install_INSTALL_SHELL_WRAPPER = YES
93 utils/ghc-pkg_dist-install_INSTALL_SHELL_WRAPPER_NAME = ghc-pkg-$(ProjectVersion)
94 utils/ghc-pkg_dist-install_INSTALL_INPLACE = NO
95
96 ifeq "$(BootingFromHc)" "YES"
97 utils/ghc-pkg_dist-install_OTHER_OBJS += $(ALL_STAGE1_LIBS) $(ALL_STAGE1_LIBS) $(ALL_STAGE1_LIBS) $(ALL_RTS_LIBS) $(libffi_STATIC_LIB)
98 endif
99
100 $(eval $(call build-prog,utils/ghc-pkg,dist-install,1))
101
102 ifeq "$(Windows)" "NO"
103 install: install_utils/ghc-pkg_link
104
105 .PNONY: install_utils/ghc-pkg_link
106 install_utils/ghc-pkg_link:
107 $(call INSTALL_DIR,"$(DESTDIR)$(bindir)")
108 $(call removeFiles,"$(DESTDIR)$(bindir)/ghc-pkg")
109 $(LN_S) ghc-pkg-$(ProjectVersion) "$(DESTDIR)$(bindir)/ghc-pkg"
110 endif
111