Add several new record features
[ghc-hetmet.git] / mk / package.mk
1 # -----------------------------------------------------------------------------
2 # $Id: package.mk,v 1.55 2005/05/13 10:05:33 krasimir Exp $
3
4 ifneq "$(PACKAGE)" ""
5
6 # -----------------------------------------------------------------------------
7 # Directory layouts, installation etc.
8
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
11 # runtime.
12 #
13 # On Unix, we only use absolute paths in package.conf.
14 #
15
16 ifeq "$(Windows)" "YES"
17
18 PKG_LIBDIR  = $$topdir
19 PKG_DATADIR = $$topdir
20
21 else
22
23 PKG_LIBDIR  = $(libdir)
24 PKG_DATADIR = $(datadir)
25
26 endif # Unix
27
28 IMPORT_DIR_INSTALLED = $(PKG_LIBDIR)/imports
29 IMPORT_DIR_INPLACE   = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
30
31 INCLUDE_DIR_INSTALLED = $(PKG_LIBDIR)/include
32 INCLUDE_DIR_INPLACE   = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/include
33
34 LIB_DIR_INSTALLED    = $(PKG_LIBDIR)
35 LIB_DIR_INPLACE      = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
36
37 DATA_DIR_INSTALLED   = $(PKG_DATADIR)
38 DATA_DIR_INPLACE     = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
39
40 HTML_DIR_INPLACE     = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/html
41 HTML_DIR_INSTALLED   = $(PKG_DATADIR)/html/libraries/$(PACKAGE)
42
43 HADDOCK_IFACE_INPLACE   = $(HTML_DIR_INPLACE)/$(PACKAGE).haddock
44 HADDOCK_IFACE_INSTALLED = $(HTML_DIR_INSTALLED)/$(PACKAGE).haddock
45
46 # -----------------------------------------------------------------------------
47 # Build the package configuration file and tell the compiler about it.
48
49 # We want to build two versions of the package configuration: one for use
50 # in the 
51
52 ifeq "$(way)" ""
53
54 PACKAGE_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -Iinclude
55
56 PACKAGE_CPP_OPTS += -DPACKAGE=${PACKAGE}
57 PACKAGE_CPP_OPTS += -DVERSION=${VERSION}
58
59 PACKAGE_CPP_OPTS += -DPKG_LIBDIR='"$(PKG_LIBDIR)"'
60 PACKAGE_CPP_OPTS += -DPKG_DATADIR='"$(PKG_DATADIR)"'
61
62 package.conf.inplace   : package.conf.in
63         $(CPP) $(RAWCPP_FLAGS) -P \
64                 -DIMPORT_DIR='"$(IMPORT_DIR_INPLACE)"' \
65                 -DLIB_DIR='"$(LIB_DIR_INPLACE)"' \
66                 -DINCLUDE_DIR='"$(INCLUDE_DIR_INPLACE)"' \
67                 -DDATA_DIR='"$(DATA_DIR_INPLACE)"' \
68                 -DHTML_DIR='"$(HTML_DIR_INPLACE)"' \
69                 -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INPLACE)"' \
70                 -DFPTOOLS_TOP_ABS='"${FPTOOLS_TOP_ABS}"' \
71                 -x c $(PACKAGE_CPP_OPTS) $< | \
72         grep -v '^#pragma GCC' | \
73         sed -e 's/""//g' -e 's/:[       ]*,/: /g' >$@
74
75 install::
76         $(CPP) $(RAWCPP_FLAGS) -P -DINSTALLING \
77                -DIMPORT_DIR='"$(IMPORT_DIR_INSTALLED)"' \
78                -DLIB_DIR='"$(LIB_DIR_INSTALLED)"' \
79                -DINCLUDE_DIR='"$(INCLUDE_DIR_INSTALLED)"' \
80                -DDATA_DIR='"$(DATA_DIR_INSTALLED)"' \
81                -DHTML_DIR='"$(HTML_DIR_INSTALLED)"' \
82                -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INSTALLED)"' \
83                -I../includes \
84                -x c $(PACKAGE_CPP_OPTS) package.conf.in \
85             | grep -v '^#pragma GCC' \
86             | sed -e 's/""//g' -e 's/:[   ]*,/: /g' \
87             | $(bindir)/ghc-pkg update - --force
88
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
94 # second.
95 #
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.
99 #
100
101 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
102 CLEAN_FILES += $(STAMP_PKG_CONF)
103
104 ifneq "$(BootingFromHc)" "YES"
105 boot all :: $(STAMP_PKG_CONF)
106 endif
107
108 $(STAMP_PKG_CONF) : package.conf.inplace
109         $(GHC_PKG_INPLACE) update - --force-files <package.conf.inplace
110         @touch $(STAMP_PKG_CONF)
111
112 CLEAN_FILES += package.conf.inplace 
113
114 endif # $(way) == ""
115
116 # -----------------------------------------------------------------------------
117 # Building the static library libHS<pkg>.a
118
119 SRC_HSC2HS_OPTS += -I.
120
121 ifneq "$(NO_SET_HC)" "YES"
122 HC = $(GHC_INPLACE)
123 endif
124 IGNORE_PACKAGE_FLAG = -package-name  $(PACKAGE)-$(VERSION)
125
126 ifeq "$(NON_HS_PACKAGE)" ""
127 SRC_HC_OPTS     += $(IGNORE_PACKAGE_FLAG)
128 SRC_HC_OPTS     += $(GhcLibHcOpts)
129 SRC_HC_OPTS     += $(patsubst %, -package %, $(PACKAGE_DEPS))
130 endif
131
132 #       -fgenerics switches on generation of support code for 
133 #               derivable type classes.  This is now off by default,
134 #               but we switch it on for the libraries so that we generate
135 #               the code in case someone importing wants it.
136 ifeq "$(NON_HS_PACKAGE)" ""
137 SRC_HC_OPTS     += -fgenerics
138 endif
139
140 ifndef LIBRARY
141 LIBRARY         = libHS$(PACKAGE)$(_way).a
142 endif
143
144 ifeq "$(WAYS)" ""
145 WAYS = $(GhcLibWays)
146 endif
147
148 all :: $(LIBRARY)
149
150 # POSSIBLE alternative version using --make:
151 #
152 # lib : $(HS_SRCS)
153 #       $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
154
155 # $(LIBNAME) : lib
156 #       $(RM) $@
157 #       $(AR) $(AR_OPTS) $@ $(HS_OBJS)
158 #       $(RANLIB) $@
159
160 # %.o : %.hs
161 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
162 # %.o : %.lhs
163 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
164
165 # -----------------------------------------------------------------------------
166 # Installation; need to install .hi files as well as libraries
167
168 ifeq "$(DLLized)" "YES"
169 INSTALL_PROGS += $(DLL_NAME)
170 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
171 endif
172
173 # The interface files are put inside the $(libdir), since they
174 # might (potentially) be platform specific..
175
176 ifeq "$(HIERARCHICAL_LIB)" "YES"
177 ifacedir = $(libdir)/imports
178 else
179 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
180 endif
181
182 # If the lib consists of a hierachy of modules, we must retain the directory
183 # structure when we install the interfaces.
184 ifeq "$(HIERARCHICAL_LIB)" "YES"
185 INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
186 ifneq "$(ALL_DIRS)" ""
187 install ::
188         @for i in $(ALL_DIRS); do \
189                 $(INSTALL_DIR) $(ifacedir)/$$i; \
190         done
191 endif
192 else
193 INSTALL_IFACES += $(HS_IFACES)
194 endif
195
196 # -----------------------------------------------------------------------------
197 # Dependencies
198
199 MKDEPENDHS = $(GHC_INPLACE)
200
201 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
202 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
203
204 endif # $(PACKAGE) != ""
205
206 #--------------------------------------------------------------
207 # Installation
208
209 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
210 INSTALL_LIBS  += $(LIBRARY) $(GHCI_LIBRARY)
211 endif
212
213 #--------------------------------------------------------------
214 # Building dynamically-linkable libraries for GHCi
215 #
216 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
217 #
218 # Why?  GHCi can only link .o files (at the moment), not .a files
219 # so we have to build libFoo.o as well as libFoo.a
220 #
221 # Furthermore, GHCi currently never loads 
222 # profiling libraries (or other non-std ways)
223
224 ifneq "$(LIBRARY)" ""
225
226 ifeq "$(way)" ""
227 ifeq "$(GhcWithInterpreter)" "YES"
228
229 ifndef GHCI_LIBRARY
230 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
231 endif
232
233 CLEAN_FILES  += $(GHCI_LIBRARY)
234
235 all :: $(GHCI_LIBRARY)
236
237 ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
238 # If you don't want to build GHCI_LIBRARY the 'standard' way,
239 # set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
240 # hslibs/Win32 uses this 'feature', which will go away soon
241 # when we can use a "fixed" ld.
242 #
243 $(GHCI_LIBRARY) : $(LIBOBJS)
244         $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
245
246 endif # DONT_WANT_STD_GHCI_LIB_RULE
247 endif # GhcWithInterpreter
248 endif # way
249
250 ifeq "$(GhcBuildDylibs)" "YES"
251
252     # Build dynamic libraries.
253     # Currently, this is a hack. Anyone, PLEASE clean it up.
254
255     # For now, we pretend that there are two operating systems in the world;
256     # Darwin, and Everything Else. Furthermore, we pretend that Everything Else
257     # behaves like Linux.
258     
259 ifeq "$(darwin_TARGET_OS)" "1"
260     # Darwin: Shared libraries end in .dylib
261 DYLD_LIBRARY = $(patsubst %.a,%_dyn.dylib,$(LIBRARY))
262
263     # About the options used for Darwin:
264     # -dynamiclib
265     #   Apple's way of saying -shared
266     # -undefined dynamic_lookup:
267     #   Without these options, we'd have to specify the correct dependencies
268     #   for each of the dylibs. Note that we could (and should) do without this
269     #   for all libraries except the RTS; all we need to do is to pass the
270     #   correct HSfoo_dyn.dylib files to the link command.
271     #   This feature requires Mac OS X 10.3 or later; there is a similar feature,
272     #   -flat_namespace -undefined suppress, which works on earlier versions,
273     #   but it has other disadvantages.
274     # -single_module
275     #   Build the dynamic library as a single "module", i.e. no dynamic binding
276     #   nonsense when referring to symbols from within the library. The NCG
277     #   assumes that this option is specified (on i386, at least).
278     # -Wl,-macosx_version_min -Wl,10.3
279     #   Tell the linker its safe to assume that the library will run on 10.3 or
280     #   later, so that it will not complain about the use of the option
281     #   -undefined dynamic_lookup above.
282     # -install_name
283     #   Causes the dynamic linker to ignore the DYLD_LIBRARY_PATH when loading
284     #   this lib and instead look for it at its absolute path.
285     #   When installing the .dylibs (see target.mk), we'll change that path to
286     #   point to the place they are installed. Therefore, we won't have to set
287     #   up DYLD_LIBRARY_PATH specifically for ghc.
288
289 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
290         $(CC) -dynamiclib -o $@ $(STUBOBJS) $(LIBOBJS) \
291                 -undefined dynamic_lookup -single_module \
292                  -Wl,-macosx_version_min -Wl,10.3 \
293                 -install_name `pwd`/$@
294
295 else
296 DYLD_LIBRARY = $(patsubst %.a,%_dyn.so,$(LIBRARY))
297
298 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
299         $(CC) -shared -o $@ $(STUBOBJS) $(LIBOBJS)
300 endif
301
302 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
303 INSTALL_LIBS += $(DYLD_LIBRARY)
304 endif
305
306 CLEAN_FILES += $(DYLD_LIBRARY)
307
308 all :: $(DYLD_LIBRARY)
309
310 endif # $(GhcBuildDylibs) == "YES"
311
312 endif # $(LIBRARY) /= ""
313
314 # -----------------------------------------------------------------------------
315 # Doc building with Haddock
316
317 ifneq "$(PACKAGE)" ""
318 ifeq "$(HADDOCK_DOCS)" "YES"
319
320 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS)))) $(EXTRA_HADDOCK_SRCS)
321
322 HTML_DIR = ../html-docs/$(PACKAGE)
323 HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
324
325 ifneq "$(HS_PPS)" ""
326
327 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
328
329 ifeq "$(HADDOCK)" ""
330 html ::
331         @echo Haddock must be installed in order to build HTML library documentation.
332         @echo Please install Haddock and re-configure.
333         @exit 1
334 endif
335
336 html :: $(HTML_DOC)
337
338 extraclean :: 
339         $(RM) -rf $(HTML_DIR)
340
341 ifneq "$(findstring $(PACKAGE), $(CorePackages))" ""
342 HaddockSourceURL = $(CorePackageSourceURL)
343 else
344 HaddockSourceURL = $(ExtraPackageSourceURL)
345 endif
346
347 $(HTML_DOC) : $(HS_PPS)
348         @$(INSTALL_DIR) $(HTML_DIR)
349         $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
350                 --package=$(PACKAGE) \
351                 --dump-interface=$(PACKAGE).haddock \
352                 --use-index=../doc-index.html --use-contents=../index.html \
353                 --source-module=$(HaddockSourceURL) \
354                 $(foreach pkg, $(PACKAGE_DEPS), \
355                    --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
356
357 CLEAN_FILES += $(PACKAGE).haddock
358
359 %.raw-hs : %.lhs
360         $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
361
362 %.raw-hs : %.hs
363         $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
364
365 HTML_INSTALL_DIR = $(datadir)/html/libraries/$(PACKAGE)
366
367 install-docs :: $(HTML_DOC)
368         @$(INSTALL_DIR) $(HTML_INSTALL_DIR)
369         for i in $(HTML_DIR)/*; do \
370           echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
371           $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
372         done; \
373         $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(HTML_INSTALL_DIR); \
374
375 endif # HS_PPS
376 endif # HADDOCK_DOCS
377 endif # $(PACKAGE) /= ""
378
379 # -----------------------------------------------------------------------------
380