1 # -----------------------------------------------------------------------------
2 # $Id: package.mk,v 1.43 2005/01/14 08:01:27 wolfgang 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 PACKAGE_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -Iinclude
22 PACKAGE_CPP_OPTS += -Iinclude
25 PACKAGE_CPP_OPTS += -DPACKAGE=${PACKAGE}
26 PACKAGE_CPP_OPTS += -DVERSION=${VERSION}
28 IMPORT_DIR_INSTALLED = $$libdir/imports
29 IMPORT_DIR_INPLACE = $$libdir/libraries/$(PACKAGE)
31 LIB_DIR_INSTALLED = $$libdir
32 LIB_DIR_INPLACE = $$libdir/libraries/$(PACKAGE)
34 package.conf.inplace : package.conf.in
35 $(CPP) $(RAWCPP_FLAGS) -P \
36 -DIMPORT_DIR='"$(IMPORT_DIR_INPLACE)"' \
37 -DLIB_DIR='"$(LIB_DIR_INPLACE)"' \
38 -x c $(PACKAGE_CPP_OPTS) $< | \
39 grep -v '^#pragma GCC' | \
40 sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$@
42 package.conf.installed : package.conf.in
43 $(CPP) $(RAWCPP_FLAGS) -P -DINSTALLING \
44 -DIMPORT_DIR='"$(IMPORT_DIR_INSTALLED)"' \
45 -DLIB_DIR='"$(LIB_DIR_INSTALLED)"' \
46 -x c $(PACKAGE_CPP_OPTS) $< | \
47 grep -v '^#pragma GCC' | \
48 sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$@
50 # we could be more accurate here and add a dependency on
51 # ghc/driver/package.conf, but that doesn't work too well because of
52 # make's limited accuracy with modification times: when doing 'make
53 # boot' in multiple packages, make won't detect that the package
54 # configuration needs updating if it was updated already in the last
57 # The stamp file goes in $(GHC_DRIVER_DIR), so that if someone happens
58 # to 'make clean' in ghc without cleaning in libraries too, the packages
59 # will be correctly re-installed.
61 ifeq "$(STANDALONE_PACKAGE)" "NO"
63 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
64 CLEAN_FILES += $(STAMP_PKG_CONF)
66 ifneq "$(BootingFromHc)" "YES"
67 boot all :: $(STAMP_PKG_CONF)
70 $(STAMP_PKG_CONF) : package.conf.inplace package.conf.installed
71 $(GHC_PKG_INPLACE) --update-package <package.conf.inplace
72 $(GHC_PKG_INPLACE) -f $(GHC_DRIVER_DIR)/package.conf --update-package <package.conf.installed
73 @touch $(STAMP_PKG_CONF)
75 CLEAN_FILES += package.conf.installed package.conf.inplace
77 else # $(STANDALONE_PACKAGE) == "YES"
79 PACKAGE_CPP_OPTS += -DPACKAGE_DEPS='$(subst " ","$(comma) ",$(patsubst %,"%",$(PACKAGE_DEPS)))'
80 PACKAGE_CPP_OPTS += -DLIBRARY=\"HS$(PACKAGE)\"
81 PACKAGE_CPP_OPTS += -DLIBDIR=\"$(libdir)\"
82 PACKAGE_CPP_OPTS += -DFPTOOLS_TOP_ABS=\"${FPTOOLS_TOP_ABS}\"
84 # Let the package configuration file refer to $(libdir) as
85 # ${pkglibdir}. Note we can't use ${libdir} because ghc-pkg already
86 # redefines it to point to GHC's libdir (bug or feature?).
88 install :: package.conf.installed
89 $(GHC_PKG) --force --update-package <package.conf.installed
91 # Invoke this rule by hand in order to use the package in-place
92 install-inplace-pkg : package.conf.inplace
93 $(GHC_PKG) --force --update-package <package.conf.inplace
95 endif # $(STANDALONE_PACKAGE)
99 # -----------------------------------------------------------------------------
100 # Building the static library libHS<pkg>.a
102 ifeq "$(STANDALONE_PACKAGE)" "NO"
106 SRC_HSC2HS_OPTS += -I.
108 ifeq "$(NON_HS_PACKAGE)" ""
109 SRC_HC_OPTS += -ignore-package $(PACKAGE)
110 SRC_HC_OPTS += $(GhcLibHcOpts)
111 SRC_HC_OPTS += $(patsubst %, -package %, $(PACKAGE_DEPS))
114 LIBRARY = libHS$(PACKAGE)$(_way).a
122 # POSSIBLE alternative version using --make:
125 # $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
129 # $(AR) $(AR_OPTS) $@ $(HS_OBJS)
133 # $(GHC_INPLACE) $(HC_OPTS) --make $<
135 # $(GHC_INPLACE) $(HC_OPTS) --make $<
137 # -----------------------------------------------------------------------------
138 # Installation; need to install .hi files as well as libraries
140 ifeq "$(DLLized)" "YES"
141 INSTALL_PROGS += $(DLL_NAME)
142 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
145 # The interface files are put inside the $(libdir), since they
146 # might (potentially) be platform specific..
148 ifeq "$(HIERARCHICAL_LIB)" "YES"
149 ifacedir = $(libdir)/imports
151 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
154 # If the lib consists of a hierachy of modules, we must retain the directory
155 # structure when we install the interfaces.
156 ifeq "$(HIERARCHICAL_LIB)" "YES"
157 INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
158 ifneq "$(ALL_DIRS)" ""
160 @for i in $(ALL_DIRS); do \
161 $(INSTALL_DIR) $(ifacedir)/$$i; \
165 INSTALL_IFACES += $(HS_IFACES)
168 # -----------------------------------------------------------------------------
171 ifeq "$(STANDALONE_PACKAGE)" "NO"
172 MKDEPENDHS = $(GHC_INPLACE)
175 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
177 ifeq "$(STANDALONE_PACKAGE)" "NO"
178 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
181 endif # $(PACKAGE) /= ""
183 # install library (could be implicitly specified or explicitly, like libHS*_cbits.a)
184 INSTALL_LIBS += $(LIBRARY)
186 #--------------------------------------------------------------
187 # Building dynamically-linkable libraries for GHCi
189 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
191 # Why? GHCi can only link .o files (at the moment), not .a files
192 # so we have to build libFoo.o as well as libFoo.a
194 # Furthermore, GHCi currently never loads
195 # profiling libraries (or other non-std ways)
197 ifneq "$(LIBRARY)" ""
200 ifeq "$(GhcWithInterpreter)" "YES"
202 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
204 INSTALL_LIBS += $(GHCI_LIBRARY)
205 CLEAN_FILES += $(GHCI_LIBRARY)
207 all :: $(GHCI_LIBRARY)
209 ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
210 # If you don't want to build GHCI_LIBRARY the 'standard' way,
211 # set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
212 # hslibs/Win32 uses this 'feature', which will go away soon
213 # when we can use a "fixed" ld.
215 $(GHCI_LIBRARY) : $(LIBOBJS)
216 $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
218 endif # DONT_WANT_STD_GHCI_LIB_RULE
219 endif # GhcWithInterpreter
222 ifeq "$(GhcBuildDylibs)" "YES"
224 # Build dynamic libraries.
225 # Currently, this is a hack. Anyone, PLEASE clean it up.
227 # For now, we pretend that there are two operating systems in the world;
228 # Darwin, and Everything Else. Furthermore, we pretend that Everything Else
229 # behaves like Linux.
231 ifeq "$(darwin_TARGET_OS)" "1"
232 # Darwin: Shared libraries end in .dylib
233 DYLD_LIBRARY = $(patsubst %.a,%_dyn.dylib,$(LIBRARY))
235 # About the options used for Darwin:
237 # Apple's way of saying -shared
238 # -flat_namespace -undefined suppress:
239 # Without these options, we'd have to specify the correct dependencies
240 # for each of the dylibs. Twolevel namespaces are in general a good thing
241 # (they make things more robust), so we should fix this sooner or later.
243 # Causes the dynamic linker to ignore the DYLD_LIBRARY_PATH when loading
244 # this lib and instead look for it at its absolute path.
245 # When installing the .dylibs (see target.mk), we'll change that path to
246 # point to the place they are installed.
247 # Note: I'm not yet sure about this, but I think it will be convenient for
248 # users not to have to set up DYLD_LIBRARY_PATH to point to the GHC
249 # library dir. -- Wolfgang
251 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
252 $(CC) -dynamiclib -o $@ $(STUBOBJS) $(LIBOBJS) -flat_namespace -undefined suppress -install_name `pwd`/$@
254 DYLD_LIBRARY = $(patsubst %.a,%_dyn.so,$(LIBRARY))
256 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
257 $(CC) -shared -o $@ $(STUBOBJS) $(LIBOBJS)
260 INSTALL_LIBS += $(DYLD_LIBRARY)
261 CLEAN_FILES += $(DYLD_LIBRARY)
263 all :: $(DYLD_LIBRARY)
268 # -----------------------------------------------------------------------------
269 # Doc building with Haddock
271 ifneq "$(NO_HADDOCK_DOCS)" "YES"
273 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS))))
276 HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
280 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
284 @echo Haddock must be installed in order to build HTML library documentation.
285 @echo Please install Haddock and re-configure.
292 $(RM) -rf $(HTML_DIR)
294 $(HTML_DOC) : $(HS_PPS)
295 @$(INSTALL_DIR) $(HTML_DIR)
296 $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
297 --package=$(PACKAGE) \
298 --dump-interface=$(PACKAGE).haddock \
299 --use-index=../doc-index.html --use-contents=../index.html \
300 $(foreach pkg, $(PACKAGE_DEPS), \
301 --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
303 CLEAN_FILES += $(PACKAGE).haddock
306 $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
309 $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
311 install-docs :: $(HTML_DOC)
312 @$(INSTALL_DIR) $(datadir)/html/libraries/$(PACKAGE)
313 @for i in $(HTML_DIR)/*; do \
314 echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(datadir)/html/libraries/$(PACKAGE); \
315 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(datadir)/html/libraries/$(PACKAGE); \
317 $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(datadir)/html/libraries/$(PACKAGE)
320 endif # NO_HADDOCK_DOCS
322 # -----------------------------------------------------------------------------
324 endif # $(LIBRARY) /= ""