1 # -----------------------------------------------------------------------------
2 # $Id: package.mk,v 1.46 2005/02/08 10:21:36 simonmar Exp $
6 ifeq "$(STANDALONE_PACKAGE)" ""
7 ifeq "$(ProjectNameShort)" "ghc"
8 STANDALONE_PACKAGE = NO
10 STANDALONE_PACKAGE = YES
14 # -----------------------------------------------------------------------------
15 # Directory layouts, installation etc.
17 # Here Windows & Unix differ. On Windows, the value of $(prefix) is known
18 # to the compiler, and spliced into package.conf in place of $topdir at
21 # On Unix, we only use absolute paths in package.conf, except that when
22 # building a binary distribution we use $libdir and $datadir in package.conf
23 # which are then replaced by the correct values at install time.
26 ifeq "$(Windows)" "YES"
29 PKG_DATADIR = $$topdir
34 PKG_LIBDIR = $(libdir)
35 PKG_DATADIR = $(datadir)
38 PKG_DATADIR = $$datadir
43 IMPORT_DIR_INSTALLED = $(PKG_LIBDIR)/imports
44 IMPORT_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
46 INCLUDE_DIR_INSTALLED = $(PKG_LIBDIR)/include
47 INCLUDE_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/include
49 LIB_DIR_INSTALLED = $(PKG_LIBDIR)
50 LIB_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
52 DATA_DIR_INSTALLED = $(PKG_DATADIR)
53 DATA_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
55 HTML_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/html
56 HTML_DIR_INSTALLED = $(PKG_DATADIR)/html/libraries/$(PACKAGE)
58 HADDOCK_IFACE_INPLACE = $(HTML_DIR_INPLACE)/$(PACKAGE).haddock
59 HADDOCK_IFACE_INSTALLED = $(HTML_DIR_INSTALLED)/$(PACKAGE).haddock
61 # -----------------------------------------------------------------------------
62 # Build the package configuration file and tell the compiler about it.
64 # We want to build two versions of the package configuration: one for use
69 ifeq "$(STANDALONE_PACKAGE)" "NO"
70 PACKAGE_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -Iinclude
72 PACKAGE_CPP_OPTS += -Iinclude
75 PACKAGE_CPP_OPTS += -DPACKAGE=${PACKAGE}
76 PACKAGE_CPP_OPTS += -DVERSION=${VERSION}
78 PACKAGE_CPP_OPTS += -DPKG_LIBDIR='"$(PKG_LIBDIR)"'
79 PACKAGE_CPP_OPTS += -DPKG_DATADIR='"$(PKG_DATADIR)"'
81 package.conf.inplace : package.conf.in
82 $(CPP) $(RAWCPP_FLAGS) -P \
83 -DIMPORT_DIR='"$(IMPORT_DIR_INPLACE)"' \
84 -DLIB_DIR='"$(LIB_DIR_INPLACE)"' \
85 -DINCLUDE_DIR='"$(INCLUDE_DIR_INPLACE)"' \
86 -DDATA_DIR='"$(DATA_DIR_INPLACE)"' \
87 -DHTML_DIR='"$(HTML_DIR_INPLACE)"' \
88 -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INPLACE)"' \
89 -DFPTOOLS_TOP_ABS=\"${FPTOOLS_TOP_ABS}\" \
90 -x c $(PACKAGE_CPP_OPTS) $< | \
91 grep -v '^#pragma GCC' | \
92 sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$@
94 package.conf.installed : package.conf.in
95 $(CPP) $(RAWCPP_FLAGS) -P -DINSTALLING \
96 -DIMPORT_DIR='"$(IMPORT_DIR_INSTALLED)"' \
97 -DLIB_DIR='"$(LIB_DIR_INSTALLED)"' \
98 -DINCLUDE_DIR='"$(INCLUDE_DIR_INSTALLED)"' \
99 -DDATA_DIR='"$(DATA_DIR_INSTALLED)"' \
100 -DHTML_DIR='"$(HTML_DIR_INSTALLED)"' \
101 -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INSTALLED)"' \
102 -x c $(PACKAGE_CPP_OPTS) $< | \
103 grep -v '^#pragma GCC' | \
104 sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$@
106 # we could be more accurate here and add a dependency on
107 # ghc/driver/package.conf, but that doesn't work too well because of
108 # make's limited accuracy with modification times: when doing 'make
109 # boot' in multiple packages, make won't detect that the package
110 # configuration needs updating if it was updated already in the last
113 # The stamp file goes in $(GHC_DRIVER_DIR), so that if someone happens
114 # to 'make clean' in ghc without cleaning in libraries too, the packages
115 # will be correctly re-installed.
117 ifeq "$(STANDALONE_PACKAGE)" "NO"
119 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
120 CLEAN_FILES += $(STAMP_PKG_CONF)
122 ifneq "$(BootingFromHc)" "YES"
123 boot all :: $(STAMP_PKG_CONF)
126 $(STAMP_PKG_CONF) : package.conf.inplace package.conf.installed
127 $(GHC_PKG_INPLACE) --force --update-package <package.conf.inplace
128 $(GHC_PKG_INPLACE) -f $(GHC_DRIVER_DIR)/package.conf --force --update-package <package.conf.installed
129 @touch $(STAMP_PKG_CONF)
131 CLEAN_FILES += package.conf.installed package.conf.inplace
133 else # $(STANDALONE_PACKAGE) == "YES"
135 PACKAGE_CPP_OPTS += -DPACKAGE_DEPS='$(subst " ","$(comma) ",$(patsubst %,"%",$(PACKAGE_DEPS)))'
136 PACKAGE_CPP_OPTS += -DLIBRARY=\"HS$(PACKAGE)\"
137 PACKAGE_CPP_OPTS += -DLIBDIR=\"$(libdir)\"
139 # Let the package configuration file refer to $(libdir) as
140 # ${pkglibdir}. Note we can't use ${libdir} because ghc-pkg already
141 # redefines it to point to GHC's libdir (bug or feature?).
143 install :: package.conf.installed
144 $(GHC_PKG) --force --update-package <package.conf.installed
146 # Invoke this rule by hand in order to use the package in-place
147 install-inplace-pkg : package.conf.inplace
148 $(GHC_PKG) --force --update-package <package.conf.inplace
150 endif # $(STANDALONE_PACKAGE)
154 # -----------------------------------------------------------------------------
155 # Building the static library libHS<pkg>.a
157 ifeq "$(STANDALONE_PACKAGE)" "NO"
161 SRC_HSC2HS_OPTS += -I.
163 ifeq "$(NON_HS_PACKAGE)" ""
164 SRC_HC_OPTS += -ignore-package $(PACKAGE)
165 SRC_HC_OPTS += $(GhcLibHcOpts)
166 SRC_HC_OPTS += $(patsubst %, -package %, $(PACKAGE_DEPS))
169 # -fgenerics switches on generation of support code for
170 # derivable type classes. This is now off by default,
171 # but we switch it on for the libraries so that we generate
172 # the code in case someone importing wants it.
173 ifeq "$(NON_HS_PACKAGE)" ""
174 SRC_HC_OPTS += -fgenerics
177 LIBRARY = libHS$(PACKAGE)$(_way).a
185 # POSSIBLE alternative version using --make:
188 # $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
192 # $(AR) $(AR_OPTS) $@ $(HS_OBJS)
196 # $(GHC_INPLACE) $(HC_OPTS) --make $<
198 # $(GHC_INPLACE) $(HC_OPTS) --make $<
200 # -----------------------------------------------------------------------------
201 # Installation; need to install .hi files as well as libraries
203 ifeq "$(DLLized)" "YES"
204 INSTALL_PROGS += $(DLL_NAME)
205 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
208 # The interface files are put inside the $(libdir), since they
209 # might (potentially) be platform specific..
211 ifeq "$(HIERARCHICAL_LIB)" "YES"
212 ifacedir = $(libdir)/imports
214 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
217 # If the lib consists of a hierachy of modules, we must retain the directory
218 # structure when we install the interfaces.
219 ifeq "$(HIERARCHICAL_LIB)" "YES"
220 INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
221 ifneq "$(ALL_DIRS)" ""
223 @for i in $(ALL_DIRS); do \
224 $(INSTALL_DIR) $(ifacedir)/$$i; \
228 INSTALL_IFACES += $(HS_IFACES)
231 # install library (could be implicitly specified or explicitly, like libHS*_cbits.a)
232 INSTALL_LIBS += $(LIBRARY)
234 # -----------------------------------------------------------------------------
237 ifeq "$(STANDALONE_PACKAGE)" "NO"
238 MKDEPENDHS = $(GHC_INPLACE)
241 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
243 ifeq "$(STANDALONE_PACKAGE)" "NO"
244 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
247 #--------------------------------------------------------------
248 # Building dynamically-linkable libraries for GHCi
250 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
252 # Why? GHCi can only link .o files (at the moment), not .a files
253 # so we have to build libFoo.o as well as libFoo.a
255 # Furthermore, GHCi currently never loads
256 # profiling libraries (or other non-std ways)
258 ifneq "$(LIBRARY)" ""
261 ifeq "$(GhcWithInterpreter)" "YES"
263 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
264 INSTALL_LIBS += $(GHCI_LIBRARY)
266 CLEAN_FILES += $(GHCI_LIBRARY)
268 all :: $(GHCI_LIBRARY)
270 ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
271 # If you don't want to build GHCI_LIBRARY the 'standard' way,
272 # set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
273 # hslibs/Win32 uses this 'feature', which will go away soon
274 # when we can use a "fixed" ld.
276 $(GHCI_LIBRARY) : $(LIBOBJS)
277 $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
279 endif # DONT_WANT_STD_GHCI_LIB_RULE
280 endif # GhcWithInterpreter
283 ifeq "$(GhcBuildDylibs)" "YES"
285 # Build dynamic libraries.
286 # Currently, this is a hack. Anyone, PLEASE clean it up.
288 # For now, we pretend that there are two operating systems in the world;
289 # Darwin, and Everything Else. Furthermore, we pretend that Everything Else
290 # behaves like Linux.
292 ifeq "$(darwin_TARGET_OS)" "1"
293 # Darwin: Shared libraries end in .dylib
294 DYLD_LIBRARY = $(patsubst %.a,%_dyn.dylib,$(LIBRARY))
296 # About the options used for Darwin:
298 # Apple's way of saying -shared
299 # -flat_namespace -undefined suppress:
300 # Without these options, we'd have to specify the correct dependencies
301 # for each of the dylibs. Twolevel namespaces are in general a good thing
302 # (they make things more robust), so we should fix this sooner or later.
304 # Causes the dynamic linker to ignore the DYLD_LIBRARY_PATH when loading
305 # this lib and instead look for it at its absolute path.
306 # When installing the .dylibs (see target.mk), we'll change that path to
307 # point to the place they are installed.
308 # Note: I'm not yet sure about this, but I think it will be convenient for
309 # users not to have to set up DYLD_LIBRARY_PATH to point to the GHC
310 # library dir. -- Wolfgang
312 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
313 $(CC) -dynamiclib -o $@ $(STUBOBJS) $(LIBOBJS) -flat_namespace -undefined suppress -install_name `pwd`/$@
315 DYLD_LIBRARY = $(patsubst %.a,%_dyn.so,$(LIBRARY))
317 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
318 $(CC) -shared -o $@ $(STUBOBJS) $(LIBOBJS)
321 INSTALL_LIBS += $(DYLD_LIBRARY)
322 CLEAN_FILES += $(DYLD_LIBRARY)
324 all :: $(DYLD_LIBRARY)
329 # -----------------------------------------------------------------------------
330 # Doc building with Haddock
332 ifneq "$(NO_HADDOCK_DOCS)" "YES"
334 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS))))
337 HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
341 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
345 @echo Haddock must be installed in order to build HTML library documentation.
346 @echo Please install Haddock and re-configure.
353 $(RM) -rf $(HTML_DIR)
355 $(HTML_DOC) : $(HS_PPS)
356 @$(INSTALL_DIR) $(HTML_DIR)
357 $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
358 --package=$(PACKAGE) \
359 --dump-interface=$(PACKAGE).haddock \
360 --use-index=../doc-index.html --use-contents=../index.html \
361 $(foreach pkg, $(PACKAGE_DEPS), \
362 --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
364 CLEAN_FILES += $(PACKAGE).haddock
367 $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
370 $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
372 HTML_INSTALL_DIR = $(datadir)/html/libraries/$(PACKAGE)
373 # NOT the same as HTML_DIR_INSTALLED when BIN_DIST is on
375 install-docs :: $(HTML_DOC)
376 @$(INSTALL_DIR) $(HTML_INSTALL_DIR)
377 @for i in $(HTML_DIR)/*; do \
378 echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
379 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
381 $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(HTML_INSTALL_DIR)
384 endif # NO_HADDOCK_DOCS
386 # -----------------------------------------------------------------------------
388 endif # $(LIBRARY) /= ""
389 endif # $(PACKAGE) /= ""