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_DATADIR = $$datadir
30 IMPORT_DIR_INSTALLED = $(PKG_LIBDIR)/imports
31 IMPORT_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
33 INCLUDE_DIR_INSTALLED = $(PKG_LIBDIR)/include
34 INCLUDE_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/include
36 LIB_DIR_INSTALLED = $(PKG_LIBDIR)
37 LIB_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
39 DATA_DIR_INSTALLED = $(PKG_DATADIR)
40 DATA_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
42 HTML_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/html
43 HTML_DIR_INSTALLED = $(PKG_DATADIR)/html/libraries/$(PACKAGE)
45 HADDOCK_IFACE_INPLACE = $(HTML_DIR_INPLACE)/$(PACKAGE).haddock
46 HADDOCK_IFACE_INSTALLED = $(HTML_DIR_INSTALLED)/$(PACKAGE).haddock
48 # -----------------------------------------------------------------------------
49 # Build the package configuration file and tell the compiler about it.
51 # We want to build two versions of the package configuration: one for use
56 PACKAGE_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -Iinclude
58 PACKAGE_CPP_OPTS += -DPACKAGE=${PACKAGE}
59 PACKAGE_CPP_OPTS += -DVERSION=${VERSION}
61 PACKAGE_CPP_OPTS += -DPKG_LIBDIR='"$(PKG_LIBDIR)"'
62 PACKAGE_CPP_OPTS += -DPKG_DATADIR='"$(PKG_DATADIR)"'
64 package.conf.inplace : package.conf.in
65 $(CPP) $(RAWCPP_FLAGS) -P \
66 -DIMPORT_DIR='"$(IMPORT_DIR_INPLACE)"' \
67 -DLIB_DIR='"$(LIB_DIR_INPLACE)"' \
68 -DINCLUDE_DIR='"$(INCLUDE_DIR_INPLACE)"' \
69 -DDATA_DIR='"$(DATA_DIR_INPLACE)"' \
70 -DHTML_DIR='"$(HTML_DIR_INPLACE)"' \
71 -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INPLACE)"' \
72 -DFPTOOLS_TOP_ABS='"${FPTOOLS_TOP_ABS}"' \
73 -x c $(PACKAGE_CPP_OPTS) $< | \
74 grep -v '^#pragma GCC' | \
75 sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$@
77 package.conf.installed : package.conf.in
78 $(CPP) $(RAWCPP_FLAGS) -P -DINSTALLING \
79 -DIMPORT_DIR='"$(IMPORT_DIR_INSTALLED)"' \
80 -DLIB_DIR='"$(LIB_DIR_INSTALLED)"' \
81 -DINCLUDE_DIR='"$(INCLUDE_DIR_INSTALLED)"' \
82 -DDATA_DIR='"$(DATA_DIR_INSTALLED)"' \
83 -DHTML_DIR='"$(HTML_DIR_INSTALLED)"' \
84 -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INSTALLED)"' \
85 -x c $(PACKAGE_CPP_OPTS) $< | \
86 grep -v '^#pragma GCC' | \
87 sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$@
89 # we could be more accurate here and add a dependency on
90 # driver/package.conf, but that doesn't work too well because of
91 # make's limited accuracy with modification times: when doing 'make
92 # boot' in multiple packages, make won't detect that the package
93 # configuration needs updating if it was updated already in the last
96 # The stamp file goes in $(GHC_DRIVER_DIR), so that if someone happens
97 # to 'make clean' in ghc without cleaning in libraries too, the packages
98 # will be correctly re-installed.
101 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
102 CLEAN_FILES += $(STAMP_PKG_CONF)
104 ifneq "$(BootingFromHc)" "YES"
105 boot all :: $(STAMP_PKG_CONF)
108 $(STAMP_PKG_CONF) : package.conf.inplace package.conf.installed
109 $(GHC_PKG_INPLACE) update - --force-files <package.conf.inplace
110 $(GHC_PKG_INPLACE) update - -f $(GHC_DRIVER_DIR)/package.conf --force-files <package.conf.installed
111 @touch $(STAMP_PKG_CONF)
113 CLEAN_FILES += package.conf.installed package.conf.inplace
117 # -----------------------------------------------------------------------------
118 # Building the static library libHS<pkg>.a
120 SRC_HSC2HS_OPTS += -I.
122 ifneq "$(NO_SET_HC)" "YES"
125 IGNORE_PACKAGE_FLAG = -package-name $(PACKAGE)-$(VERSION)
127 ifeq "$(NON_HS_PACKAGE)" ""
128 SRC_HC_OPTS += $(IGNORE_PACKAGE_FLAG)
129 SRC_HC_OPTS += $(GhcLibHcOpts)
130 SRC_HC_OPTS += $(patsubst %, -package %, $(PACKAGE_DEPS))
133 # -fgenerics switches on generation of support code for
134 # derivable type classes. This is now off by default,
135 # but we switch it on for the libraries so that we generate
136 # the code in case someone importing wants it.
137 ifeq "$(NON_HS_PACKAGE)" ""
138 SRC_HC_OPTS += -fgenerics
142 LIBRARY = libHS$(PACKAGE)$(_way).a
151 # POSSIBLE alternative version using --make:
154 # $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
158 # $(AR) $(AR_OPTS) $@ $(HS_OBJS)
162 # $(GHC_INPLACE) $(HC_OPTS) --make $<
164 # $(GHC_INPLACE) $(HC_OPTS) --make $<
166 # -----------------------------------------------------------------------------
167 # Installation; need to install .hi files as well as libraries
169 ifeq "$(DLLized)" "YES"
170 INSTALL_PROGS += $(DLL_NAME)
171 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
174 # The interface files are put inside the $(libdir), since they
175 # might (potentially) be platform specific..
177 ifeq "$(HIERARCHICAL_LIB)" "YES"
178 ifacedir = $(libdir)/imports
180 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
183 # If the lib consists of a hierachy of modules, we must retain the directory
184 # structure when we install the interfaces.
185 ifeq "$(HIERARCHICAL_LIB)" "YES"
186 INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
187 ifneq "$(ALL_DIRS)" ""
189 @for i in $(ALL_DIRS); do \
190 $(INSTALL_DIR) $(ifacedir)/$$i; \
194 INSTALL_IFACES += $(HS_IFACES)
197 # -----------------------------------------------------------------------------
200 MKDEPENDHS = $(GHC_INPLACE)
202 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
203 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
205 endif # $(PACKAGE) != ""
207 #--------------------------------------------------------------
210 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
211 INSTALL_LIBS += $(LIBRARY) $(GHCI_LIBRARY)
214 #--------------------------------------------------------------
215 # Building dynamically-linkable libraries for GHCi
217 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
219 # Why? GHCi can only link .o files (at the moment), not .a files
220 # so we have to build libFoo.o as well as libFoo.a
222 # Furthermore, GHCi currently never loads
223 # profiling libraries (or other non-std ways)
225 ifneq "$(LIBRARY)" ""
228 ifeq "$(GhcWithInterpreter)" "YES"
231 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
234 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
235 INSTALL_LIBS += $(GHCI_LIBRARY)
238 CLEAN_FILES += $(GHCI_LIBRARY)
240 all :: $(GHCI_LIBRARY)
242 ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
243 # If you don't want to build GHCI_LIBRARY the 'standard' way,
244 # set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
245 # hslibs/Win32 uses this 'feature', which will go away soon
246 # when we can use a "fixed" ld.
248 $(GHCI_LIBRARY) : $(LIBOBJS)
249 $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
251 endif # DONT_WANT_STD_GHCI_LIB_RULE
252 endif # GhcWithInterpreter
255 ifeq "$(GhcBuildDylibs)" "YES"
257 # Build dynamic libraries.
258 # Currently, this is a hack. Anyone, PLEASE clean it up.
260 # For now, we pretend that there are two operating systems in the world;
261 # Darwin, and Everything Else. Furthermore, we pretend that Everything Else
262 # behaves like Linux.
264 ifeq "$(darwin_TARGET_OS)" "1"
265 # Darwin: Shared libraries end in .dylib
266 DYLD_LIBRARY = $(patsubst %.a,%_dyn.dylib,$(LIBRARY))
268 # About the options used for Darwin:
270 # Apple's way of saying -shared
271 # -undefined dynamic_lookup:
272 # Without these options, we'd have to specify the correct dependencies
273 # for each of the dylibs. Note that we could (and should) do without this
274 # for all libraries except the RTS; all we need to do is to pass the
275 # correct HSfoo_dyn.dylib files to the link command.
276 # This feature requires Mac OS X 10.3 or later; there is a similar feature,
277 # -flat_namespace -undefined suppress, which works on earlier versions,
278 # but it has other disadvantages.
280 # Build the dynamic library as a single "module", i.e. no dynamic binding
281 # nonsense when referring to symbols from within the library. The NCG
282 # assumes that this option is specified (on i386, at least).
283 # -Wl,-macosx_version_min -Wl,10.3
284 # Tell the linker its safe to assume that the library will run on 10.3 or
285 # later, so that it will not complain about the use of the option
286 # -undefined dynamic_lookup above.
288 # Causes the dynamic linker to ignore the DYLD_LIBRARY_PATH when loading
289 # this lib and instead look for it at its absolute path.
290 # When installing the .dylibs (see target.mk), we'll change that path to
291 # point to the place they are installed. Therefore, we won't have to set
292 # up DYLD_LIBRARY_PATH specifically for ghc.
294 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
295 $(CC) -dynamiclib -o $@ $(STUBOBJS) $(LIBOBJS) \
296 -undefined dynamic_lookup -single_module \
297 -Wl,-macosx_version_min -Wl,10.3 \
298 -install_name `pwd`/$@
301 DYLD_LIBRARY = $(patsubst %.a,%_dyn.so,$(LIBRARY))
303 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
304 $(CC) -shared -o $@ $(STUBOBJS) $(LIBOBJS)
307 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
308 INSTALL_LIBS += $(DYLD_LIBRARY)
311 CLEAN_FILES += $(DYLD_LIBRARY)
313 all :: $(DYLD_LIBRARY)
315 endif # $(GhcBuildDylibs) == "YES"
317 endif # $(LIBRARY) /= ""
319 # -----------------------------------------------------------------------------
320 # Doc building with Haddock
322 ifneq "$(PACKAGE)" ""
323 ifneq "$(NO_HADDOCK_DOCS)" "YES"
325 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS)))) $(EXTRA_HADDOCK_SRCS)
327 HTML_DIR = ../html-docs/$(PACKAGE)
328 HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
332 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
336 @echo Haddock must be installed in order to build HTML library documentation.
337 @echo Please install Haddock and re-configure.
344 $(RM) -rf $(HTML_DIR)
346 ifneq "$(findstring $(PACKAGE), $(CorePackages))" ""
347 HaddockSourceURL = $(CorePackageSourceURL)
349 HaddockSourceURL = $(ExtraPackageSourceURL)
352 $(HTML_DOC) : $(HS_PPS)
353 @$(INSTALL_DIR) $(HTML_DIR)
354 $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
355 --package=$(PACKAGE) \
356 --dump-interface=$(PACKAGE).haddock \
357 --use-index=../doc-index.html --use-contents=../index.html \
358 --source-module=$(HaddockSourceURL) \
359 $(foreach pkg, $(PACKAGE_DEPS), \
360 --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
362 CLEAN_FILES += $(PACKAGE).haddock
365 $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
368 $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
370 HTML_INSTALL_DIR = $(datadir)/html/libraries/$(PACKAGE)
372 install-docs :: $(HTML_DOC)
373 @$(INSTALL_DIR) $(HTML_INSTALL_DIR)
374 for i in $(HTML_DIR)/*; do \
375 echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
376 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
378 $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(HTML_INSTALL_DIR); \
381 endif # NO_HADDOCK_DOCS
382 endif # $(PACKAGE) /= ""
384 # -----------------------------------------------------------------------------