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 # [ -e foo/configure.ac ] && ( cd foo && autoreconf )
21 # make make.library.foo
23 .PHONY: default_target show
28 @echo '$(VALUE)="$($(VALUE))"'
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.
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.
39 include $(TOP)/mk/boilerplate.mk
40 include $(TOP)/mk/cabal-flags.mk
42 # Any libraries listed here should also be in ../packages
44 SUBDIRS = ghc-prim $(INTEGER_LIBRARY) base base3-compat array packedstring
45 SUBDIRS += containers bytestring old-locale old-time filepath directory
46 ifeq "$(GhcLibsWithUnix)" "YES"
49 ifeq "$(Windows)" "YES"
50 SUBDIRS += $(wildcard Win32)
52 SUBDIRS += process pretty hpc template-haskell editline Cabal random haskell98
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
81 # -----------------------------------------------------------------------------
84 space=$(empty) $(empty)
86 # -----------------------------------------------------------------------------
88 ifeq "$(ghc_ge_609)" "YES"
89 GhcLibHcOpts += -fno-warn-deprecated-flags
92 ifeq "$(RelocatableBuild)" "YES"
93 # On Windows we want to make moveable bindists, but we need to tell
94 # ghc-pkg where the haddock docs are. Therefore we completely ignore
95 # where the user tells us to put the haddock documentation and put it
96 # somewhere whose relative location we know. When installing we need
97 # to give Cabal a real path, though.
101 ilibexecdir = $$topdir
102 idynlibdir = $$topdir
104 idocdir = $$topdir/doc/libraries/$$pkg
105 ihaddockdir = $$topdir/doc/libraries/$$pkg
106 ihtmldir = $$httptopdir/doc/libraries/$$pkg
107 html_installed_root = $(prefix)/doc/libraries
109 # On non-Windows we can just give absolute paths all the time, and
110 # thus obey the htmldir that we are given.
114 ilibexecdir = $(libexecdir)
115 idynlibdir = $(dynlibdir)
116 idatadir = $(datadir)
117 idocdir = $(docdir)/libraries/$$pkg
118 ihaddockdir = $(htmldir)/libraries/$$pkg
119 ihtmldir = $(htmldir)/libraries/$$pkg
120 html_installed_root = $(htmldir)/libraries
123 IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/packages
125 ifneq "$(DOING_BIN_DIST)" "YES"
128 CONFIGURE_STAMP_EXTRAS :=
130 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
131 CONFIGURE_OPTS += --enable-library-profiling
132 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
135 ifeq "$(BuildSharedLibs)" "YES"
136 CONFIGURE_OPTS += --enable-shared
137 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
140 ifeq "$(SplitObjs)" "YES"
141 CONFIGURE_OPTS += --enable-split-objs
142 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
150 HERE_ABS=$(FPTOOLS_TOP_ABS)/libraries
152 CABAL_GHC_FLAGS = -Wall
153 ifeq "$(ghc_ge_605)" "NO"
154 CABAL_GHC_FLAGS += -cpp
157 # Euch, hideous hack:
158 CABAL_VERSION = $(shell grep "^Version:" Cabal/Cabal.cabal | sed -e "s/^Version: //" -e 's/\./,/g')
160 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
164 boot: ifBuildable/ifBuildable cabal-bin bootstrapping.conf
166 cabal-bin: cabal-bin.hs
168 $(GHC) $(BOOTSTRAPPING_FLAGS) --make cabal-bin -o cabal-bin
170 bootstrapping.conf: cabal-bin
172 -cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
173 cd filepath && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
174 cd filepath && $(CABAL) build --distpref=dist-bootstrapping
175 cd filepath && $(CABAL) install --distpref=dist-bootstrapping --inplace
176 -cd Cabal && $(CABAL) clean --distpref=dist-bootstrapping
177 cd Cabal && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
178 cd Cabal && $(CABAL) build --distpref=dist-bootstrapping
179 cd Cabal && $(CABAL) install --distpref=dist-bootstrapping --inplace
180 -cd hpc && $(CABAL) clean --distpref=dist-bootstrapping
181 cd hpc && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
182 cd hpc && $(CABAL) build --distpref=dist-bootstrapping
183 cd hpc && $(CABAL) install --distpref=dist-bootstrapping --inplace
186 ifBuildable/ifBuildable: ifBuildable.hs
187 -$(RM) -rf ifBuildable
189 $(CP) ifBuildable.hs ifBuildable/
191 cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable
193 cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
196 .PHONY: all build configure
200 ifeq "$(HADDOCK_DOCS)" "YES"
204 .PHONY: rebuild.library.%
205 .PHONY: remake.library.%
207 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
208 rebuild.library.%: clean.library.% build.library.%
210 $(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
211 remake.library.%: clean.library.% make.library.%
213 # NB. we're depending on make chasing dependencies from left to right here.
214 # This bit goes wrong with 'make -j'.
215 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
217 configure: $(foreach SUBDIR,$(SUBDIRS), \
218 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
220 .PHONY: build.library.%
221 .PHONY: make.library.%
223 # We should depend on %/%.cabal here (and in other rules), but make
224 # makes that difficult.
226 ALL_CONFIGURE_FLAGS = \
227 $(INSTALL_DIRS_CONFIGURE_FLAGS) \
228 $(USE_STAGE1_CONFIGURE_FLAGS) \
229 $(COMMON_CONFIGURE_FLAGS) \
230 --haddock-options="--use-contents=../index.html \
231 --use-index=../doc-index.html" \
234 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-par: \
237 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-seq: \
240 .PHONY: dph-create_par create_dph-seq
242 create_dph-par create_dph-seq: create_%:
245 $(foreach SUBDIR,$(SUBDIRS), \
246 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
247 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: cabal-bin \
249 -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
250 $(MKDIRHIER) `dirname $@`
251 ( cd $* && $(CABAL) configure $(ALL_CONFIGURE_FLAGS) ) \
252 && touch $@ || touch $*/unbuildable
253 # We don't touch $@ if configure failed as we would prefer to try
254 # configuring it next time round, rather than assuming it'll still fail.
255 # This is particularly important for bootlibs, where failure means the
258 # Build the library using 'make'
259 # We re-run 'setup makefile' each time, just in case any preprocessing
260 # needs to be done. However, we're careful not to overwrite GNUmakefile
261 # if it hasn't changed, so that dependency-generation isn't forced
263 $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR)):\
264 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
265 cabal-bin ifBuildable/ifBuildable bootstrapping.conf
266 if $(IFBUILDABLE) $*; then \
268 cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
269 mv GNUmakefile GNUmakefile.tmp; \
270 $(CABAL) makefile -f GNUmakefile; \
271 cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
272 $(MAKE) $(MFLAGS) && \
273 $(CABAL) register --inplace; \
276 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
278 # Build the library using 'setup build' (not the default)
279 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
280 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
281 cabal-bin ifBuildable/ifBuildable bootstrapping.conf
282 if $(IFBUILDABLE) $*; then \
284 $(CABAL) build $(BUILD_FLAGS); \
285 $(CABAL) register --inplace; \
292 # No docs for compat libraries for now.
293 DOC_SUBDIRS = $(filter-out %-compat, $(SUBDIRS))
295 doc: $(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR))
296 sh gen_contents_index --inplace
298 # Making hyperlinked source only works if we have hscolour
299 ifneq "$(HSCOLOUR)" ""
300 CABAL_HADDOCK_FLAGS=--hyperlink-source
303 $(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR)):\
304 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
305 cabal-bin ifBuildable/ifBuildable bootstrapping.conf
306 if $(IFBUILDABLE) $*; then \
307 cd $* && $(CABAL) haddock --html-location='../$$pkg' \
308 $(CABAL_HADDOCK_FLAGS); \
310 ifneq "$(HSCOLOUR)" ""
311 # We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
313 # XXX We also need to check that the directory exists, as e.g. dph disables
314 # haddock, so the directory doesn't get made. We should remove this once
315 # we can always haddock everything.
316 if $(IFBUILDABLE) $* && [ -d $*/dist/doc/html/*/src/ ]; then cp hscolour.css $*/dist/doc/html/*/src/; fi
319 .PHONY: distclean clean clean.library.%
323 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
324 -cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
325 -cd Cabal && $(CABAL) clean --distpref=dist-bootstrapping
326 -cd hpc && $(CABAL) clean --distpref=dist-bootstrapping
327 $(RM) -rf bootstrapping
328 $(RM) -f bootstrapping.conf bootstrapping.conf.old
329 $(RM) -f bootstrapping.conf.tmp bootstrapping.conf.tmp.old
330 $(RM) -f cabal-bin cabal-bin.exe
331 $(RM) -rf ifBuildable
332 $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
333 $(RM) -f haddock* *.gif
335 ifneq "$(wildcard dph)" ""
340 $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
342 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
344 $(RM) -f stamp/configure.library.*.$* $*/unbuildable
345 -cd $* && $(CABAL) clean
346 $(RM) -f $*/Setup $*/Setup.exe $*/Setup.hi $*/Setup.o
347 $(RM) $*/GNUmakefile $*/Makefile.local
350 # -----------------------------------------------------------------------------
352 .PHONY: install install-docs install.library.%
354 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
355 ifeq "$(HADDOCK_DOCS)" "YES"
356 $(INSTALL_DIR) $(DESTDIR)$(html_installed_root)
357 $(INSTALL_DATA) index.html doc-index*.html $(DESTDIR)$(html_installed_root)
358 $(INSTALL_SCRIPT) gen_contents_index $(DESTDIR)$(html_installed_root)
360 $(INSTALL_DATA) base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
361 $(INSTALL_DATA) base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
362 $(INSTALL_DATA) base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
365 # Cabal doesn't let us ask to install docs only, so do nothing here
369 # Ideally this would depend on a stamp/build.library.%, but if it does
370 # then we can't change the libraries and then just rerun make.
371 # Thus if you install without building then it will just break.
373 # prefix and (on Windows) htmldir use $topdir when configuring, so we
374 # need to tell installPackage the real path to use when installing.
376 # We also need to pass all the other directories in, as they can be
377 # overridden when installing a bindist.
379 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
380 install.library.%: ifBuildable/ifBuildable
381 if $(IFBUILDABLE) $*; then \
383 $(INSTALL_PACKAGE) install '$(DESTDIR)$(bindir)/ghc-pkg' '$(DESTDIR)$(datadir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' ; \
386 .PHONY: binary-dist binary-dist.library.%
388 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
390 BINDIST_EXTRAS += ifBuildable/ifBuildable
391 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
392 echo $(WHERE_AM_I)/Makefile >> $(BIN_DIST_LIST)
393 # XXX This needs to be changed: This ifBuildable is built with the
394 # bootstrapping compiler, so isn't OS X friendly. It should be made into
395 # a Cabal package if we keep it. However, once we drop extralibs we can
396 # probably remove it anyway.
397 echo $(WHERE_AM_I)/ifBuildable/ifBuildable >> $(BIN_DIST_LIST)
398 ifeq "$(HADDOCK_DOCS)" "YES"
399 for FILE in gen_contents_index index.html doc-index*.html; do echo $(WHERE_AM_I)/$$FILE >> $(BIN_DIST_LIST); done
402 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
403 binary-dist.library.%:
404 if $(IFBUILDABLE) $*; then \
405 $(MAKE) -C $* -f Makefile.local binary-dist BINDIST_EXTRAS="$*.cabal LICENSE $*.buildinfo unbuildable" WHERE_AM_I=$(WHERE_AM_I)/$*; \
408 # Ignore some doc targets that we don't support
409 # The root recurses into us when these targets are made
410 .PHONY: html-no-chunks chm HxS fo dvi ps pdf
411 html-no-chunks chm HxS fo dvi ps pdf: