Fix the build with GHC 6.4
[ghc-hetmet.git] / libraries / Makefile
1
2 # To do a fresh build:
3 #
4 #   make clean
5 #   make boot
6 #   make
7 #
8 # To rebuild a particular library <package>:
9 #
10 #   make clean.library.<package>
11 #   make make.library.<package>
12 #
13 # or the following is equivalent:
14 #
15 #   make remake.library.<package>
16 #
17 # To add a new library to the tree, do
18 #
19 #   darcs get http://darcs.haskell.org/packages/foo
20 #   [ -e foo/configure.ac ] && ( cd foo && autoreconf )
21 #   make make.library.foo
22
23 .PHONY: default_target show
24
25 default_target: all
26
27 show:
28         @echo '$(VALUE)="$($(VALUE))"'
29
30 # make doesn't give us an easy way to get the libraries built in
31 # dependency order the first time, but not rebuild base (for example)
32 # when we want to rebuild another library later.
33 # So for now we just don't do anything in parallel in here.
34 .NOTPARALLEL:
35
36 # Ideally we'd just include something to give us variables
37 # for paths and arguments to tools etc, and those set in mk/build.mk.
38 TOP=..
39 include $(TOP)/mk/boilerplate.mk
40
41 SUBDIRS  = ghc-prim $(INTEGER_LIBRARY) base array packedstring
42 SUBDIRS += containers bytestring old-locale old-time filepath directory
43 ifeq "$(GhcLibsWithUnix)" "YES"
44 SUBDIRS += unix
45 endif
46 ifeq "$(Windows)" "YES"
47 SUBDIRS += $(wildcard Win32)
48 endif
49 SUBDIRS += process pretty hpc template-haskell editline Cabal random haskell98
50
51 # Set GhcBootLibs=YES from the command line to work with just the libraries
52 # needed to bootstrap GHC.
53 ifneq "$(GhcBootLibs)" "YES"
54 SUBDIRS += $(wildcard regex-base)
55 SUBDIRS += $(wildcard regex-posix)
56 SUBDIRS += $(wildcard regex-compat)
57 SUBDIRS += $(wildcard parsec)
58 SUBDIRS += $(wildcard haskell-src)
59 SUBDIRS += $(wildcard html)
60 SUBDIRS += $(wildcard network)
61 SUBDIRS += $(wildcard QuickCheck)
62 SUBDIRS += $(wildcard HUnit)
63 SUBDIRS += $(wildcard mtl)
64 SUBDIRS += $(wildcard fgl)
65 SUBDIRS += $(wildcard time)
66 SUBDIRS += $(wildcard OpenGL)
67 SUBDIRS += $(wildcard GLUT)
68 SUBDIRS += $(wildcard OpenAL)
69 SUBDIRS += $(wildcard ALUT)
70 SUBDIRS += $(wildcard stm)
71 SUBDIRS += $(wildcard xhtml)
72 SUBDIRS += $(wildcard cgi)
73 ifeq "$(GhcLibsWithObjectIO)" "YES"
74 SUBDIRS += $(wildcard ObjectIO)
75 endif
76 SUBDIRS += $(wildcard parallel)
77 SUBDIRS_BUILD += $(wildcard ndp)
78 SUBDIRS_BUILD += $(wildcard dph/dph-base)
79 SUBDIRS_BUILD += $(wildcard dph/dph-prim-seq)
80 SUBDIRS_BUILD += $(wildcard dph/dph-prim-par)
81 SUBDIRS_BUILD += $(wildcard dph/dph)
82 endif
83
84 SUBDIRS += $(SUBDIRS_BUILD)
85
86 # -----------------------------------------------------------------------------
87
88 empty=
89 space=$(empty) $(empty)
90
91 # -----------------------------------------------------------------------------
92
93 ifeq "$(ghc_ge_609)" "YES"
94 GhcLibHcOpts += -fno-warn-deprecated-flags
95 endif
96
97 ifeq "$(RelocatableBuild)" "YES"
98 # On Windows we want to make moveable bindists, but we need to tell
99 # ghc-pkg where the haddock docs are. Therefore we completely ignore
100 # where the user tells us to put the haddock documentation and put it
101 # somewhere whose relative location we know. When installing we need
102 # to give Cabal a real path, though.
103 iprefix             = $$topdir
104 ibindir             = $$topdir
105 ilibdir             = $$topdir
106 ilibexecdir         = $$topdir
107 idynlibdir          = $$topdir
108 idatadir            = $$topdir
109 idocdir             = $$topdir/doc/libraries/$$pkg
110 ihaddockdir         = $$topdir/doc/libraries/$$pkg
111 ihtmldir            = $$httptopdir/doc/libraries/$$pkg
112 html_installed_root = $(prefix)/doc/libraries
113 else
114 # On non-Windows we can just give absolute paths all the time, and
115 # thus obey the htmldir that we are given.
116 iprefix             = $(prefix)
117 ibindir             = $(bindir)
118 ilibdir             = $(libdir)
119 ilibexecdir         = $(libexecdir)
120 idynlibdir          = $(dynlibdir)
121 idatadir            = $(datadir)
122 idocdir             = $(docdir)/libraries/$$pkg
123 ihaddockdir         = $(htmldir)/libraries/$$pkg
124 ihtmldir            = $(htmldir)/libraries/$$pkg
125 html_installed_root = $(htmldir)/libraries
126 endif
127
128 ifneq "$(DOING_BIN_DIST)" "YES"
129
130 CONFIGURE_OPTS =
131 CONFIGURE_STAMP_EXTRAS :=
132
133 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
134 CONFIGURE_OPTS += --enable-library-profiling
135 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
136 endif
137
138 ifneq "$(findstring $(space)dyn$(space), $(space)$(GhcLibWays)$(space))" ""
139 CONFIGURE_OPTS += --enable-shared
140 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
141 endif
142
143 ifeq "$(SplitObjs)" "YES"
144 CONFIGURE_OPTS += --enable-split-objs
145 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
146 endif
147
148 ifneq "$(HSCOLOUR)" ""
149 CONFIGURE_OPTS += --with-hscolour=$(HSCOLOUR)
150 endif
151
152 BOOTSTRAP_LIBS = Cabal filepath
153 BOOTSTRAP_STAMPS = $(addprefix stamp/bootstrapping.,$(BOOTSTRAP_LIBS))
154 BOOTSTRAP_INC = -DCABAL_VERSION=1,3 $(addprefix -i$(FPTOOLS_TOP_ABS)/libraries/bootstrapping.,$(BOOTSTRAP_LIBS))
155 DEPLOYMENT_OPTS = $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS)) \
156                   $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
157
158 .PHONY: subdirs
159
160 subdirs:
161         @echo $(SUBDIRS)
162
163 .PHONY: boot
164
165 boot: $(BOOTSTRAP_STAMPS) ifBuildable/ifBuildable \
166           $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
167           installPackage/installPackage
168
169 # We build the Setup program in a setup subdirectory to stop it trying
170 # to use bits of base and Cabal when we build those packages.
171 # This also makes it slightly easier to clean.
172
173 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
174
175 CABAL_GHC_FLAGS = -Wall
176 ifeq "$(ghc_ge_605)" "NO"
177 CABAL_GHC_FLAGS += -cpp
178 endif
179
180 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
181 %/setup/Setup: $(BOOTSTRAP_STAMPS)
182         -$(RM) -rf $*/setup
183         mkdir $*/setup
184         $(CP) $*/Setup.*hs $*/setup
185         cd $*/setup && $(GHC) $(CABAL_GHC_FLAGS) --make Setup.*hs -o Setup \
186                               $(BOOTSTRAP_INC)
187
188 installPackage/installPackage: installPackage.hs $(BOOTSTRAP_STAMPS)
189         -$(RM) -rf installPackage
190         mkdir installPackage
191         $(CP) installPackage.hs installPackage/
192 ifeq "$(stage)" "2"
193         cd installPackage && ../$(HC) $(CABAL_GHC_FLAGS) \
194                                     --make installPackage -o installPackage \
195                                     $(BOOTSTRAP_INC) $(DEPLOYMENT_OPTS)
196 else
197         cd installPackage && $(GHC) $(CABAL_GHC_FLAGS) \
198                                     --make installPackage -o installPackage \
199                                     $(BOOTSTRAP_INC)
200 endif
201 # TODO: The conditional is yucky, but we need to be able to build with stage1
202 #       for bindists and as installPackages/ has no Makefile, it seems hard
203 #       to make this nicer.
204
205 ifBuildable/ifBuildable: ifBuildable.hs
206         -$(RM) -rf ifBuildable
207         mkdir ifBuildable
208         $(CP) ifBuildable.hs ifBuildable/
209 ifeq "$(stage)" "2"
210         cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable \
211                                  $(DEPLOYMENT_OPTS)
212 else
213         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
214 endif
215
216 IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/libraries/boot-packages
217
218 $(BOOTSTRAP_STAMPS): stamp/bootstrapping.%:
219         $(RM) -rf bootstrapping.$*
220         $(CP) -R $* bootstrapping.$*
221         $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
222                                  -exec $(RM) -f {} \;
223         touch $@
224
225 .PHONY: all build configure
226
227 all: build
228
229 ifeq "$(HADDOCK_DOCS)" "YES"
230 all: doc
231 endif
232
233 .PHONY: rebuild.library.%
234 .PHONY: remake.library.%
235
236 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
237 rebuild.library.%: clean.library.% build.library.%
238
239 $(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
240 remake.library.%: clean.library.% make.library.%
241
242 # NB. we're depending on make chasing dependencies from left to right here.
243 # This bit goes wrong with 'make -j'.
244 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
245 build: installPackage/installPackage
246
247 configure: $(foreach SUBDIR,$(SUBDIRS), \
248              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
249
250 .PHONY: build.library.%
251 .PHONY: make.library.%
252
253 # We should depend on %/%.cabal here (and in other rules), but make
254 # makes that difficult.
255
256 # We put non-existant paths in when configuring, as we require that
257 # builds don't depend on these paths when making bindists.
258
259 # We rely on all the CONFIGURE_ARGS being quoted with '...', and there
260 # being no 's inside the values.
261 FLAGGED_CONFIGURE_ARGS = $(subst $(space)',\
262                                  $(space)--configure-option=',\
263                                  $(space)$(CONFIGURE_ARGS))
264
265 ifeq "$(Windows)" "YES"
266 NONEXISTENT=c:/NONEXISTENT
267 else
268 NONEXISTENT=/NONEXISTENT
269 endif
270
271 ALL_CONFIGURE_FLAGS = \
272                    $(CONFIGURE_OPTS) \
273                    --prefix=$(NONEXISTENT) \
274                    --bindir=$(NONEXISTENT) \
275                    --libdir=$(NONEXISTENT) \
276                    --libsubdir='$$pkgid' \
277                    --libexecdir=$(NONEXISTENT) \
278                    --datadir=$(NONEXISTENT) \
279                    --docdir=$(NONEXISTENT) \
280                            --haddockdir=$(NONEXISTENT) \
281                    --htmldir=$(NONEXISTENT) \
282                    --with-compiler=$(FPTOOLS_TOP_ABS)/compiler/stage1/ghc-inplace \
283                    --with-hc-pkg=$(FPTOOLS_TOP_ABS)/utils/ghc-pkg/ghc-pkg-inplace \
284                    --with-hsc2hs=$(FPTOOLS_TOP_ABS)/utils/hsc2hs/hsc2hs-inplace \
285                    --with-ld=$(LD) \
286                    --haddock-options="--use-contents=../index.html \
287                                       --use-index=../doc-index.html" \
288                    $(FLAGGED_CONFIGURE_ARGS) \
289                    --configure-option=--with-cc=$(CC)
290
291 $(foreach SUBDIR,$(SUBDIRS), \
292                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
293 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
294         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
295         $(MKDIRHIER) `dirname $@`
296         ( cd $* && setup/Setup configure $(ALL_CONFIGURE_FLAGS) ) \
297               && touch $@ || touch $*/unbuildable
298 # We don't touch $@ if configure failed as we would prefer to try
299 # configuring it next time round, rather than assuming it'll still fail.
300 # This is particularly important for bootlibs, where failure means the
301 # build dies!
302
303 # Build the library using 'make'
304 # We re-run 'setup makefile' each time, just in case any preprocessing
305 # needs to be done.  However, we're careful not to overwrite GNUmakefile
306 # if it hasn't changed, so that dependency-generation isn't forced
307 # every time.
308 # Packages in $(SUBDIRS_BUILD) need to use the build.* rules instead of
309 # make.*, so filter them out and use an alternate rule below instead.
310 $(foreach SUBDIR,$(filter-out $(SUBDIRS_BUILD),$(SUBDIRS)),make.library.$(SUBDIR)):\
311 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
312                 %/setup/Setup ifBuildable/ifBuildable installPackage/installPackage
313         if $(IFBUILDABLE) $*; then \
314           cd $* && \
315           cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
316           mv GNUmakefile GNUmakefile.tmp; \
317           setup/Setup makefile -f GNUmakefile; \
318           cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
319           $(MAKE) $(MFLAGS) && \
320           setup/Setup register --inplace; \
321         fi
322
323 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
324
325 # Alternate rule, as described above
326 $(foreach SUBDIR,$(SUBDIRS_BUILD),make.library.$(SUBDIR)):\
327 make.library.%: build.library.%
328
329 # Build the library using 'setup build' (not the default)
330 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
331 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
332                  %/setup/Setup ifBuildable/ifBuildable
333         if $(IFBUILDABLE) $*; then \
334           cd $* && \
335           setup/Setup build $(addprefix --ghc-option=,$(GhcLibHcOpts)); \
336           setup/Setup register --inplace; \
337         fi
338
339 .PHONY: doc html
340
341 html: doc
342
343 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
344         sh gen_contents_index --inplace
345
346 # Making hyperlinked source only works if we have hscolour
347 ifneq "$(HSCOLOUR)" ""
348 CABAL_HADDOCK_FLAGS=--hyperlink-source
349 endif
350
351 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
352 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
353                %/setup/Setup ifBuildable/ifBuildable
354         if $(IFBUILDABLE) $*; then \
355           cd $* && setup/Setup haddock --html-location='../$$pkg' \
356                                        $(CABAL_HADDOCK_FLAGS); \
357         fi
358 ifneq "$(HSCOLOUR)" ""
359 # We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
360 # mismatch
361         if $(IFBUILDABLE) $*; then cp hscolour.css $*/dist/doc/html/*/src/; fi
362 endif
363
364 .PHONY: distclean clean clean.library.%
365
366 distclean: clean
367
368 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
369         $(RM) -f stamp/bootstrapping.*
370         $(RM) -rf bootstrapping.*
371         $(RM) -rf ifBuildable
372         $(RM) -rf installPackage
373         $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
374         $(RM) -f haddock* *.gif
375
376 distclean:
377         $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
378
379 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
380 clean.library.%:
381         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
382         -cd $* && setup/Setup clean
383         $(RM) -rf $*/setup
384         $(RM) $*/GNUmakefile $*/Makefile.local
385 endif
386
387 # -----------------------------------------------------------------------------
388
389 .PHONY: install install-docs install.library.%
390
391 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
392 ifeq "$(HADDOCK_DOCS)" "YES"
393         $(INSTALL_DIR)                                                     $(DESTDIR)$(html_installed_root)
394         $(INSTALL_DATA)   index.html doc-index*.html                       $(DESTDIR)$(html_installed_root)
395         $(INSTALL_SCRIPT) gen_contents_index                               $(DESTDIR)$(html_installed_root)
396         # Hacks:
397         $(INSTALL_DATA)   base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
398         $(INSTALL_DATA)   base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
399         $(INSTALL_DATA)   base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
400 endif
401
402 # Cabal doesn't let us ask to install docs only, so do nothing here
403 install-docs:
404         @:
405
406 # Ideally this would depend on a stamp/build.library.%, but if it does
407 # then we can't change the libraries and then just rerun make.
408 # Thus if you install without building then it will just break.
409
410 # prefix and (on Windows) htmldir use $topdir when configuring, so we
411 # need to tell installPackage the real path to use when installing.
412
413 # We also need to pass all the other directories in, as they can be
414 # overridden when installing a bindist.
415
416 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
417 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
418         if $(IFBUILDABLE) $*; then \
419           cd $* && \
420           $(FPTOOLS_TOP_ABS)/libraries/installPackage/installPackage install '$(GHC_PKG_PROG)' '$(DESTDIR)$(libdir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' ; \
421         fi
422
423 .PHONY: binary-dist binary-dist.library.%
424
425 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
426
427 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
428         mkdir                               $(BIN_DIST_LIBDIR)/installPackage
429         cp        installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
430         mkdir                               $(BIN_DIST_LIBDIR)/ifBuildable
431         cp        ifBuildable/ifBuildable       $(BIN_DIST_LIBDIR)/ifBuildable
432         cp    Makefile                      $(BIN_DIST_LIBDIR)
433 ifeq "$(HADDOCK_DOCS)" "YES"
434         cp    gen_contents_index            $(BIN_DIST_LIBDIR)
435         cp    index.html                    $(BIN_DIST_LIBDIR)
436         cp    doc-index*.html               $(BIN_DIST_LIBDIR)
437 endif
438         cp -pR stamp                         $(BIN_DIST_LIBDIR)
439
440 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
441 binary-dist.library.%:
442         if $(IFBUILDABLE) $*; then \
443           $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*; \
444           cd $* && \
445           cp    $*.cabal      $(BIN_DIST_LIBDIR)/$* && \
446           cp    LICENSE       $(BIN_DIST_LIBDIR)/$* && \
447           cp -R dist          $(BIN_DIST_LIBDIR)/$* && \
448           $(FIND) . -name "*.buildinfo" -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
449           $(FIND) . -name unbuildable -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
450           (cp -RL include      $(BIN_DIST_LIBDIR)/$* || true) && \
451           $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
452              \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
453           $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
454              \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
455              -exec rm {} \; ; \
456         fi
457
458 # Ignore some doc targets that we don't support
459 # The root recurses into us when these targets are made
460 .PHONY: html-no-chunks chm HxS fo dvi ps pdf
461 html-no-chunks chm HxS fo dvi ps pdf:
462         @:
463