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