don't forget to clean the .bat files
[ghc-hetmet.git] / utils / ghc-pkg / Makefile
1 TOP=../..
2 include $(TOP)/mk/boilerplate.mk
3
4 # hack for ghci-inplace script, see below
5 INSTALLING=1
6
7 # -----------------------------------------------------------------------------
8 # ghc-pkg.bin
9
10 SRC_HC_OPTS += -cpp -Wall -fno-warn-name-shadowing -fno-warn-unused-matches
11
12 # This causes libghccompat.a to be used:
13 include $(GHC_COMPAT_DIR)/compat.mk
14
15 SRC_HC_OPTS += $(PACKAGE_CABAL)
16
17 # This is required because libghccompat.a must be built with
18 # $(GhcHcOpts) because it is linked to the compiler, and hence
19 # we must also build with $(GhcHcOpts) here:
20 SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
21
22 ifeq "$(ghc_ge_504)" "NO"
23 SRC_HC_OPTS +=  -package lang -package util -package text
24 endif
25
26 # On Windows, ghc-pkg is a standalone program
27 # ($bindir/ghc-pkg.exe), whereas on Unix it needs a wrapper script
28 # to pass the appropriate flag to the real binary
29 # ($libexecdir/ghc-pkg.bin) so that it can find package.conf.
30 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
31 HS_PROG           = ghc-pkg.exe
32 INSTALL_PROGS    += $(HS_PROG)
33 else
34 HS_PROG           = ghc-pkg.bin
35 INSTALL_LIBEXECS += $(HS_PROG)
36 endif
37
38 # -----------------------------------------------------------------------------
39 # Create the Version.hs file
40
41 VERSION_HS = Version.hs
42 EXTRA_SRCS += $(VERSION_HS)
43
44 boot :: $(VERSION_HS)
45
46 Version.hs : Makefile $(TOP)/mk/config.mk
47         @$(RM) -f $(VERSION_HS)
48         @echo "Creating $(VERSION_HS) ... "
49         @echo "module Version where" >>$(VERSION_HS)
50         @echo "version, targetOS, targetARCH :: String" >>$(VERSION_HS)
51         @echo "version    = \"$(ProjectVersion)\"" >> $(VERSION_HS)
52         @echo "targetOS   = \"$(TargetOS_CPP)\"" >> $(VERSION_HS)
53         @echo "targetARCH = \"$(TargetArch_CPP)\"" >> $(VERSION_HS)
54
55 DIST_CLEAN_FILES += $(VERSION_HS)
56
57 # -----------------------------------------------------------------------------
58 # ghc-pkg script
59
60 ifeq "$(INSTALLING)" "1"
61 ifeq "$(BIN_DIST)"   "1"
62 GHCPKGBIN=$$\"\"libexecdir/$(HS_PROG)
63 PKGCONF=$$\"\"libdir/package.conf
64 else
65 GHCPKGBIN=$(libexecdir)/$(HS_PROG)
66 PKGCONF=$(libdir)/package.conf
67 endif # BIN_DIST
68 else
69 GHCPKGBIN=$(FPTOOLS_TOP_ABS)/utils/ghc-pkg/$(HS_PROG)
70 PKGCONF=$(FPTOOLS_TOP_ABS_PLATFORM)/driver/package.conf.inplace
71 endif
72
73 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
74 INSTALLED_SCRIPT_PROG  = ghc-pkg-$(ProjectVersion)
75 endif
76 INPLACE_SCRIPT_PROG    = ghc-pkg-inplace
77
78 SCRIPT_OBJS       = ghc-pkg.sh
79 INTERP            = $(SHELL)
80 SCRIPT_SUBST_VARS = GHCPKGBIN PKGCONFOPT
81 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
82 INSTALL_SCRIPTS  += $(SCRIPT_PROG)
83 endif
84 PKGCONFOPT        = --global-conf $(PKGCONF)
85
86 ifeq "$(INSTALLING)" "1"
87 SCRIPT_PROG     =  $(INSTALLED_SCRIPT_PROG)
88 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
89 LINK            =  ghc-pkg
90 endif
91 else
92 SCRIPT_PROG     =  $(INPLACE_SCRIPT_PROG)
93 endif
94
95 # -----------------------------------------------------------------------------
96 # don't recurse on 'make install'
97 #
98 ifeq "$(INSTALLING)" "1"
99 all :: $(HS_PROG)
100         $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
101 clean distclean maintainer-clean ::
102         $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
103 endif
104
105 ifeq "$(INSTALLING)$(HOSTPLATFORM)" "0i386-unknown-mingw32"
106 all :: $(INPLACE_SCRIPT_PROG).bat
107
108 # See "MSys Note 3" in compiler/Makefile
109 $(INPLACE_SCRIPT_PROG).bat :
110         echo '@call $(subst /,\,$(FPTOOLS_TOP_ABS_PLATFORM)/utils/ghc-pkg/$(HS_PROG)) --global-conf $(PKGCONF) %*' >> $@
111         chmod 755 $@
112
113 CLEAN_FILES += $(INPLACE_SCRIPT_PROG).bat
114 endif
115
116 # ghc-pkg is needed to boot in rts/ and library dirs
117 # Do a recursive 'make all' after generating dependencies, because this
118 # will work with 'make -j'.
119 ifneq "$(BootingFromHc)" "YES"
120 boot :: depend
121         $(MAKE) all
122 endif
123
124 include $(TOP)/mk/target.mk