8 # To rebuild a particular library <package>:
10 # make clean.library.<package>
11 # make make.library.<package>
13 # or the following is equivalent:
15 # make remake.library.<package>
17 # To add a new library to the tree, do
19 # darcs get http://darcs.haskell.org/packages/foo
20 # [ -f foo/configure.ac ] && ( cd foo && autoreconf )
21 # make make.library.foo
23 .PHONY: default_target
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.
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.
36 include $(TOP)/mk/boilerplate.mk
37 include $(TOP)/mk/cabal-flags.mk
39 # Any libraries listed here should also be in ../packages
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"
46 ifeq "$(Windows)" "YES"
47 SUBDIRS += $(wildcard Win32)
49 SUBDIRS += directory process pretty hpc template-haskell editline Cabal random haskell98
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
78 # -----------------------------------------------------------------------------
81 space=$(empty) $(empty)
83 # -----------------------------------------------------------------------------
85 ifeq "$(ghc_ge_609)" "YES"
86 GhcLibHcOpts += -fno-warn-deprecated-flags
89 IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/packages
91 ifneq "$(DOING_BIN_DIST)" "YES"
94 CONFIGURE_STAMP_EXTRAS :=
96 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
97 CONFIGURE_OPTS += --enable-library-profiling
98 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
101 ifeq "$(BuildSharedLibs)" "YES"
102 CONFIGURE_OPTS += --enable-shared
103 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
106 ifeq "$(SplitObjs)" "YES"
107 CONFIGURE_OPTS += --enable-split-objs
108 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
111 ifeq "$(HSCOLOUR_SRCS)" "YES"
112 CONFIGURE_OPTS += --with-hscolour="$(HSCOLOUR)"
120 HERE_ABS=$(FPTOOLS_TOP_ABS)/libraries
122 CABAL_GHC_FLAGS = -Wall
124 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
128 boot: ifBuildable/ifBuildable cabal-bin bootstrapping.conf
130 cabal-bin: cabal-bin.hs
132 $(GHC) $(BOOTSTRAPPING_FLAGS) --make cabal-bin -o cabal-bin
134 bootstrapping.conf: cabal-bin
136 -cd extensible-exceptions && $(CABAL) clean --distpref=dist-bootstrapping
137 cd extensible-exceptions && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
138 cd extensible-exceptions && $(CABAL) build --distpref=dist-bootstrapping
139 cd extensible-exceptions && $(CABAL) install --distpref=dist-bootstrapping --inplace
140 -cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
141 cd filepath && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
142 cd filepath && $(CABAL) build --distpref=dist-bootstrapping
143 cd filepath && $(CABAL) install --distpref=dist-bootstrapping --inplace
144 -cd Cabal && $(CABAL) clean --distpref=dist-bootstrapping
145 cd Cabal && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
146 cd Cabal && $(CABAL) build --distpref=dist-bootstrapping
147 cd Cabal && $(CABAL) install --distpref=dist-bootstrapping --inplace
148 -cd hpc && $(CABAL) clean --distpref=dist-bootstrapping
149 cd hpc && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
150 cd hpc && $(CABAL) build --distpref=dist-bootstrapping
151 cd hpc && $(CABAL) install --distpref=dist-bootstrapping --inplace
154 ifBuildable/ifBuildable: ifBuildable.hs
155 -$(RM) -rf ifBuildable
157 $(CP) ifBuildable.hs ifBuildable/
159 cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable
161 cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
164 .PHONY: all build configure
168 .PHONY: rebuild.library.%
169 .PHONY: remake.library.%
171 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
172 rebuild.library.%: clean.library.% build.library.%
174 $(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
175 remake.library.%: clean.library.% make.library.%
177 # NB. we're depending on make chasing dependencies from left to right here.
178 # This bit goes wrong with 'make -j'.
179 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
181 configure: $(foreach SUBDIR,$(SUBDIRS), \
182 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
184 .PHONY: build.library.%
185 .PHONY: make.library.%
187 # We should depend on %/%.cabal here (and in other rules), but make
188 # makes that difficult.
190 ALL_CONFIGURE_FLAGS = \
191 $(INSTALL_DIRS_CONFIGURE_FLAGS) \
192 $(USE_STAGE1_CONFIGURE_FLAGS) \
193 $(COMMON_CONFIGURE_FLAGS) \
194 --haddock-options="--use-contents=../index.html \
195 --use-index=../doc-index.html" \
198 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-par: \
201 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-seq: \
207 $(foreach SUBDIR,$(SUBDIRS), \
208 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
209 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: cabal-bin
210 -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
211 $(MKDIRHIER) `dirname $@`
212 ( cd $* && $(CABAL) configure $(ALL_CONFIGURE_FLAGS) ) \
213 && touch $@ || touch $*/unbuildable
214 # We don't touch $@ if configure failed as we would prefer to try
215 # configuring it next time round, rather than assuming it'll still fail.
216 # This is particularly important for bootlibs, where failure means the
219 # Build the library using 'make'
220 # We re-run 'setup makefile' each time, just in case any preprocessing
221 # needs to be done. However, we're careful not to overwrite GNUmakefile
222 # if it hasn't changed, so that dependency-generation isn't forced
224 $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR)):\
225 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
226 cabal-bin ifBuildable/ifBuildable
227 if $(IFBUILDABLE) $*; then \
229 cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
230 mv GNUmakefile GNUmakefile.tmp; \
231 $(CABAL) makefile -f GNUmakefile; \
232 cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
233 $(MAKE) $(MFLAGS) && \
234 $(CABAL) register --inplace; \
237 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
239 # Build the library using 'setup build' (not the default)
240 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
241 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
242 cabal-bin ifBuildable/ifBuildable
243 if $(IFBUILDABLE) $*; then \
245 $(CABAL) build $(BUILD_FLAGS); \
246 $(CABAL) register --inplace; \
253 # No docs for compat libraries for now.
254 DOC_SUBDIRS = $(filter-out %-compat, $(SUBDIRS))
256 doc: $(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR))
257 sh gen_contents_index --inplace
259 # Making hyperlinked source only works if we have hscolour
260 ifeq "$(HSCOLOUR_SRCS)" "YES"
261 CABAL_HADDOCK_FLAGS += --hyperlink-source
263 CABAL_HADDOCK_FLAGS += --with-haddock=$(FPTOOLS_TOP_ABS)/utils/haddock/install-inplace/bin/haddock
265 $(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR)):\
266 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
267 cabal-bin ifBuildable/ifBuildable
268 if $(IFBUILDABLE) $*; then \
269 cd $* && $(CABAL) haddock --html-location='../$$pkg' \
270 $(CABAL_HADDOCK_FLAGS); \
272 ifneq "$(HSCOLOUR)" ""
273 # We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
275 # XXX We also need to check that the directory exists, as e.g. dph disables
276 # haddock, so the directory doesn't get made. We should remove this once
277 # we can always haddock everything.
278 if $(IFBUILDABLE) $* && [ -d $*/dist/doc/html/*/src/ ]; then cp hscolour.css $*/dist/doc/html/*/src/; fi
281 .PHONY: maintainer-clean distclean clean clean.library.%
283 maintainer-clean: clean
286 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
287 -cd extensible-exceptions && $(CABAL) clean --distpref=dist-bootstrapping
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
299 ifneq "$(wildcard dph)" ""
303 maintainer-clean distclean:
304 $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
306 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
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
314 # -----------------------------------------------------------------------------
316 .PHONY: install install-docs install.library.%
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 $(INSTALL_DATA) prologue.txt $(DESTDIR)$(html_installed_root)
325 $(INSTALL_DATA) base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
326 $(INSTALL_DATA) base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
327 $(INSTALL_DATA) base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
330 # Cabal doesn't let us ask to install docs only, so do nothing here
334 # Ideally this would depend on a stamp/build.library.%, but if it does
335 # then we can't change the libraries and then just rerun make.
336 # Thus if you install without building then it will just break.
338 # prefix and (on Windows) htmldir use $topdir when configuring, so we
339 # need to tell installPackage the real path to use when installing.
341 # We also need to pass all the other directories in, as they can be
342 # overridden when installing a bindist.
344 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
345 install.library.%: ifBuildable/ifBuildable
346 if $(IFBUILDABLE) $*; then \
348 $(INSTALL_PACKAGE) install '$(GHC_PKG_INSTALL_PROG)' '$(DESTDIR)$(datadir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' ; \
351 .PHONY: binary-dist binary-dist.library.%
353 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
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
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 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
367 ifeq "$(HADDOCK_DOCS)" "YES"
368 for FILE in gen_contents_index prologue.txt index.html doc-index*.html; do echo $(WHERE_AM_I)/$$FILE >> $(BIN_DIST_LIST); done
371 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
372 binary-dist.library.%:
373 if $(IFBUILDABLE) $*; then \
374 $(MAKE) -C $* -f Makefile.local binary-dist BINDIST_EXTRAS="$*.cabal LICENSE $*.buildinfo unbuildable" WHERE_AM_I=$(WHERE_AM_I)/$*; \
377 # Ignore some doc targets that we don't support
378 # The root recurses into us when these targets are made
379 .PHONY: html-no-chunks chm HxS fo dvi ps pdf
380 html-no-chunks chm HxS fo dvi ps pdf: