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