[project @ 2005-01-14 08:01:26 by wolfgang]
[ghc-hetmet.git] / mk / package.mk
1 # -----------------------------------------------------------------------------
2 # $Id: package.mk,v 1.43 2005/01/14 08:01:27 wolfgang Exp $
3
4 ifneq "$(PACKAGE)" ""
5
6 ifeq "$(STANDALONE_PACKAGE)" ""
7 ifeq "$(ProjectNameShort)" "ghc"
8 STANDALONE_PACKAGE = NO
9 else
10 STANDALONE_PACKAGE = YES
11 endif
12 endif
13
14 # -----------------------------------------------------------------------------
15 # Build the package configuration file and tell the compiler about it.
16
17 ifeq "$(way)" ""
18
19 ifeq "$(STANDALONE_PACKAGE)" "NO"
20 PACKAGE_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -Iinclude
21 else
22 PACKAGE_CPP_OPTS += -Iinclude
23 endif
24
25 PACKAGE_CPP_OPTS += -DPACKAGE=${PACKAGE}
26 PACKAGE_CPP_OPTS += -DVERSION=${VERSION}
27
28 IMPORT_DIR_INSTALLED = $$libdir/imports
29 IMPORT_DIR_INPLACE   = $$libdir/libraries/$(PACKAGE)
30
31 LIB_DIR_INSTALLED    = $$libdir
32 LIB_DIR_INPLACE      = $$libdir/libraries/$(PACKAGE)
33
34 package.conf.inplace   : package.conf.in
35         $(CPP) $(RAWCPP_FLAGS) -P \
36                 -DIMPORT_DIR='"$(IMPORT_DIR_INPLACE)"' \
37                 -DLIB_DIR='"$(LIB_DIR_INPLACE)"' \
38                 -x c $(PACKAGE_CPP_OPTS) $< | \
39         grep -v '^#pragma GCC' | \
40         sed -e 's/""//g' -e 's/:[       ]*,/: /g' >$@
41
42 package.conf.installed : package.conf.in
43         $(CPP) $(RAWCPP_FLAGS) -P -DINSTALLING \
44                 -DIMPORT_DIR='"$(IMPORT_DIR_INSTALLED)"' \
45                 -DLIB_DIR='"$(LIB_DIR_INSTALLED)"' \
46                  -x c $(PACKAGE_CPP_OPTS) $< | \
47         grep -v '^#pragma GCC' | \
48         sed -e 's/""//g' -e 's/:[       ]*,/: /g' >$@
49
50 # we could be more accurate here and add a dependency on
51 # ghc/driver/package.conf, but that doesn't work too well because of
52 # make's limited accuracy with modification times: when doing 'make
53 # boot' in multiple packages, make won't detect that the package
54 # configuration needs updating if it was updated already in the last
55 # second.
56 #
57 # The stamp file goes in $(GHC_DRIVER_DIR), so that if someone happens
58 # to 'make clean' in ghc without cleaning in libraries too, the packages
59 # will be correctly re-installed.
60 #
61 ifeq "$(STANDALONE_PACKAGE)" "NO"
62
63 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
64 CLEAN_FILES += $(STAMP_PKG_CONF)
65
66 ifneq "$(BootingFromHc)" "YES"
67 boot all :: $(STAMP_PKG_CONF)
68 endif
69
70 $(STAMP_PKG_CONF) : package.conf.inplace package.conf.installed
71         $(GHC_PKG_INPLACE) --update-package <package.conf.inplace
72         $(GHC_PKG_INPLACE)  -f $(GHC_DRIVER_DIR)/package.conf --update-package <package.conf.installed
73         @touch $(STAMP_PKG_CONF)
74
75 CLEAN_FILES += package.conf.installed package.conf.inplace 
76
77 else # $(STANDALONE_PACKAGE) == "YES"
78
79 PACKAGE_CPP_OPTS += -DPACKAGE_DEPS='$(subst " ","$(comma) ",$(patsubst %,"%",$(PACKAGE_DEPS)))'
80 PACKAGE_CPP_OPTS += -DLIBRARY=\"HS$(PACKAGE)\"
81 PACKAGE_CPP_OPTS += -DLIBDIR=\"$(libdir)\"
82 PACKAGE_CPP_OPTS += -DFPTOOLS_TOP_ABS=\"${FPTOOLS_TOP_ABS}\"
83
84 # Let the package configuration file refer to $(libdir) as
85 # ${pkglibdir}.  Note we can't use ${libdir} because ghc-pkg already
86 # redefines it to point to GHC's libdir (bug or feature?).
87 #
88 install :: package.conf.installed
89         $(GHC_PKG) --force --update-package <package.conf.installed
90
91 # Invoke this rule by hand in order to use the package in-place
92 install-inplace-pkg : package.conf.inplace
93         $(GHC_PKG) --force --update-package <package.conf.inplace
94
95 endif # $(STANDALONE_PACKAGE)
96
97 endif # $(way) == ""
98
99 # -----------------------------------------------------------------------------
100 # Building the static library libHS<pkg>.a
101
102 ifeq "$(STANDALONE_PACKAGE)" "NO"
103 HC = $(GHC_INPLACE)
104 endif
105
106 SRC_HSC2HS_OPTS += -I.
107
108 ifeq "$(NON_HS_PACKAGE)" ""
109 SRC_HC_OPTS     += -ignore-package $(PACKAGE)
110 SRC_HC_OPTS     += $(GhcLibHcOpts)
111 SRC_HC_OPTS     += $(patsubst %, -package %, $(PACKAGE_DEPS))
112 endif
113
114 LIBRARY         = libHS$(PACKAGE)$(_way).a
115
116 ifeq "$(WAYS)" ""
117 WAYS = $(GhcLibWays)
118 endif
119
120 all :: $(LIBRARY)
121
122 # POSSIBLE alternative version using --make:
123 #
124 # lib : $(HS_SRCS)
125 #       $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
126
127 # $(LIBNAME) : lib
128 #       $(RM) $@
129 #       $(AR) $(AR_OPTS) $@ $(HS_OBJS)
130 #       $(RANLIB) $@
131
132 # %.o : %.hs
133 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
134 # %.o : %.lhs
135 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
136
137 # -----------------------------------------------------------------------------
138 # Installation; need to install .hi files as well as libraries
139
140 ifeq "$(DLLized)" "YES"
141 INSTALL_PROGS += $(DLL_NAME)
142 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
143 endif
144
145 # The interface files are put inside the $(libdir), since they
146 # might (potentially) be platform specific..
147
148 ifeq "$(HIERARCHICAL_LIB)" "YES"
149 ifacedir = $(libdir)/imports
150 else
151 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
152 endif
153
154 # If the lib consists of a hierachy of modules, we must retain the directory
155 # structure when we install the interfaces.
156 ifeq "$(HIERARCHICAL_LIB)" "YES"
157 INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
158 ifneq "$(ALL_DIRS)" ""
159 install ::
160         @for i in $(ALL_DIRS); do \
161                 $(INSTALL_DIR) $(ifacedir)/$$i; \
162         done
163 endif
164 else
165 INSTALL_IFACES += $(HS_IFACES)
166 endif
167
168 # -----------------------------------------------------------------------------
169 # Dependencies
170
171 ifeq "$(STANDALONE_PACKAGE)" "NO"
172 MKDEPENDHS = $(GHC_INPLACE)
173 endif
174
175 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
176
177 ifeq "$(STANDALONE_PACKAGE)" "NO"
178 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
179 endif
180
181 endif # $(PACKAGE) /= ""
182
183 # install library (could be implicitly specified or explicitly, like libHS*_cbits.a)
184 INSTALL_LIBS  += $(LIBRARY)
185
186 #--------------------------------------------------------------
187 # Building dynamically-linkable libraries for GHCi
188 #
189 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
190 #
191 # Why?  GHCi can only link .o files (at the moment), not .a files
192 # so we have to build libFoo.o as well as libFoo.a
193 #
194 # Furthermore, GHCi currently never loads 
195 # profiling libraries (or other non-std ways)
196
197 ifneq "$(LIBRARY)" ""
198
199 ifeq "$(way)" ""
200 ifeq "$(GhcWithInterpreter)" "YES"
201
202 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
203
204 INSTALL_LIBS += $(GHCI_LIBRARY)
205 CLEAN_FILES  += $(GHCI_LIBRARY)
206
207 all :: $(GHCI_LIBRARY)
208
209 ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
210 # If you don't want to build GHCI_LIBRARY the 'standard' way,
211 # set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
212 # hslibs/Win32 uses this 'feature', which will go away soon
213 # when we can use a "fixed" ld.
214 #
215 $(GHCI_LIBRARY) : $(LIBOBJS)
216         $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
217
218 endif # DONT_WANT_STD_GHCI_LIB_RULE
219 endif # GhcWithInterpreter
220 endif # way
221
222 ifeq "$(GhcBuildDylibs)" "YES"
223
224     # Build dynamic libraries.
225     # Currently, this is a hack. Anyone, PLEASE clean it up.
226
227     # For now, we pretend that there are two operating systems in the world;
228     # Darwin, and Everything Else. Furthermore, we pretend that Everything Else
229     # behaves like Linux.
230     
231 ifeq "$(darwin_TARGET_OS)" "1"
232     # Darwin: Shared libraries end in .dylib
233 DYLD_LIBRARY = $(patsubst %.a,%_dyn.dylib,$(LIBRARY))
234
235     # About the options used for Darwin:
236     # -dynamiclib
237     #   Apple's way of saying -shared
238     # -flat_namespace -undefined suppress:
239     #   Without these options, we'd have to specify the correct dependencies
240     #   for each of the dylibs. Twolevel namespaces are in general a good thing
241     #   (they make things more robust), so we should fix this sooner or later.
242     # -install_name
243     #   Causes the dynamic linker to ignore the DYLD_LIBRARY_PATH when loading
244     #   this lib and instead look for it at its absolute path.
245     #   When installing the .dylibs (see target.mk), we'll change that path to
246     #   point to the place they are installed.
247     #   Note: I'm not yet sure about this, but I think it will be convenient for
248     #         users not to have to set up DYLD_LIBRARY_PATH to point to the GHC
249     #         library dir. -- Wolfgang
250     
251 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
252         $(CC) -dynamiclib -o $@ $(STUBOBJS) $(LIBOBJS) -flat_namespace -undefined suppress -install_name `pwd`/$@
253 else
254 DYLD_LIBRARY = $(patsubst %.a,%_dyn.so,$(LIBRARY))
255
256 $(DYLD_LIBRARY) : $(LIBOBJS) $(STUBOBJS)
257         $(CC) -shared -o $@ $(STUBOBJS) $(LIBOBJS)
258 endif
259
260 INSTALL_LIBS += $(DYLD_LIBRARY)
261 CLEAN_FILES += $(DYLD_LIBRARY)
262
263 all :: $(DYLD_LIBRARY)
264
265
266 endif
267
268 # -----------------------------------------------------------------------------
269 # Doc building with Haddock
270
271 ifneq "$(NO_HADDOCK_DOCS)" "YES"
272
273 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS))))
274
275 HTML_DIR = html
276 HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
277
278 ifneq "$(HS_PPS)" ""
279
280 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
281
282 ifeq "$(HADDOCK)" ""
283 html ::
284         @echo Haddock must be installed in order to build HTML library documentation.
285         @echo Please install Haddock and re-configure.
286         @exit 1
287 endif
288
289 html :: $(HTML_DOC)
290
291 extraclean :: 
292         $(RM) -rf $(HTML_DIR)
293
294 $(HTML_DOC) : $(HS_PPS)
295         @$(INSTALL_DIR) $(HTML_DIR)
296         $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
297                 --package=$(PACKAGE) \
298                 --dump-interface=$(PACKAGE).haddock \
299                 --use-index=../doc-index.html --use-contents=../index.html \
300                 $(foreach pkg, $(PACKAGE_DEPS), \
301                    --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
302
303 CLEAN_FILES += $(PACKAGE).haddock
304
305 %.raw-hs : %.lhs
306         $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
307
308 %.raw-hs : %.hs
309         $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
310
311 install-docs :: $(HTML_DOC)
312         @$(INSTALL_DIR) $(datadir)/html/libraries/$(PACKAGE)
313         @for i in $(HTML_DIR)/*; do \
314            echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(datadir)/html/libraries/$(PACKAGE); \
315            $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(datadir)/html/libraries/$(PACKAGE); \
316         done
317         $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(datadir)/html/libraries/$(PACKAGE)
318
319 endif # HS_PPS
320 endif # NO_HADDOCK_DOCS
321
322 # -----------------------------------------------------------------------------
323
324 endif # $(LIBRARY) /= ""