1 # -----------------------------------------------------------------------------
2 # $Id: package.mk,v 1.40 2004/11/03 12:31:42 ross Exp $
6 ifeq "$(STANDALONE_PACKAGE)" ""
7 ifeq "$(ProjectNameShort)" "ghc"
8 STANDALONE_PACKAGE = NO
10 STANDALONE_PACKAGE = YES
14 # -----------------------------------------------------------------------------
15 # Build the package configuration file and tell the compiler about it.
19 ifeq "$(STANDALONE_PACKAGE)" "NO"
20 PKGCONF_CPP_EXTRA_OPTS = -I$(GHC_INCLUDE_DIR)
22 PKGCONF_CPP_EXTRA_OPTS =
25 package.conf.inplace : package.conf.in
26 $(CPP) $(RAWCPP_FLAGS) -P $(PKGCONF_CPP_EXTRA_OPTS) -x c $(PACKAGE_CPP_OPTS) $< | \
27 grep -v '^#pragma GCC' | \
28 sed -e 's/""//g' -e 's/\[ *,/[ /g' >$@
30 package.conf.installed : package.conf.in
31 $(CPP) $(RAWCPP_FLAGS) -P $(PKGCONF_CPP_EXTRA_OPTS) -DINSTALLING -x c $(PACKAGE_CPP_OPTS) $< | \
32 grep -v '^#pragma GCC' | \
33 sed -e 's/""//g' -e 's/\[ *,/[ /g' >$@
35 # we could be more accurate here and add a dependency on
36 # ghc/driver/package.conf, but that doesn't work too well because of
37 # make's limited accuracy with modification times: when doing 'make
38 # boot' in multiple packages, make won't detect that the package
39 # configuration needs updating if it was updated already in the last
42 # The stamp file goes in $(GHC_DRIVER_DIR), so that if someone happens
43 # to 'make clean' in ghc without cleaning in libraries too, the packages
44 # will be correctly re-installed.
46 ifeq "$(STANDALONE_PACKAGE)" "NO"
48 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
49 CLEAN_FILES += $(STAMP_PKG_CONF)
51 ifneq "$(BootingFromHc)" "YES"
52 boot all :: $(STAMP_PKG_CONF)
55 $(STAMP_PKG_CONF) : package.conf.inplace package.conf.installed
56 $(GHC_PKG_INPLACE) --update-package <package.conf.inplace
57 $(GHC_PKG_INPLACE) -f $(GHC_DRIVER_DIR)/package.conf --update-package <package.conf.installed
58 @touch $(STAMP_PKG_CONF)
60 CLEAN_FILES += package.conf.installed package.conf.inplace
62 else # $(STANDALONE_PACKAGE) == "YES"
64 PACKAGE_CPP_OPTS += -DPACKAGE=\"${PACKAGE}\"
65 PACKAGE_CPP_OPTS += -DPACKAGE_DEPS='$(subst " ","$(comma) ",$(patsubst %,"%",$(PACKAGE_DEPS)))'
66 PACKAGE_CPP_OPTS += -DLIBRARY=\"HS$(PACKAGE)\"
67 PACKAGE_CPP_OPTS += -DLIBDIR=\"$(libdir)\"
68 PACKAGE_CPP_OPTS += -DFPTOOLS_TOP_ABS=\"${FPTOOLS_TOP_ABS}\"
70 # Let the package configuration file refer to $(libdir) as
71 # ${pkglibdir}. Note we can't use ${libdir} because ghc-pkg already
72 # redefines it to point to GHC's libdir (bug or feature?).
74 install :: package.conf.installed
75 $(GHC_PKG) --force --update-package <package.conf.installed
77 # Invoke this rule by hand in order to use the package in-place
78 install-inplace-pkg : package.conf.inplace
79 $(GHC_PKG) --force --update-package <package.conf.inplace
81 endif # $(STANDALONE_PACKAGE)
85 # -----------------------------------------------------------------------------
86 # Building the static library libHS<pkg>.a
88 ifeq "$(STANDALONE_PACKAGE)" "NO"
92 SRC_HSC2HS_OPTS += -I.
94 ifeq "$(NON_HS_PACKAGE)" ""
95 SRC_HC_OPTS += -package-name $(PACKAGE)
96 SRC_HC_OPTS += $(GhcLibHcOpts)
97 SRC_HC_OPTS += $(patsubst %, -package %, $(PACKAGE_DEPS))
100 LIBRARY = libHS$(PACKAGE)$(_way).a
108 # POSSIBLE alternative version using --make:
111 # $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
115 # $(AR) $(AR_OPTS) $@ $(HS_OBJS)
119 # $(GHC_INPLACE) $(HC_OPTS) --make $<
121 # $(GHC_INPLACE) $(HC_OPTS) --make $<
123 # -----------------------------------------------------------------------------
124 # Installation; need to install .hi files as well as libraries
126 ifeq "$(DLLized)" "YES"
127 INSTALL_PROGS += $(DLL_NAME)
128 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
131 # The interface files are put inside the $(libdir), since they
132 # might (potentially) be platform specific..
134 ifeq "$(HIERARCHICAL_LIB)" "YES"
135 ifacedir = $(libdir)/imports
137 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
140 # If the lib consists of a hierachy of modules, we must retain the directory
141 # structure when we install the interfaces.
142 ifeq "$(HIERARCHICAL_LIB)" "YES"
143 INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
144 ifneq "$(ALL_DIRS)" ""
146 @for i in $(ALL_DIRS); do \
147 $(INSTALL_DIR) $(ifacedir)/$$i; \
151 INSTALL_IFACES += $(HS_IFACES)
154 # -----------------------------------------------------------------------------
157 ifeq "$(STANDALONE_PACKAGE)" "NO"
158 MKDEPENDHS = $(GHC_INPLACE)
161 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
163 ifeq "$(STANDALONE_PACKAGE)" "NO"
164 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
167 endif # $(PACKAGE) /= ""
169 # install library (could be implicitly specified or explicitly, like libHS*_cbits.a)
170 INSTALL_LIBS += $(LIBRARY)
172 #--------------------------------------------------------------
173 # Building dynamically-linkable libraries for GHCi
175 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
177 # Why? GHCi can only link .o files (at the moment), not .a files
178 # so we have to build libFoo.o as well as libFoo.a
180 # Furthermore, GHCi currently never loads
181 # profiling libraries (or other non-std ways)
183 ifneq "$(LIBRARY)" ""
186 ifeq "$(GhcWithInterpreter)" "YES"
188 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
190 INSTALL_LIBS += $(GHCI_LIBRARY)
191 CLEAN_FILES += $(GHCI_LIBRARY)
193 all :: $(GHCI_LIBRARY)
195 ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
196 # If you don't want to build GHCI_LIBRARY the 'standard' way,
197 # set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
198 # hslibs/Win32 uses this 'feature', which will go away soon
199 # when we can use a "fixed" ld.
201 $(GHCI_LIBRARY) : $(LIBOBJS)
202 $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
204 endif # DONT_WANT_STD_GHCI_LIB_RULE
205 endif # GhcWithInterpreter
208 # -----------------------------------------------------------------------------
209 # Doc building with Haddock
211 ifneq "$(NO_HADDOCK_DOCS)" "YES"
213 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS))))
216 HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
220 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
224 @echo Haddock must be installed in order to build HTML library documentation.
225 @echo Please install Haddock and re-configure.
232 $(RM) -rf $(HTML_DIR)
234 $(HTML_DOC) : $(HS_PPS)
235 @$(INSTALL_DIR) $(HTML_DIR)
236 $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
237 --package=$(PACKAGE) \
238 --dump-interface=$(PACKAGE).haddock \
239 --use-index=../doc-index.html --use-contents=../index.html \
240 $(foreach pkg, $(PACKAGE_DEPS), \
241 --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
243 CLEAN_FILES += $(PACKAGE).haddock
246 $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
249 $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
251 install-docs :: $(HTML_DOC)
252 @$(INSTALL_DIR) $(datadir)/html/libraries/$(PACKAGE)
253 @for i in $(HTML_DIR)/*; do \
254 echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(datadir)/html/libraries/$(PACKAGE); \
255 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(datadir)/html/libraries/$(PACKAGE); \
257 $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(datadir)/html/libraries/$(PACKAGE)
260 endif # NO_HADDOCK_DOCS
262 # -----------------------------------------------------------------------------
264 endif # $(LIBRARY) /= ""