1 # -----------------------------------------------------------------------------
2 # $Id: package.mk,v 1.55 2005/05/13 10:05:33 krasimir Exp $
6 # FIXME: does anyone do this any more?
7 STANDALONE_PACKAGE = NO
9 # -----------------------------------------------------------------------------
10 # Directory layouts, installation etc.
12 # Here Windows & Unix differ. On Windows, the value of $(prefix) is known
13 # to the compiler, and spliced into package.conf in place of $topdir at
16 # On Unix, we only use absolute paths in package.conf, except that when
17 # building a binary distribution we use $libdir and $datadir in package.conf
18 # which are then replaced by the correct values at install time.
21 ifeq "$(Windows)" "YES"
24 PKG_DATADIR = $$topdir
29 PKG_LIBDIR = $(libdir)
30 PKG_DATADIR = $(datadir)
33 PKG_DATADIR = $$datadir
38 IMPORT_DIR_INSTALLED = $(PKG_LIBDIR)/imports
39 IMPORT_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
41 INCLUDE_DIR_INSTALLED = $(PKG_LIBDIR)/include
42 INCLUDE_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/include
44 LIB_DIR_INSTALLED = $(PKG_LIBDIR)
45 LIB_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
47 DATA_DIR_INSTALLED = $(PKG_DATADIR)
48 DATA_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
50 HTML_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/html
51 HTML_DIR_INSTALLED = $(PKG_DATADIR)/html/libraries/$(PACKAGE)
53 HADDOCK_IFACE_INPLACE = $(HTML_DIR_INPLACE)/$(PACKAGE).haddock
54 HADDOCK_IFACE_INSTALLED = $(HTML_DIR_INSTALLED)/$(PACKAGE).haddock
56 # -----------------------------------------------------------------------------
57 # Build the package configuration file and tell the compiler about it.
59 # We want to build two versions of the package configuration: one for use
64 ifeq "$(STANDALONE_PACKAGE)" "NO"
65 PACKAGE_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -Iinclude
67 PACKAGE_CPP_OPTS += -Iinclude
70 PACKAGE_CPP_OPTS += -DPACKAGE=${PACKAGE}
71 PACKAGE_CPP_OPTS += -DVERSION=${VERSION}
73 PACKAGE_CPP_OPTS += -DPKG_LIBDIR='"$(PKG_LIBDIR)"'
74 PACKAGE_CPP_OPTS += -DPKG_DATADIR='"$(PKG_DATADIR)"'
76 package.conf.inplace : package.conf.in
77 $(CPP) $(RAWCPP_FLAGS) -P \
78 -DIMPORT_DIR='"$(IMPORT_DIR_INPLACE)"' \
79 -DLIB_DIR='"$(LIB_DIR_INPLACE)"' \
80 -DINCLUDE_DIR='"$(INCLUDE_DIR_INPLACE)"' \
81 -DDATA_DIR='"$(DATA_DIR_INPLACE)"' \
82 -DHTML_DIR='"$(HTML_DIR_INPLACE)"' \
83 -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INPLACE)"' \
84 -DFPTOOLS_TOP_ABS='"${FPTOOLS_TOP_ABS}"' \
85 -x c $(PACKAGE_CPP_OPTS) $< | \
86 grep -v '^#pragma GCC' | \
87 sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$@
89 package.conf.installed : package.conf.in
90 $(CPP) $(RAWCPP_FLAGS) -P -DINSTALLING \
91 -DIMPORT_DIR='"$(IMPORT_DIR_INSTALLED)"' \
92 -DLIB_DIR='"$(LIB_DIR_INSTALLED)"' \
93 -DINCLUDE_DIR='"$(INCLUDE_DIR_INSTALLED)"' \
94 -DDATA_DIR='"$(DATA_DIR_INSTALLED)"' \
95 -DHTML_DIR='"$(HTML_DIR_INSTALLED)"' \
96 -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INSTALLED)"' \
97 -x c $(PACKAGE_CPP_OPTS) $< | \
98 grep -v '^#pragma GCC' | \
99 sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$@
101 # we could be more accurate here and add a dependency on
102 # driver/package.conf, but that doesn't work too well because of
103 # make's limited accuracy with modification times: when doing 'make
104 # boot' in multiple packages, make won't detect that the package
105 # configuration needs updating if it was updated already in the last
108 # The stamp file goes in $(GHC_DRIVER_DIR), so that if someone happens
109 # to 'make clean' in ghc without cleaning in libraries too, the packages
110 # will be correctly re-installed.
112 ifeq "$(STANDALONE_PACKAGE)" "NO"
114 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
115 CLEAN_FILES += $(STAMP_PKG_CONF)
117 ifneq "$(BootingFromHc)" "YES"
118 boot all :: $(STAMP_PKG_CONF)
121 $(STAMP_PKG_CONF) : package.conf.inplace package.conf.installed
122 $(GHC_PKG_INPLACE) --force --update-package <package.conf.inplace
123 $(GHC_PKG_INPLACE) -f $(GHC_DRIVER_DIR)/package.conf --force --update-package <package.conf.installed
124 @touch $(STAMP_PKG_CONF)
126 CLEAN_FILES += package.conf.installed package.conf.inplace
128 else # $(STANDALONE_PACKAGE) == "YES"
130 PACKAGE_CPP_OPTS += -DPACKAGE_DEPS='$(subst " ","$(comma) ",$(patsubst %,"%",$(PACKAGE_DEPS)))'
131 PACKAGE_CPP_OPTS += -DLIBRARY=\"HS$(PACKAGE)\"
132 PACKAGE_CPP_OPTS += -DLIBDIR=\"$(libdir)\"
134 # Let the package configuration file refer to $(libdir) as
135 # ${pkglibdir}. Note we can't use ${libdir} because ghc-pkg already
136 # redefines it to point to GHC's libdir (bug or feature?).
138 install :: package.conf.installed
139 $(GHC_PKG) --force --update-package <package.conf.installed
141 # Invoke this rule by hand in order to use the package in-place
142 install-inplace-pkg : package.conf.inplace
143 $(GHC_PKG) --force --update-package <package.conf.inplace
145 endif # $(STANDALONE_PACKAGE)
149 # -----------------------------------------------------------------------------
150 # Building the static library libHS<pkg>.a
152 SRC_HSC2HS_OPTS += -I.
154 ifeq "$(STANDALONE_PACKAGE)" "NO"
156 IGNORE_PACKAGE_FLAG = -package-name $(PACKAGE)-$(VERSION)
158 # Only use -ignore-package if supported by HC; i.e., ghc-6.3 and later.
159 # (Don't like the use of slow $(shell ..) in Makefiles, but can't see a way around it here.)
160 ifeq "$(strip $(GHC))" ""
161 IGNORE_PACKAGE_FLAG = -ignore-package $(PACKAGE)
163 # Making the assumption here that standalone packages will be using mk/config.mk:GHC
164 IGNORE_PACKAGE_FLAG = $(shell if (test $(GhcCanonVersion) -ge 603); then echo "-ignore-package"; else echo "-package-name"; fi) $(PACKAGE)
166 endif # STANDALONE_PACKAGE
168 ifeq "$(NON_HS_PACKAGE)" ""
169 SRC_HC_OPTS += $(IGNORE_PACKAGE_FLAG)
170 SRC_HC_OPTS += $(GhcLibHcOpts)
171 SRC_HC_OPTS += $(patsubst %, -package %, $(PACKAGE_DEPS))
174 # -fgenerics switches on generation of support code for
175 # derivable type classes. This is now off by default,
176 # but we switch it on for the libraries so that we generate
177 # the code in case someone importing wants it.
178 ifeq "$(NON_HS_PACKAGE)" ""
179 SRC_HC_OPTS += -fgenerics
183 LIBRARY = libHS$(PACKAGE)$(_way).a
192 # POSSIBLE alternative version using --make:
195 # $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
199 # $(AR) $(AR_OPTS) $@ $(HS_OBJS)
203 # $(GHC_INPLACE) $(HC_OPTS) --make $<
205 # $(GHC_INPLACE) $(HC_OPTS) --make $<
207 # -----------------------------------------------------------------------------
208 # Installation; need to install .hi files as well as libraries
210 ifeq "$(DLLized)" "YES"
211 INSTALL_PROGS += $(DLL_NAME)
212 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
215 # The interface files are put inside the $(libdir), since they
216 # might (potentially) be platform specific..
218 ifeq "$(HIERARCHICAL_LIB)" "YES"
219 ifacedir = $(libdir)/imports
221 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
224 # If the lib consists of a hierachy of modules, we must retain the directory
225 # structure when we install the interfaces.
226 ifeq "$(HIERARCHICAL_LIB)" "YES"
227 INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
228 ifneq "$(ALL_DIRS)" ""
230 @for i in $(ALL_DIRS); do \
231 $(INSTALL_DIR) $(ifacedir)/$$i; \
235 INSTALL_IFACES += $(HS_IFACES)
238 # -----------------------------------------------------------------------------
241 ifeq "$(STANDALONE_PACKAGE)" "NO"
242 MKDEPENDHS = $(GHC_INPLACE)
245 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
247 ifeq "$(STANDALONE_PACKAGE)" "NO"
248 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
251 endif # $(PACKAGE) != ""
253 #--------------------------------------------------------------
256 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
257 INSTALL_LIBS += $(LIBRARY) $(GHCI_LIBRARY)
260 #--------------------------------------------------------------
261 # Building dynamically-linkable libraries for GHCi
263 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
265 # Why? GHCi can only link .o files (at the moment), not .a files
266 # so we have to build libFoo.o as well as libFoo.a
268 # Furthermore, GHCi currently never loads
269 # profiling libraries (or other non-std ways)
271 ifneq "$(LIBRARY)" ""
274 ifeq "$(GhcWithInterpreter)" "YES"
277 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
280 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
281 INSTALL_LIBS += $(GHCI_LIBRARY)
284 CLEAN_FILES += $(GHCI_LIBRARY)
286 all :: $(GHCI_LIBRARY)
288 ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
289 # If you don't want to build GHCI_LIBRARY the 'standard' way,
290 # set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
291 # hslibs/Win32 uses this 'feature', which will go away soon
292 # when we can use a "fixed" ld.
294 $(GHCI_LIBRARY) : $(LIBOBJS)
295 $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
297 endif # DONT_WANT_STD_GHCI_LIB_RULE
298 endif # GhcWithInterpreter
301 ifeq "$(GhcBuildDylibs)" "YES"
303 # Build dynamic libraries.
304 # Currently, this is a hack. Anyone, PLEASE clean it up.
306 # For now, we pretend that there are two operating systems in the world;
307 # Darwin, and Everything Else. Furthermore, we pretend that Everything Else
308 # behaves like Linux.
310 ifeq "$(darwin_TARGET_OS)" "1"
311 # Darwin: Shared libraries end in .dylib
312 DYLD_LIBRARY = $(patsubst %.a,%_dyn.dylib,$(LIBRARY))
314 # About the options used for Darwin:
316 # Apple's way of saying -shared
317 # -flat_namespace -undefined suppress:
318 # Without these options, we'd have to specify the correct dependencies
319 # for each of the dylibs. Twolevel namespaces are in general a good thing
320 # (they make things more robust), so we should fix this sooner or later.
322 # Causes the dynamic linker to ignore the DYLD_LIBRARY_PATH when loading
323 # this lib and instead look for it at its absolute path.
324 # When installing the .dylibs (see target.mk), we'll change that path to
325 # point to the place they are installed.
326 # Note: I'm not yet sure about this, but I think it will be convenient for
327 # users not to have to set up DYLD_LIBRARY_PATH to point to the GHC
328 # library dir. -- Wolfgang
330 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
331 $(CC) -dynamiclib -o $@ $(STUBOBJS) $(LIBOBJS) -flat_namespace -undefined suppress -install_name `pwd`/$@
333 DYLD_LIBRARY = $(patsubst %.a,%_dyn.so,$(LIBRARY))
335 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
336 $(CC) -shared -o $@ $(STUBOBJS) $(LIBOBJS)
339 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
340 INSTALL_LIBS += $(DYLD_LIBRARY)
343 CLEAN_FILES += $(DYLD_LIBRARY)
345 all :: $(DYLD_LIBRARY)
347 endif # $(GhcBuildDylibs) == "YES"
349 endif # $(LIBRARY) /= ""
351 # -----------------------------------------------------------------------------
352 # Doc building with Haddock
354 ifneq "$(PACKAGE)" ""
355 ifneq "$(NO_HADDOCK_DOCS)" "YES"
357 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS)))) $(EXTRA_HADDOCK_SRCS)
359 HTML_DIR = ../html/$(PACKAGE)
360 HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
364 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
368 @echo Haddock must be installed in order to build HTML library documentation.
369 @echo Please install Haddock and re-configure.
376 $(RM) -rf $(HTML_DIR)
378 $(HTML_DOC) : $(HS_PPS)
379 @$(INSTALL_DIR) $(HTML_DIR)
380 $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
381 --package=$(PACKAGE) \
382 --dump-interface=$(PACKAGE).haddock \
383 --use-index=../doc-index.html --use-contents=../index.html \
384 $(foreach pkg, $(PACKAGE_DEPS), \
385 --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
387 CLEAN_FILES += $(PACKAGE).haddock
390 $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
393 $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
395 HTML_INSTALL_DIR = $(datadir)/html/libraries/$(PACKAGE)
396 # NOT the same as HTML_DIR_INSTALLED when BIN_DIST is on
398 install-docs :: $(HTML_DOC)
399 @$(INSTALL_DIR) $(HTML_INSTALL_DIR)
400 for i in $(HTML_DIR)/*; do \
401 echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
402 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
404 $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(HTML_INSTALL_DIR); \
407 endif # NO_HADDOCK_DOCS
408 endif # $(PACKAGE) /= ""
410 # -----------------------------------------------------------------------------