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