1 # -----------------------------------------------------------------------------
2 # $Id: package.mk,v 1.55 2005/05/13 10:05:33 krasimir Exp $
6 # -----------------------------------------------------------------------------
7 # Directory layouts, installation etc.
9 # Here Windows & Unix differ. On Windows, the value of $(prefix) is known
10 # to the compiler, and spliced into package.conf in place of $topdir at
13 # On Unix, we only use absolute paths in package.conf.
16 ifeq "$(Windows)" "YES"
19 PKG_DATADIR = $$topdir
23 PKG_LIBDIR = $(libdir)
24 PKG_DATADIR = $(datadir)
28 IMPORT_DIR_INSTALLED = $(PKG_LIBDIR)/imports
29 IMPORT_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
31 INCLUDE_DIR_INSTALLED = $(PKG_LIBDIR)/include
32 INCLUDE_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/include
34 LIB_DIR_INSTALLED = $(PKG_LIBDIR)
35 LIB_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
37 DATA_DIR_INSTALLED = $(PKG_DATADIR)
38 DATA_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
40 HTML_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/html
41 HTML_DIR_INSTALLED = $(PKG_DATADIR)/html/libraries/$(PACKAGE)
43 HADDOCK_IFACE_INPLACE = $(HTML_DIR_INPLACE)/$(PACKAGE).haddock
44 HADDOCK_IFACE_INSTALLED = $(HTML_DIR_INSTALLED)/$(PACKAGE).haddock
46 # -----------------------------------------------------------------------------
47 # Build the package configuration file and tell the compiler about it.
49 # We want to build two versions of the package configuration: one for use
54 PACKAGE_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -Iinclude
56 PACKAGE_CPP_OPTS += -DPACKAGE=${PACKAGE}
57 PACKAGE_CPP_OPTS += -DVERSION=${VERSION}
59 PACKAGE_CPP_OPTS += -DPKG_LIBDIR='"$(PKG_LIBDIR)"'
60 PACKAGE_CPP_OPTS += -DPKG_DATADIR='"$(PKG_DATADIR)"'
62 package.conf.inplace : package.conf.in
63 $(CPP) $(RAWCPP_FLAGS) -P \
64 -DIMPORT_DIR='"$(IMPORT_DIR_INPLACE)"' \
65 -DLIB_DIR='"$(LIB_DIR_INPLACE)"' \
66 -DINCLUDE_DIR='"$(INCLUDE_DIR_INPLACE)"' \
67 -DDATA_DIR='"$(DATA_DIR_INPLACE)"' \
68 -DHTML_DIR='"$(HTML_DIR_INPLACE)"' \
69 -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INPLACE)"' \
70 -DFPTOOLS_TOP_ABS='"${FPTOOLS_TOP_ABS}"' \
71 -x c $(PACKAGE_CPP_OPTS) $< | \
72 grep -v '^#pragma GCC' | \
73 sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$@
76 $(CPP) $(RAWCPP_FLAGS) -P -DINSTALLING \
77 -DIMPORT_DIR='"$(IMPORT_DIR_INSTALLED)"' \
78 -DLIB_DIR='"$(LIB_DIR_INSTALLED)"' \
79 -DINCLUDE_DIR='"$(INCLUDE_DIR_INSTALLED)"' \
80 -DDATA_DIR='"$(DATA_DIR_INSTALLED)"' \
81 -DHTML_DIR='"$(HTML_DIR_INSTALLED)"' \
82 -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INSTALLED)"' \
84 -x c $(PACKAGE_CPP_OPTS) package.conf.in \
85 | grep -v '^#pragma GCC' \
86 | sed -e 's/""//g' -e 's/:[ ]*,/: /g' \
87 | $(GHC_PKG_INSTALL_PROG) --global-conf $(DESTDIR)$(datadir)/package.conf update - --force
89 GHC_PKG_INSTALL_PROG = $(FPTOOLS_TOP_ABS)/utils/ghc-pkg/dist-install/build/ghc-pkg/ghc-pkg
91 # we could be more accurate here and add a dependency on
92 # driver/package.conf, but that doesn't work too well because of
93 # make's limited accuracy with modification times: when doing 'make
94 # boot' in multiple packages, make won't detect that the package
95 # configuration needs updating if it was updated already in the last
98 # The stamp file goes in $(GHC_DRIVER_DIR), so that if someone happens
99 # to 'make clean' in ghc without cleaning in libraries too, the packages
100 # will be correctly re-installed.
103 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
104 CLEAN_FILES += $(STAMP_PKG_CONF)
106 ifneq "$(BootingFromHc)" "YES"
107 boot all :: $(STAMP_PKG_CONF)
110 $(STAMP_PKG_CONF) : package.conf.inplace
111 $(GHC_PKG_INPLACE) update - --force-files <package.conf.inplace
112 @touch $(STAMP_PKG_CONF)
114 CLEAN_FILES += package.conf.inplace
118 # -----------------------------------------------------------------------------
119 # Building the static library libHS<pkg>.a
121 SRC_HSC2HS_OPTS += -I.
123 ifneq "$(NO_SET_HC)" "YES"
125 BOOTSTRAPPING_PACKAGE_CONF_HC_OPTS =
127 IGNORE_PACKAGE_FLAG = -package-name $(PACKAGE)-$(VERSION)
129 ifeq "$(NON_HS_PACKAGE)" ""
130 SRC_HC_OPTS += $(IGNORE_PACKAGE_FLAG)
131 SRC_HC_OPTS += $(GhcLibHcOpts)
132 SRC_HC_OPTS += $(patsubst %, -package %, $(PACKAGE_DEPS))
135 # -XGenerics switches on generation of support code for
136 # derivable type classes. This is now off by default,
137 # but we switch it on for the libraries so that we generate
138 # the code in case someone importing wants it.
139 ifeq "$(NON_HS_PACKAGE)" ""
140 SRC_HC_OPTS += -XGenerics
143 ifndef DONT_WANT_STD_LIBRARY
145 ifeq "$(_way:%_dyn=YES)" "YES"
146 LIBRARY = libHS$(PACKAGE)$(_way:%_dyn=%)-ghc$(ProjectVersion)$(soext)
148 LIBRARY = libHS$(PACKAGE)$(_way).a
160 # POSSIBLE alternative version using --make:
163 # $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
167 # $(AR) $(AR_OPTS) $@ $(HS_OBJS)
171 # $(GHC_INPLACE) $(HC_OPTS) --make $<
173 # $(GHC_INPLACE) $(HC_OPTS) --make $<
175 # -----------------------------------------------------------------------------
176 # Installation; need to install .hi files as well as libraries
178 ifeq "$(DLLized)" "YES"
179 INSTALL_PROGS += $(DLL_NAME)
180 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
184 # The interface files are put inside the $(libdir), since they
185 # might (potentially) be platform specific..
187 ifeq "$(HIERARCHICAL_LIB)" "YES"
188 ifacedir = $(libdir)/imports
190 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
193 # If the lib consists of a hierachy of modules, we must retain the directory
194 # structure when we install the interfaces.
195 ifeq "$(HIERARCHICAL_LIB)" "YES"
196 INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
197 ifneq "$(ALL_DIRS)" ""
199 @for i in $(ALL_DIRS); do \
200 $(INSTALL_DIR) $(ifacedir)/$$i; \
204 INSTALL_IFACES += $(HS_IFACES)
207 # -----------------------------------------------------------------------------
210 MKDEPENDHS = $(GHC_INPLACE)
212 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
213 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
215 endif # $(PACKAGE) != ""
217 #--------------------------------------------------------------
220 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
221 INSTALL_LIBS += $(LIBRARY) $(GHCI_LIBRARY)
224 #--------------------------------------------------------------
225 # Building dynamically-linkable libraries for GHCi
227 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
229 # Why? GHCi can only link .o files (at the moment), not .a files
230 # so we have to build libFoo.o as well as libFoo.a
232 # Furthermore, GHCi currently never loads
233 # profiling libraries (or other non-std ways)
235 ifneq "$(LIBRARY)" ""
238 ifeq "$(GhcWithInterpreter)" "YES"
241 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
244 CLEAN_FILES += $(GHCI_LIBRARY)
246 all :: $(GHCI_LIBRARY)
248 ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
249 # If you don't want to build GHCI_LIBRARY the 'standard' way,
250 # set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
251 # hslibs/Win32 uses this 'feature', which will go away soon
252 # when we can use a "fixed" ld.
254 $(GHCI_LIBRARY) : $(LIBOBJS)
255 $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
257 endif # DONT_WANT_STD_GHCI_LIB_RULE
258 endif # GhcWithInterpreter
260 endif # $(LIBRARY) /= ""
262 # -----------------------------------------------------------------------------
263 # Doc building with Haddock
265 ifneq "$(PACKAGE)" ""
266 ifeq "$(HADDOCK_DOCS)" "YES"
268 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS)))) $(EXTRA_HADDOCK_SRCS)
270 HTML_DIR = ../html-docs/$(PACKAGE)
271 HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
275 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
280 $(RM) -rf $(HTML_DIR)
282 $(HTML_DOC) : $(HS_PPS)
283 @$(INSTALL_DIR) $(HTML_DIR)
284 $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
285 --package=$(PACKAGE) \
286 --dump-interface=$(PACKAGE).haddock \
287 --use-index=../doc-index.html --use-contents=../index.html \
288 --source-module=$(PackageSourceURL) \
289 $(foreach pkg, $(PACKAGE_DEPS), \
290 --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
292 CLEAN_FILES += $(PACKAGE).haddock
295 $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
298 $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
300 HTML_INSTALL_DIR = $(DESTDIR)$(htmldir)/libraries/html/$(PACKAGE)
302 install-docs :: $(HTML_DOC)
303 @$(INSTALL_DIR) $(HTML_INSTALL_DIR)
304 for i in $(HTML_DIR)/*; do \
305 echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
306 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
308 $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(HTML_INSTALL_DIR); \
312 endif # $(PACKAGE) /= ""
314 # -----------------------------------------------------------------------------