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