c32c1f61526e6ceca8997bb7018ffce77cc90abb
[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 #   [ -f foo/configure.ac ] && ( cd foo && autoreconf )
21 #   make make.library.foo
22
23 .PHONY: default_target
24
25 default_target: all
26
27 # make doesn't give us an easy way to get the libraries built in
28 # dependency order the first time, but not rebuild base (for example)
29 # when we want to rebuild another library later.
30 # So for now we just don't do anything in parallel in here.
31 .NOTPARALLEL:
32
33 # Ideally we'd just include something to give us variables
34 # for paths and arguments to tools etc, and those set in mk/build.mk.
35 TOP=..
36 include $(TOP)/mk/boilerplate.mk
37 include $(TOP)/mk/cabal-flags.mk
38
39 ifeq "$(stage)" ""
40 stage := 1
41 endif
42
43 DO_STAGE_1_LIBS := NO
44 DO_STAGE_2_LIBS := NO
45 ifeq "$(stage)" "1"
46 DO_STAGE_1_LIBS := YES
47 endif
48 ifeq "$(stage)" "2"
49 DO_STAGE_2_LIBS := YES
50 endif
51 ifneq "$(filter install clean maintainer-clean distclean binary-dist,$(MAKECMDGOALS))" ""
52 DO_STAGE_1_LIBS := YES
53 DO_STAGE_2_LIBS := YES
54 endif
55
56 # Any libraries listed here should also be in ../packages
57
58 SUBDIRS :=
59
60 ifeq "$(DO_STAGE_1_LIBS)" "YES"
61 SUBDIRS += ghc-prim $(INTEGER_LIBRARY) base syb base3-compat array packedstring
62 SUBDIRS += containers bytestring old-locale old-time filepath 
63 ifeq "$(GhcLibsWithUnix)" "YES"
64 SUBDIRS += unix
65 endif
66 ifeq "$(Windows)" "YES"
67 SUBDIRS += $(wildcard Win32)
68 endif
69 SUBDIRS += directory process pretty hpc template-haskell editline Cabal random haskell98
70
71 # Set GhcBootLibs=YES from the command line to work with just the libraries
72 # needed to bootstrap GHC.
73 ifneq "$(GhcBootLibs)" "YES"
74 SUBDIRS += $(wildcard regex-base)
75 SUBDIRS += $(wildcard regex-posix)
76 SUBDIRS += $(wildcard regex-compat)
77 SUBDIRS += $(wildcard parsec)
78 SUBDIRS += $(wildcard haskell-src)
79 SUBDIRS += $(wildcard html)
80 SUBDIRS += $(wildcard network)
81 SUBDIRS += $(wildcard QuickCheck)
82 SUBDIRS += $(wildcard HUnit)
83 SUBDIRS += $(wildcard mtl)
84 SUBDIRS += $(wildcard time)
85 SUBDIRS += $(wildcard stm)
86 SUBDIRS += $(wildcard xhtml)
87 SUBDIRS += $(wildcard parallel)
88 endif
89 endif
90
91 DPH_SUBDIRS :=
92 ifneq "$(GhcBootLibs)" "YES"
93 ifneq "$(wildcard dph)" ""
94 DPH_SUBDIRS += dph/dph-base
95 DPH_SUBDIRS += dph/dph-prim-interface
96 DPH_SUBDIRS += dph/dph-prim-seq
97 DPH_SUBDIRS += dph/dph-prim-par
98 DPH_SUBDIRS += dph/dph-seq
99 DPH_SUBDIRS += dph/dph-par
100 endif
101 endif
102
103 # We have a separate variable for cleaning as this happens in stage=1 and
104 # we want to clean the dph subdirectories, too.
105 ifeq "$(DO_STAGE_2_LIBS)" "YES"
106 SUBDIRS       += $(DPH_SUBDIRS)
107 CLEAN_SUBDIRS  = $(SUBDIRS)
108 else
109 CLEAN_SUBDIRS  = $(SUBDIRS) $(DPH_SUBDIRS)
110 endif
111
112 # -----------------------------------------------------------------------------
113
114 empty=
115 space=$(empty) $(empty)
116
117 # -----------------------------------------------------------------------------
118
119 ifeq "$(ghc_ge_609)" "YES"
120 GhcLibHcOpts += -fno-warn-deprecated-flags
121 endif
122
123 IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/packages
124
125 ifneq "$(DOING_BIN_DIST)" "YES"
126
127 CONFIGURE_OPTS =
128 CONFIGURE_STAMP_EXTRAS :=
129
130 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
131 CONFIGURE_OPTS += --enable-library-profiling
132 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
133 endif
134
135 ifeq "$(BuildSharedLibs)" "YES"
136 CONFIGURE_OPTS += --enable-shared
137 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
138 endif
139
140 ifeq "$(SplitObjs)" "YES"
141 CONFIGURE_OPTS += --enable-split-objs
142 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
143 endif
144
145 .PHONY: subdirs
146
147 subdirs:
148         @echo $(SUBDIRS)
149
150 HERE_ABS=$(FPTOOLS_TOP_ABS)/libraries
151
152 CABAL_GHC_FLAGS = -Wall
153
154 BOOTSTRAPPING_FLAGS = $(CABAL_GHC_FLAGS) -DCABAL_VERSION=$(CABAL_VERSION) -odir $(HERE_ABS)/bootstrapping -hidir $(HERE_ABS)/bootstrapping -i$(HERE_ABS)/Cabal -i$(HERE_ABS)/filepath -i$(HERE_ABS)/hpc
155
156 .PHONY: boot
157
158 boot: ifBuildable/ifBuildable cabal-bin bootstrapping.conf
159
160 cabal-bin: cabal-bin.hs
161         -mkdir bootstrapping
162         $(GHC) $(BOOTSTRAPPING_FLAGS) --make cabal-bin -o cabal-bin
163
164 bootstrapping.conf: cabal-bin
165         echo "[]" > $@.tmp
166         -cd extensible-exceptions && $(CABAL) clean     --distpref=dist-bootstrapping
167         cd extensible-exceptions && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
168         cd extensible-exceptions && $(CABAL) build     --distpref=dist-bootstrapping
169         cd extensible-exceptions && $(CABAL) install   --distpref=dist-bootstrapping --inplace
170         -cd filepath && $(CABAL) clean     --distpref=dist-bootstrapping
171         cd filepath && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
172         cd filepath && $(CABAL) build     --distpref=dist-bootstrapping
173         cd filepath && $(CABAL) install   --distpref=dist-bootstrapping --inplace
174         -cd Cabal    && $(CABAL) clean     --distpref=dist-bootstrapping
175         cd Cabal    && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
176         cd Cabal    && $(CABAL) build     --distpref=dist-bootstrapping
177         cd Cabal    && $(CABAL) install   --distpref=dist-bootstrapping --inplace
178         -cd hpc    && $(CABAL) clean     --distpref=dist-bootstrapping
179         cd hpc    && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
180         cd hpc    && $(CABAL) build     --distpref=dist-bootstrapping
181         cd hpc    && $(CABAL) install   --distpref=dist-bootstrapping --inplace
182         mv $@.tmp $@
183
184 ifBuildable/ifBuildable: ifBuildable.hs
185         -$(RM) -rf ifBuildable
186         mkdir ifBuildable
187         $(CP) ifBuildable.hs ifBuildable/
188 ifeq "$(stage)" "2"
189         cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable
190 else
191         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
192 endif
193
194 .PHONY: all build configure
195
196 all: build
197
198 .PHONY: rebuild.library.%
199 .PHONY: remake.library.%
200
201 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
202 rebuild.library.%: clean.library.% build.library.%
203
204 $(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
205 remake.library.%: clean.library.% make.library.%
206
207 # The meta package dph is a special case
208 ifeq "$(stage)" "1"
209 remake.library.dph:
210         @echo "*** Package dph needs to be made in stage=2"
211 endif
212 ifeq "$(stage)" "2"
213 # NB. we're depending on make chasing dependencies from left to right here.
214 # This bit goes wrong with 'make -j'.
215 remake.library.dph: remake.library.dph/dph-base \
216                 remake.library.dph/dph-prim-interface \
217                 remake.library.dph/dph-prim-seq \
218                 remake.library.dph/dph-prim-par \
219                 remake.library.dph/dph-seq \
220                 remake.library.dph/dph-par
221 endif
222
223 # NB. we're depending on make chasing dependencies from left to right here.
224 # This bit goes wrong with 'make -j'.
225 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
226
227 configure: $(foreach SUBDIR,$(SUBDIRS), \
228              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
229
230 .PHONY: build.library.%
231 .PHONY: make.library.%
232
233 # We should depend on %/%.cabal here (and in other rules), but make
234 # makes that difficult.
235
236 ALL_CONFIGURE_FLAGS = \
237                $(INSTALL_DIRS_CONFIGURE_FLAGS) \
238                $(USE_STAGE$(stage)_CONFIGURE_FLAGS) \
239                $(COMMON_CONFIGURE_FLAGS) \
240                    --haddock-options="--use-contents=../index.html \
241                                       --use-index=../doc-index.html" \
242                    $(CONFIGURE_OPTS)
243
244 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-par: \
245     dph/dph-par
246
247 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-seq: \
248     dph/dph-seq
249
250 dph/%:
251         $(MAKE) -C dph $*
252
253 $(foreach SUBDIR,$(SUBDIRS), \
254                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
255 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: cabal-bin
256         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
257         $(MKDIRHIER) `dirname $@`
258         ( cd $* && $(CABAL) configure $(ALL_CONFIGURE_FLAGS) ) \
259               && touch $@ || touch $*/unbuildable
260 # We don't touch $@ if configure failed as we would prefer to try
261 # configuring it next time round, rather than assuming it'll still fail.
262 # This is particularly important for bootlibs, where failure means the
263 # build dies!
264
265 # Build the library using 'make'
266 # We re-run 'setup makefile' each time, just in case any preprocessing
267 # needs to be done.  However, we're careful not to overwrite GNUmakefile
268 # if it hasn't changed, so that dependency-generation isn't forced
269 # every time.
270 $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR)):\
271 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
272                 cabal-bin ifBuildable/ifBuildable
273         if $(IFBUILDABLE) $*; then \
274           cd $* && \
275           cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
276           mv GNUmakefile GNUmakefile.tmp; \
277           $(CABAL) makefile -f GNUmakefile; \
278           cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
279           $(MAKE) $(MFLAGS) && \
280           $(CABAL) register --inplace; \
281         fi
282
283 # Special case for meta package dph: we can only remake it as we don't have
284 # any dependency info between the sub-packages
285 make.library.dph:
286         @echo "*** Please use the target 'remake.library.dph' instead"
287
288 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
289
290 # Build the library using 'setup build' (not the default)
291 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
292 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
293                  cabal-bin ifBuildable/ifBuildable
294         if $(IFBUILDABLE) $*; then \
295           cd $* && \
296           $(CABAL) build $(BUILD_FLAGS); \
297           $(CABAL) register --inplace; \
298         fi
299
300 .PHONY: doc html
301
302 html: doc
303
304 # No docs for compat libraries for now.
305 DOC_SUBDIRS = $(filter-out %-compat, $(SUBDIRS))
306
307 doc: $(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR))
308         sh gen_contents_index --inplace
309
310 # Making hyperlinked source only works if we have hscolour
311 ifeq "$(HSCOLOUR_SRCS)" "YES"
312 CABAL_HADDOCK_FLAGS += --hyperlink-source
313 endif
314 CABAL_HADDOCK_FLAGS += --with-haddock=$(FPTOOLS_TOP_ABS)/utils/haddock/install-inplace/bin/haddock
315
316 $(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR)):\
317 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
318                cabal-bin ifBuildable/ifBuildable
319         if $(IFBUILDABLE) $*; then \
320           cd $* && $(CABAL) haddock --html-location='../$$pkg' \
321                                     $(CABAL_HADDOCK_FLAGS); \
322         fi
323 ifneq "$(HSCOLOUR)" ""
324 # We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
325 # mismatch
326 # XXX We also need to check that the directory exists, as e.g. dph disables
327 # haddock, so the directory doesn't get made. We should remove this once
328 # we can always haddock everything.
329         if $(IFBUILDABLE) $* && [ -d $*/dist/doc/html/*/src/ ]; then cp hscolour.css $*/dist/doc/html/*/src/; fi
330 endif
331
332 .PHONY: maintainer-clean distclean clean clean.library.%
333
334 maintainer-clean: clean
335 distclean: clean
336
337 ifeq "$(DPH_SUBDIRS)" ""
338 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
339 else
340 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)) clean.library.dph
341 endif
342         -cd extensible-exceptions && $(CABAL) clean --distpref=dist-bootstrapping
343         -cd filepath              && $(CABAL) clean --distpref=dist-bootstrapping
344         -cd Cabal                 && $(CABAL) clean --distpref=dist-bootstrapping
345         -cd hpc                   && $(CABAL) clean --distpref=dist-bootstrapping
346         $(RM) -rf bootstrapping
347         $(RM) -f bootstrapping.conf     bootstrapping.conf.old
348         $(RM) -f bootstrapping.conf.tmp bootstrapping.conf.tmp.old
349         $(RM) -f cabal-bin cabal-bin.exe
350         $(RM) -rf ifBuildable
351         $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
352         $(RM) -f haddock* *.gif
353         $(RM) -rf stamp/*
354
355 maintainer-clean distclean:
356         $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
357
358 $(foreach SUBDIR,$(CLEAN_SUBDIRS),clean.library.$(SUBDIR)): \
359 clean.library.%:
360         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
361         -cd $* && $(CABAL) clean
362         $(RM) -f $*/Setup $*/Setup.exe $*/Setup.hi $*/Setup.o
363         $(RM) $*/GNUmakefile $*/Makefile.local
364 endif
365
366 # Extra target to clean all the sub-packages of dph
367 clean.library.dph: clean.library.dph/dph-prim-par \
368                 clean.library.dph/dph-prim-seq \
369                 clean.library.dph/dph-prim-interface \
370                 clean.library.dph/dph-base
371         $(MAKE) -C dph clean
372
373 # -----------------------------------------------------------------------------
374
375 .PHONY: install install-docs install.library.%
376
377 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
378 ifeq "$(HADDOCK_DOCS)" "YES"
379         $(INSTALL_DIR)                                                     $(DESTDIR)$(html_installed_root)
380         $(INSTALL_DATA)   index.html doc-index*.html                       $(DESTDIR)$(html_installed_root)
381         $(INSTALL_SCRIPT) gen_contents_index                               $(DESTDIR)$(html_installed_root)
382         $(INSTALL_DATA)   prologue.txt                                     $(DESTDIR)$(html_installed_root)
383         # Hacks:
384         $(INSTALL_DATA)   base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
385         $(INSTALL_DATA)   base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
386         $(INSTALL_DATA)   base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
387 endif
388
389 # Cabal doesn't let us ask to install docs only, so do nothing here
390 install-docs:
391         @:
392
393 # Ideally this would depend on a stamp/build.library.%, but if it does
394 # then we can't change the libraries and then just rerun make.
395 # Thus if you install without building then it will just break.
396
397 # prefix and (on Windows) htmldir use $topdir when configuring, so we
398 # need to tell installPackage the real path to use when installing.
399
400 # We also need to pass all the other directories in, as they can be
401 # overridden when installing a bindist.
402
403 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
404 install.library.%: ifBuildable/ifBuildable
405         if $(IFBUILDABLE) $*; then \
406           cd $* && \
407           $(INSTALL_PACKAGE) install '$(GHC_PKG_INSTALL_PROG)' '$(DESTDIR)$(datadir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' ; \
408         fi
409
410 .PHONY: binary-dist binary-dist.library.%
411
412 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
413
414 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
415 ifeq "$(WHERE_AM_I)" ""
416         echo "I don't know where I am" >&2
417         exit 1
418 endif
419         echo $(WHERE_AM_I)/Makefile >> $(BIN_DIST_LIST)
420 # XXX This needs to be changed: This ifBuildable is built with the
421 # bootstrapping compiler, so isn't OS X friendly. It should be made into
422 # a Cabal package if we keep it. However, once we drop extralibs we can
423 # probably remove it anyway.
424         echo $(WHERE_AM_I)/ifBuildable/ifBuildable >> $(BIN_DIST_LIST)
425         for FILE in dph/dph-prim-interface/interface/*.h dph/dph/LICENSE; do if [ -f $$FILE ]; then echo $(WHERE_AM_I)/$$FILE >> $(BIN_DIST_LIST); fi; done
426 ifeq "$(HADDOCK_DOCS)" "YES"
427         for FILE in gen_contents_index prologue.txt index.html doc-index*.html; do echo $(WHERE_AM_I)/$$FILE >> $(BIN_DIST_LIST); done
428 endif
429
430 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
431 binary-dist.library.%:
432         if $(IFBUILDABLE) $*; then \
433           $(MAKE) -C $* -f Makefile.local binary-dist BINDIST_EXTRAS="$*.cabal LICENSE $*.buildinfo unbuildable" WHERE_AM_I=$(WHERE_AM_I)/$*; \
434         fi
435
436 # Ignore some doc targets that we don't support
437 # The root recurses into us when these targets are made
438 .PHONY: html-no-chunks chm HxS fo dvi ps pdf
439 html-no-chunks chm HxS fo dvi ps pdf:
440         @:
441