Install the stage 2 ghc package when installing; fixes trac #2567
[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 include $(TOP)/mk/cabal-flags.mk
41
42 # Any libraries listed here should also be in ../packages
43
44 SUBDIRS  = ghc-prim $(INTEGER_LIBRARY) base syb base3-compat array packedstring
45 SUBDIRS += containers bytestring old-locale old-time filepath 
46 ifeq "$(GhcLibsWithUnix)" "YES"
47 SUBDIRS += unix
48 endif
49 ifeq "$(Windows)" "YES"
50 SUBDIRS += $(wildcard Win32)
51 endif
52 SUBDIRS += directory process pretty hpc template-haskell editline Cabal random haskell98
53
54 # Set GhcBootLibs=YES from the command line to work with just the libraries
55 # needed to bootstrap GHC.
56 ifneq "$(GhcBootLibs)" "YES"
57 SUBDIRS += $(wildcard regex-base)
58 SUBDIRS += $(wildcard regex-posix)
59 SUBDIRS += $(wildcard regex-compat)
60 SUBDIRS += $(wildcard parsec)
61 SUBDIRS += $(wildcard haskell-src)
62 SUBDIRS += $(wildcard html)
63 SUBDIRS += $(wildcard network)
64 SUBDIRS += $(wildcard QuickCheck)
65 SUBDIRS += $(wildcard HUnit)
66 SUBDIRS += $(wildcard mtl)
67 SUBDIRS += $(wildcard time)
68 SUBDIRS += $(wildcard stm)
69 SUBDIRS += $(wildcard xhtml)
70 SUBDIRS += $(wildcard parallel)
71 ifneq "$(wildcard dph)" ""
72 SUBDIRS += dph/dph-base
73 SUBDIRS += dph/dph-prim-interface
74 SUBDIRS += dph/dph-prim-seq
75 SUBDIRS += dph/dph-prim-par
76 SUBDIRS += dph/dph-seq
77 SUBDIRS += dph/dph-par
78 endif
79 endif
80
81 # -----------------------------------------------------------------------------
82
83 empty=
84 space=$(empty) $(empty)
85
86 # -----------------------------------------------------------------------------
87
88 ifeq "$(ghc_ge_609)" "YES"
89 GhcLibHcOpts += -fno-warn-deprecated-flags
90 endif
91
92 IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/packages
93
94 ifneq "$(DOING_BIN_DIST)" "YES"
95
96 CONFIGURE_OPTS =
97 CONFIGURE_STAMP_EXTRAS :=
98
99 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
100 CONFIGURE_OPTS += --enable-library-profiling
101 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
102 endif
103
104 ifeq "$(BuildSharedLibs)" "YES"
105 CONFIGURE_OPTS += --enable-shared
106 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
107 endif
108
109 ifeq "$(SplitObjs)" "YES"
110 CONFIGURE_OPTS += --enable-split-objs
111 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
112 endif
113
114 .PHONY: subdirs
115
116 subdirs:
117         @echo $(SUBDIRS)
118
119 HERE_ABS=$(FPTOOLS_TOP_ABS)/libraries
120
121 CABAL_GHC_FLAGS = -Wall
122 ifeq "$(ghc_ge_605)" "NO"
123 CABAL_GHC_FLAGS += -cpp
124 endif
125
126 # Euch, hideous hack:
127 CABAL_VERSION = $(shell grep "^Version:" Cabal/Cabal.cabal | sed -e "s/^Version: //" -e 's/\./,/g')
128
129 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
130
131 .PHONY: boot
132
133 boot: ifBuildable/ifBuildable cabal-bin bootstrapping.conf
134
135 cabal-bin: cabal-bin.hs
136         -mkdir bootstrapping
137         $(GHC) $(BOOTSTRAPPING_FLAGS) --make cabal-bin -o cabal-bin
138
139 bootstrapping.conf: cabal-bin
140         echo "[]" > $@.tmp
141         -cd filepath && $(CABAL) clean     --distpref=dist-bootstrapping
142         cd filepath && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
143         cd filepath && $(CABAL) build     --distpref=dist-bootstrapping
144         cd filepath && $(CABAL) install   --distpref=dist-bootstrapping --inplace
145         -cd Cabal    && $(CABAL) clean     --distpref=dist-bootstrapping
146         cd Cabal    && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
147         cd Cabal    && $(CABAL) build     --distpref=dist-bootstrapping
148         cd Cabal    && $(CABAL) install   --distpref=dist-bootstrapping --inplace
149         -cd hpc    && $(CABAL) clean     --distpref=dist-bootstrapping
150         cd hpc    && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
151         cd hpc    && $(CABAL) build     --distpref=dist-bootstrapping
152         cd hpc    && $(CABAL) install   --distpref=dist-bootstrapping --inplace
153         mv $@.tmp $@
154
155 ifBuildable/ifBuildable: ifBuildable.hs
156         -$(RM) -rf ifBuildable
157         mkdir ifBuildable
158         $(CP) ifBuildable.hs ifBuildable/
159 ifeq "$(stage)" "2"
160         cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable
161 else
162         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
163 endif
164
165 .PHONY: all build configure
166
167 all: build
168
169 .PHONY: rebuild.library.%
170 .PHONY: remake.library.%
171
172 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
173 rebuild.library.%: clean.library.% build.library.%
174
175 $(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
176 remake.library.%: clean.library.% make.library.%
177
178 # NB. we're depending on make chasing dependencies from left to right here.
179 # This bit goes wrong with 'make -j'.
180 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
181
182 configure: $(foreach SUBDIR,$(SUBDIRS), \
183              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
184
185 .PHONY: build.library.%
186 .PHONY: make.library.%
187
188 # We should depend on %/%.cabal here (and in other rules), but make
189 # makes that difficult.
190
191 ALL_CONFIGURE_FLAGS = \
192                $(INSTALL_DIRS_CONFIGURE_FLAGS) \
193                $(USE_STAGE1_CONFIGURE_FLAGS) \
194                $(COMMON_CONFIGURE_FLAGS) \
195                    --haddock-options="--use-contents=../index.html \
196                                       --use-index=../doc-index.html" \
197                    $(CONFIGURE_OPTS)
198
199 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-par: \
200     dph/dph-par
201
202 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-seq: \
203     dph/dph-seq
204
205 dph/%:
206         $(MAKE) -C dph $*
207
208 $(foreach SUBDIR,$(SUBDIRS), \
209                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
210 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: cabal-bin \
211                                                           bootstrapping.conf
212         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
213         $(MKDIRHIER) `dirname $@`
214         ( cd $* && $(CABAL) configure $(ALL_CONFIGURE_FLAGS) ) \
215               && touch $@ || touch $*/unbuildable
216 # We don't touch $@ if configure failed as we would prefer to try
217 # configuring it next time round, rather than assuming it'll still fail.
218 # This is particularly important for bootlibs, where failure means the
219 # build dies!
220
221 # Build the library using 'make'
222 # We re-run 'setup makefile' each time, just in case any preprocessing
223 # needs to be done.  However, we're careful not to overwrite GNUmakefile
224 # if it hasn't changed, so that dependency-generation isn't forced
225 # every time.
226 $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR)):\
227 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
228                 cabal-bin ifBuildable/ifBuildable bootstrapping.conf
229         if $(IFBUILDABLE) $*; then \
230           cd $* && \
231           cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
232           mv GNUmakefile GNUmakefile.tmp; \
233           $(CABAL) makefile -f GNUmakefile; \
234           cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
235           $(MAKE) $(MFLAGS) && \
236           $(CABAL) register --inplace; \
237         fi
238
239 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
240
241 # Build the library using 'setup build' (not the default)
242 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
243 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
244                  cabal-bin ifBuildable/ifBuildable bootstrapping.conf
245         if $(IFBUILDABLE) $*; then \
246           cd $* && \
247           $(CABAL) build $(BUILD_FLAGS); \
248           $(CABAL) register --inplace; \
249         fi
250
251 .PHONY: doc html
252
253 html: doc
254
255 # No docs for compat libraries for now.
256 DOC_SUBDIRS = $(filter-out %-compat, $(SUBDIRS))
257
258 doc: $(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR))
259         sh gen_contents_index --inplace
260
261 # Making hyperlinked source only works if we have hscolour
262 ifneq "$(HSCOLOUR)" ""
263 CABAL_HADDOCK_FLAGS += --hyperlink-source
264 endif
265 CABAL_HADDOCK_FLAGS += --with-haddock=$(FPTOOLS_TOP_ABS)/utils/haddock/install-inplace/bin/haddock
266
267 $(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR)):\
268 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
269                cabal-bin ifBuildable/ifBuildable bootstrapping.conf
270         if $(IFBUILDABLE) $*; then \
271           cd $* && $(CABAL) haddock --html-location='../$$pkg' \
272                                     $(CABAL_HADDOCK_FLAGS); \
273         fi
274 ifneq "$(HSCOLOUR)" ""
275 # We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
276 # mismatch
277 # XXX We also need to check that the directory exists, as e.g. dph disables
278 # haddock, so the directory doesn't get made. We should remove this once
279 # we can always haddock everything.
280         if $(IFBUILDABLE) $* && [ -d $*/dist/doc/html/*/src/ ]; then cp hscolour.css $*/dist/doc/html/*/src/; fi
281 endif
282
283 .PHONY: distclean clean clean.library.%
284
285 distclean: clean
286
287 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
288         -cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
289         -cd Cabal    && $(CABAL) clean --distpref=dist-bootstrapping
290         -cd hpc      && $(CABAL) clean --distpref=dist-bootstrapping
291         $(RM) -rf bootstrapping
292         $(RM) -f bootstrapping.conf     bootstrapping.conf.old
293         $(RM) -f bootstrapping.conf.tmp bootstrapping.conf.tmp.old
294         $(RM) -f cabal-bin cabal-bin.exe
295         $(RM) -rf ifBuildable
296         $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
297         $(RM) -f haddock* *.gif
298         $(RM) -rf stamp/*
299 ifneq "$(wildcard dph)" ""
300         $(MAKE) -C dph clean
301 endif
302
303 distclean:
304         $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
305
306 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
307 clean.library.%:
308         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
309         -cd $* && $(CABAL) clean
310         $(RM) -f $*/Setup $*/Setup.exe $*/Setup.hi $*/Setup.o
311         $(RM) $*/GNUmakefile $*/Makefile.local
312 endif
313
314 # -----------------------------------------------------------------------------
315
316 .PHONY: install install-docs install.library.%
317
318 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
319 ifeq "$(HADDOCK_DOCS)" "YES"
320         $(INSTALL_DIR)                                                     $(DESTDIR)$(html_installed_root)
321         $(INSTALL_DATA)   index.html doc-index*.html                       $(DESTDIR)$(html_installed_root)
322         $(INSTALL_SCRIPT) gen_contents_index                               $(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 BINDIST_EXTRAS += ifBuildable/ifBuildable
355 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
356 ifeq "$(WHERE_AM_I)" ""
357         echo "I don't know where I am" >&2
358         exit 1
359 endif
360         echo $(WHERE_AM_I)/Makefile >> $(BIN_DIST_LIST)
361 # XXX This needs to be changed: This ifBuildable is built with the
362 # bootstrapping compiler, so isn't OS X friendly. It should be made into
363 # a Cabal package if we keep it. However, once we drop extralibs we can
364 # probably remove it anyway.
365         echo $(WHERE_AM_I)/ifBuildable/ifBuildable >> $(BIN_DIST_LIST)
366 ifeq "$(HADDOCK_DOCS)" "YES"
367         for FILE in gen_contents_index 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