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, except that when
14 # building a binary distribution we use $libdir and $datadir in package.conf
15 # which are then replaced by the correct values at install time.
18 ifeq "$(Windows)" "YES"
21 PKG_DATADIR = $$topdir
26 PKG_LIBDIR = $(libdir)
27 PKG_DATADIR = $(datadir)
30 PKG_DATADIR = $$datadir
35 IMPORT_DIR_INSTALLED = $(PKG_LIBDIR)/imports
36 IMPORT_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
38 INCLUDE_DIR_INSTALLED = $(PKG_LIBDIR)/include
39 INCLUDE_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/include
41 LIB_DIR_INSTALLED = $(PKG_LIBDIR)
42 LIB_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
44 DATA_DIR_INSTALLED = $(PKG_DATADIR)
45 DATA_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
47 HTML_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/html
48 HTML_DIR_INSTALLED = $(PKG_DATADIR)/html/libraries/$(PACKAGE)
50 HADDOCK_IFACE_INPLACE = $(HTML_DIR_INPLACE)/$(PACKAGE).haddock
51 HADDOCK_IFACE_INSTALLED = $(HTML_DIR_INSTALLED)/$(PACKAGE).haddock
53 # -----------------------------------------------------------------------------
54 # Build the package configuration file and tell the compiler about it.
56 # We want to build two versions of the package configuration: one for use
61 PACKAGE_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -Iinclude
63 PACKAGE_CPP_OPTS += -DPACKAGE=${PACKAGE}
64 PACKAGE_CPP_OPTS += -DVERSION=${VERSION}
66 PACKAGE_CPP_OPTS += -DPKG_LIBDIR='"$(PKG_LIBDIR)"'
67 PACKAGE_CPP_OPTS += -DPKG_DATADIR='"$(PKG_DATADIR)"'
69 package.conf.inplace : package.conf.in
70 $(CPP) $(RAWCPP_FLAGS) -P \
71 -DIMPORT_DIR='"$(IMPORT_DIR_INPLACE)"' \
72 -DLIB_DIR='"$(LIB_DIR_INPLACE)"' \
73 -DINCLUDE_DIR='"$(INCLUDE_DIR_INPLACE)"' \
74 -DDATA_DIR='"$(DATA_DIR_INPLACE)"' \
75 -DHTML_DIR='"$(HTML_DIR_INPLACE)"' \
76 -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INPLACE)"' \
77 -DFPTOOLS_TOP_ABS='"${FPTOOLS_TOP_ABS}"' \
78 -x c $(PACKAGE_CPP_OPTS) $< | \
79 grep -v '^#pragma GCC' | \
80 sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$@
82 package.conf.installed : package.conf.in
83 $(CPP) $(RAWCPP_FLAGS) -P -DINSTALLING \
84 -DIMPORT_DIR='"$(IMPORT_DIR_INSTALLED)"' \
85 -DLIB_DIR='"$(LIB_DIR_INSTALLED)"' \
86 -DINCLUDE_DIR='"$(INCLUDE_DIR_INSTALLED)"' \
87 -DDATA_DIR='"$(DATA_DIR_INSTALLED)"' \
88 -DHTML_DIR='"$(HTML_DIR_INSTALLED)"' \
89 -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INSTALLED)"' \
90 -x c $(PACKAGE_CPP_OPTS) $< | \
91 grep -v '^#pragma GCC' | \
92 sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$@
94 # we could be more accurate here and add a dependency on
95 # driver/package.conf, but that doesn't work too well because of
96 # make's limited accuracy with modification times: when doing 'make
97 # boot' in multiple packages, make won't detect that the package
98 # configuration needs updating if it was updated already in the last
101 # The stamp file goes in $(GHC_DRIVER_DIR), so that if someone happens
102 # to 'make clean' in ghc without cleaning in libraries too, the packages
103 # will be correctly re-installed.
106 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
107 CLEAN_FILES += $(STAMP_PKG_CONF)
109 ifneq "$(BootingFromHc)" "YES"
110 boot all :: $(STAMP_PKG_CONF)
113 $(STAMP_PKG_CONF) : package.conf.inplace package.conf.installed
114 $(GHC_PKG_INPLACE) update - --force-files <package.conf.inplace
115 $(GHC_PKG_INPLACE) update - -f $(GHC_DRIVER_DIR)/package.conf --force-files <package.conf.installed
116 @touch $(STAMP_PKG_CONF)
118 CLEAN_FILES += package.conf.installed package.conf.inplace
120 else # $(STANDALONE_PACKAGE) == "YES"
122 PACKAGE_CPP_OPTS += -DPACKAGE_DEPS='$(subst " ","$(comma) ",$(patsubst %,"%",$(PACKAGE_DEPS)))'
123 PACKAGE_CPP_OPTS += -DLIBRARY=\"HS$(PACKAGE)\"
124 PACKAGE_CPP_OPTS += -DLIBDIR=\"$(libdir)\"
126 # Let the package configuration file refer to $(libdir) as
127 # ${pkglibdir}. Note we can't use ${libdir} because ghc-pkg already
128 # redefines it to point to GHC's libdir (bug or feature?).
130 install :: package.conf.installed
131 $(GHC_PKG) --force --update-package <package.conf.installed
133 # Invoke this rule by hand in order to use the package in-place
134 install-inplace-pkg : package.conf.inplace
135 $(GHC_PKG) --force --update-package <package.conf.inplace
139 # -----------------------------------------------------------------------------
140 # Building the static library libHS<pkg>.a
142 SRC_HSC2HS_OPTS += -I.
145 IGNORE_PACKAGE_FLAG = -package-name $(PACKAGE)-$(VERSION)
147 ifeq "$(NON_HS_PACKAGE)" ""
148 SRC_HC_OPTS += $(IGNORE_PACKAGE_FLAG)
149 SRC_HC_OPTS += $(GhcLibHcOpts)
150 SRC_HC_OPTS += $(patsubst %, -package %, $(PACKAGE_DEPS))
153 # -fgenerics switches on generation of support code for
154 # derivable type classes. This is now off by default,
155 # but we switch it on for the libraries so that we generate
156 # the code in case someone importing wants it.
157 ifeq "$(NON_HS_PACKAGE)" ""
158 SRC_HC_OPTS += -fgenerics
162 LIBRARY = libHS$(PACKAGE)$(_way).a
171 # POSSIBLE alternative version using --make:
174 # $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
178 # $(AR) $(AR_OPTS) $@ $(HS_OBJS)
182 # $(GHC_INPLACE) $(HC_OPTS) --make $<
184 # $(GHC_INPLACE) $(HC_OPTS) --make $<
186 # -----------------------------------------------------------------------------
187 # Installation; need to install .hi files as well as libraries
189 ifeq "$(DLLized)" "YES"
190 INSTALL_PROGS += $(DLL_NAME)
191 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
194 # The interface files are put inside the $(libdir), since they
195 # might (potentially) be platform specific..
197 ifeq "$(HIERARCHICAL_LIB)" "YES"
198 ifacedir = $(libdir)/imports
200 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
203 # If the lib consists of a hierachy of modules, we must retain the directory
204 # structure when we install the interfaces.
205 ifeq "$(HIERARCHICAL_LIB)" "YES"
206 INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
207 ifneq "$(ALL_DIRS)" ""
209 @for i in $(ALL_DIRS); do \
210 $(INSTALL_DIR) $(ifacedir)/$$i; \
214 INSTALL_IFACES += $(HS_IFACES)
217 # -----------------------------------------------------------------------------
220 MKDEPENDHS = $(GHC_INPLACE)
222 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
223 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
225 endif # $(PACKAGE) != ""
227 #--------------------------------------------------------------
230 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
231 INSTALL_LIBS += $(LIBRARY) $(GHCI_LIBRARY)
234 #--------------------------------------------------------------
235 # Building dynamically-linkable libraries for GHCi
237 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
239 # Why? GHCi can only link .o files (at the moment), not .a files
240 # so we have to build libFoo.o as well as libFoo.a
242 # Furthermore, GHCi currently never loads
243 # profiling libraries (or other non-std ways)
245 ifneq "$(LIBRARY)" ""
248 ifeq "$(GhcWithInterpreter)" "YES"
251 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
254 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
255 INSTALL_LIBS += $(GHCI_LIBRARY)
258 CLEAN_FILES += $(GHCI_LIBRARY)
260 all :: $(GHCI_LIBRARY)
262 ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
263 # If you don't want to build GHCI_LIBRARY the 'standard' way,
264 # set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
265 # hslibs/Win32 uses this 'feature', which will go away soon
266 # when we can use a "fixed" ld.
268 $(GHCI_LIBRARY) : $(LIBOBJS)
269 $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
271 endif # DONT_WANT_STD_GHCI_LIB_RULE
272 endif # GhcWithInterpreter
275 ifeq "$(GhcBuildDylibs)" "YES"
277 # Build dynamic libraries.
278 # Currently, this is a hack. Anyone, PLEASE clean it up.
280 # For now, we pretend that there are two operating systems in the world;
281 # Darwin, and Everything Else. Furthermore, we pretend that Everything Else
282 # behaves like Linux.
284 ifeq "$(darwin_TARGET_OS)" "1"
285 # Darwin: Shared libraries end in .dylib
286 DYLD_LIBRARY = $(patsubst %.a,%_dyn.dylib,$(LIBRARY))
288 # About the options used for Darwin:
290 # Apple's way of saying -shared
291 # -flat_namespace -undefined suppress:
292 # Without these options, we'd have to specify the correct dependencies
293 # for each of the dylibs. Twolevel namespaces are in general a good thing
294 # (they make things more robust), so we should fix this sooner or later.
296 # Causes the dynamic linker to ignore the DYLD_LIBRARY_PATH when loading
297 # this lib and instead look for it at its absolute path.
298 # When installing the .dylibs (see target.mk), we'll change that path to
299 # point to the place they are installed.
300 # Note: I'm not yet sure about this, but I think it will be convenient for
301 # users not to have to set up DYLD_LIBRARY_PATH to point to the GHC
302 # library dir. -- Wolfgang
304 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
305 $(CC) -dynamiclib -o $@ $(STUBOBJS) $(LIBOBJS) -flat_namespace -undefined suppress -install_name `pwd`/$@
307 DYLD_LIBRARY = $(patsubst %.a,%_dyn.so,$(LIBRARY))
309 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
310 $(CC) -shared -o $@ $(STUBOBJS) $(LIBOBJS)
313 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
314 INSTALL_LIBS += $(DYLD_LIBRARY)
317 CLEAN_FILES += $(DYLD_LIBRARY)
319 all :: $(DYLD_LIBRARY)
321 endif # $(GhcBuildDylibs) == "YES"
323 endif # $(LIBRARY) /= ""
325 # -----------------------------------------------------------------------------
326 # Doc building with Haddock
328 ifneq "$(PACKAGE)" ""
329 ifneq "$(NO_HADDOCK_DOCS)" "YES"
331 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS)))) $(EXTRA_HADDOCK_SRCS)
333 HTML_DIR = ../html-docs/$(PACKAGE)
334 HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
338 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
342 @echo Haddock must be installed in order to build HTML library documentation.
343 @echo Please install Haddock and re-configure.
350 $(RM) -rf $(HTML_DIR)
352 ifneq "$(findstring $(PACKAGE), $(CorePackages))" ""
353 HaddockSourceURL = $(CorePackageSourceURL)
355 HaddockSourceURL = $(ExtraPackageSourceURL)
358 $(HTML_DOC) : $(HS_PPS)
359 @$(INSTALL_DIR) $(HTML_DIR)
360 $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
361 --package=$(PACKAGE) \
362 --dump-interface=$(PACKAGE).haddock \
363 --use-index=../doc-index.html --use-contents=../index.html \
364 --source-module=$(HaddockSourceURL) \
365 $(foreach pkg, $(PACKAGE_DEPS), \
366 --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
368 CLEAN_FILES += $(PACKAGE).haddock
371 $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
374 $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
376 HTML_INSTALL_DIR = $(datadir)/html/libraries/$(PACKAGE)
377 # NOT the same as HTML_DIR_INSTALLED when BIN_DIST is on
379 install-docs :: $(HTML_DOC)
380 @$(INSTALL_DIR) $(HTML_INSTALL_DIR)
381 for i in $(HTML_DIR)/*; do \
382 echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
383 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
385 $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(HTML_INSTALL_DIR); \
388 endif # NO_HADDOCK_DOCS
389 endif # $(PACKAGE) /= ""
391 # -----------------------------------------------------------------------------