Fix scoped type variables for expression type signatures
[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 # FIXME: does anyone do this any more?
7 STANDALONE_PACKAGE = NO
8
9 # -----------------------------------------------------------------------------
10 # Directory layouts, installation etc.
11
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
14 # runtime.
15 #
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.
19 #
20
21 ifeq "$(Windows)" "YES"
22
23 PKG_LIBDIR  = $$topdir
24 PKG_DATADIR = $$topdir
25
26 else
27
28 ifeq "$(BIN_DIST)" ""
29 PKG_LIBDIR  = $(libdir)
30 PKG_DATADIR = $(datadir)
31 else
32 PKG_LIBDIR  = $$libdir
33 PKG_DATADIR = $$datadir
34 endif
35
36 endif # Unix
37
38 IMPORT_DIR_INSTALLED = $(PKG_LIBDIR)/imports
39 IMPORT_DIR_INPLACE   = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
40
41 INCLUDE_DIR_INSTALLED = $(PKG_LIBDIR)/include
42 INCLUDE_DIR_INPLACE   = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/include
43
44 LIB_DIR_INSTALLED    = $(PKG_LIBDIR)
45 LIB_DIR_INPLACE      = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
46
47 DATA_DIR_INSTALLED   = $(PKG_DATADIR)
48 DATA_DIR_INPLACE     = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
49
50 HTML_DIR_INPLACE     = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/html
51 HTML_DIR_INSTALLED   = $(PKG_DATADIR)/html/libraries/$(PACKAGE)
52
53 HADDOCK_IFACE_INPLACE   = $(HTML_DIR_INPLACE)/$(PACKAGE).haddock
54 HADDOCK_IFACE_INSTALLED = $(HTML_DIR_INSTALLED)/$(PACKAGE).haddock
55
56 # -----------------------------------------------------------------------------
57 # Build the package configuration file and tell the compiler about it.
58
59 # We want to build two versions of the package configuration: one for use
60 # in the 
61
62 ifeq "$(way)" ""
63
64 ifeq "$(STANDALONE_PACKAGE)" "NO"
65 PACKAGE_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -Iinclude
66 else
67 PACKAGE_CPP_OPTS += -Iinclude
68 endif
69
70 PACKAGE_CPP_OPTS += -DPACKAGE=${PACKAGE}
71 PACKAGE_CPP_OPTS += -DVERSION=${VERSION}
72
73 PACKAGE_CPP_OPTS += -DPKG_LIBDIR='"$(PKG_LIBDIR)"'
74 PACKAGE_CPP_OPTS += -DPKG_DATADIR='"$(PKG_DATADIR)"'
75
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' >$@
88
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' >$@
100
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
106 # second.
107 #
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.
111 #
112 ifeq "$(STANDALONE_PACKAGE)" "NO"
113
114 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
115 CLEAN_FILES += $(STAMP_PKG_CONF)
116
117 ifneq "$(BootingFromHc)" "YES"
118 boot all :: $(STAMP_PKG_CONF)
119 endif
120
121 $(STAMP_PKG_CONF) : package.conf.inplace package.conf.installed
122         $(GHC_PKG_INPLACE) update - --force-files <package.conf.inplace
123         $(GHC_PKG_INPLACE) update - -f $(GHC_DRIVER_DIR)/package.conf --force-files <package.conf.installed
124         @touch $(STAMP_PKG_CONF)
125
126 CLEAN_FILES += package.conf.installed package.conf.inplace 
127
128 else # $(STANDALONE_PACKAGE) == "YES"
129
130 PACKAGE_CPP_OPTS += -DPACKAGE_DEPS='$(subst " ","$(comma) ",$(patsubst %,"%",$(PACKAGE_DEPS)))'
131 PACKAGE_CPP_OPTS += -DLIBRARY=\"HS$(PACKAGE)\"
132 PACKAGE_CPP_OPTS += -DLIBDIR=\"$(libdir)\"
133
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?).
137 #
138 install :: package.conf.installed
139         $(GHC_PKG) --force --update-package <package.conf.installed
140
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
144
145 endif # $(STANDALONE_PACKAGE)
146
147 endif # $(way) == ""
148
149 # -----------------------------------------------------------------------------
150 # Building the static library libHS<pkg>.a
151
152 SRC_HSC2HS_OPTS += -I.
153
154 ifeq "$(STANDALONE_PACKAGE)" "NO"
155 HC = $(GHC_INPLACE)
156 IGNORE_PACKAGE_FLAG = -package-name  $(PACKAGE)-$(VERSION)
157 else
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)
162 else
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)
165 endif 
166 endif # STANDALONE_PACKAGE
167
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))
172 endif
173
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
180 endif
181
182 ifndef LIBRARY
183 LIBRARY         = libHS$(PACKAGE)$(_way).a
184 endif
185
186 ifeq "$(WAYS)" ""
187 WAYS = $(GhcLibWays)
188 endif
189
190 all :: $(LIBRARY)
191
192 # POSSIBLE alternative version using --make:
193 #
194 # lib : $(HS_SRCS)
195 #       $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
196
197 # $(LIBNAME) : lib
198 #       $(RM) $@
199 #       $(AR) $(AR_OPTS) $@ $(HS_OBJS)
200 #       $(RANLIB) $@
201
202 # %.o : %.hs
203 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
204 # %.o : %.lhs
205 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
206
207 # -----------------------------------------------------------------------------
208 # Installation; need to install .hi files as well as libraries
209
210 ifeq "$(DLLized)" "YES"
211 INSTALL_PROGS += $(DLL_NAME)
212 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
213 endif
214
215 # The interface files are put inside the $(libdir), since they
216 # might (potentially) be platform specific..
217
218 ifeq "$(HIERARCHICAL_LIB)" "YES"
219 ifacedir = $(libdir)/imports
220 else
221 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
222 endif
223
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)" ""
229 install ::
230         @for i in $(ALL_DIRS); do \
231                 $(INSTALL_DIR) $(ifacedir)/$$i; \
232         done
233 endif
234 else
235 INSTALL_IFACES += $(HS_IFACES)
236 endif
237
238 # -----------------------------------------------------------------------------
239 # Dependencies
240
241 ifeq "$(STANDALONE_PACKAGE)" "NO"
242 MKDEPENDHS = $(GHC_INPLACE)
243 endif
244
245 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
246
247 ifeq "$(STANDALONE_PACKAGE)" "NO"
248 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
249 endif
250
251 endif # $(PACKAGE) != ""
252
253 #--------------------------------------------------------------
254 # Installation
255
256 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
257 INSTALL_LIBS  += $(LIBRARY) $(GHCI_LIBRARY)
258 endif
259
260 #--------------------------------------------------------------
261 # Building dynamically-linkable libraries for GHCi
262 #
263 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
264 #
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
267 #
268 # Furthermore, GHCi currently never loads 
269 # profiling libraries (or other non-std ways)
270
271 ifneq "$(LIBRARY)" ""
272
273 ifeq "$(way)" ""
274 ifeq "$(GhcWithInterpreter)" "YES"
275
276 ifndef GHCI_LIBRARY
277 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
278 endif
279
280 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
281 INSTALL_LIBS += $(GHCI_LIBRARY)
282 endif
283
284 CLEAN_FILES  += $(GHCI_LIBRARY)
285
286 all :: $(GHCI_LIBRARY)
287
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.
293 #
294 $(GHCI_LIBRARY) : $(LIBOBJS)
295         $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
296
297 endif # DONT_WANT_STD_GHCI_LIB_RULE
298 endif # GhcWithInterpreter
299 endif # way
300
301 ifeq "$(GhcBuildDylibs)" "YES"
302
303     # Build dynamic libraries.
304     # Currently, this is a hack. Anyone, PLEASE clean it up.
305
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.
309     
310 ifeq "$(darwin_TARGET_OS)" "1"
311     # Darwin: Shared libraries end in .dylib
312 DYLD_LIBRARY = $(patsubst %.a,%_dyn.dylib,$(LIBRARY))
313
314     # About the options used for Darwin:
315     # -dynamiclib
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.
321     # -install_name
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
329
330 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
331         $(CC) -dynamiclib -o $@ $(STUBOBJS) $(LIBOBJS) -flat_namespace -undefined suppress -install_name `pwd`/$@
332 else
333 DYLD_LIBRARY = $(patsubst %.a,%_dyn.so,$(LIBRARY))
334
335 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
336         $(CC) -shared -o $@ $(STUBOBJS) $(LIBOBJS)
337 endif
338
339 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
340 INSTALL_LIBS += $(DYLD_LIBRARY)
341 endif
342
343 CLEAN_FILES += $(DYLD_LIBRARY)
344
345 all :: $(DYLD_LIBRARY)
346
347 endif # $(GhcBuildDylibs) == "YES"
348
349 endif # $(LIBRARY) /= ""
350
351 # -----------------------------------------------------------------------------
352 # Doc building with Haddock
353
354 ifneq "$(PACKAGE)" ""
355 ifneq "$(NO_HADDOCK_DOCS)" "YES"
356
357 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS)))) $(EXTRA_HADDOCK_SRCS)
358
359 HTML_DIR = ../html-docs/$(PACKAGE)
360 HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
361
362 ifneq "$(HS_PPS)" ""
363
364 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
365
366 ifeq "$(HADDOCK)" ""
367 html ::
368         @echo Haddock must be installed in order to build HTML library documentation.
369         @echo Please install Haddock and re-configure.
370         @exit 1
371 endif
372
373 html :: $(HTML_DOC)
374
375 extraclean :: 
376         $(RM) -rf $(HTML_DIR)
377
378 ifneq "$(findstring $(PACKAGE), $(CorePackages))" ""
379 HaddockSourceURL = $(CorePackageSourceURL)
380 else
381 HaddockSourceURL = $(ExtraPackageSourceURL)
382 endif
383
384 $(HTML_DOC) : $(HS_PPS)
385         @$(INSTALL_DIR) $(HTML_DIR)
386         $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
387                 --package=$(PACKAGE) \
388                 --dump-interface=$(PACKAGE).haddock \
389                 --use-index=../doc-index.html --use-contents=../index.html \
390                 --source-module=$(HaddockSourceURL) \
391                 $(foreach pkg, $(PACKAGE_DEPS), \
392                    --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
393
394 CLEAN_FILES += $(PACKAGE).haddock
395
396 %.raw-hs : %.lhs
397         $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
398
399 %.raw-hs : %.hs
400         $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
401
402 HTML_INSTALL_DIR = $(datadir)/html/libraries/$(PACKAGE)
403 #  NOT the same as HTML_DIR_INSTALLED when BIN_DIST is on
404
405 install-docs :: $(HTML_DOC)
406         @$(INSTALL_DIR) $(HTML_INSTALL_DIR)
407         for i in $(HTML_DIR)/*; do \
408           echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
409           $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
410         done; \
411         $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(HTML_INSTALL_DIR); \
412
413 endif # HS_PPS
414 endif # NO_HADDOCK_DOCS
415 endif # $(PACKAGE) /= ""
416
417 # -----------------------------------------------------------------------------
418