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 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 cgi)
71 SUBDIRS += $(wildcard parallel)
72 SUBDIRS_BUILD += $(wildcard dph/dph-base)
73 SUBDIRS_BUILD += $(wildcard dph/dph-prim-interface)
74 SUBDIRS_BUILD += $(wildcard dph/dph-prim-seq)
75 SUBDIRS_BUILD += $(wildcard dph/dph-prim-par)
76 SUBDIRS_BUILD += $(wildcard dph/dph)
79 SUBDIRS += $(SUBDIRS_BUILD)
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 ifneq "$(DOING_BIN_DIST)" "YES"
126 CONFIGURE_STAMP_EXTRAS :=
128 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
129 CONFIGURE_OPTS += --enable-library-profiling
130 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
133 ifeq "$(BuildSharedLibs)" "YES"
134 CONFIGURE_OPTS += --enable-shared
135 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
138 ifeq "$(SplitObjs)" "YES"
139 CONFIGURE_OPTS += --enable-split-objs
140 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
148 HERE_ABS=$(FPTOOLS_TOP_ABS)/libraries
150 IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/packages
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
167 $(GHC) $(BOOTSTRAPPING_FLAGS) --make cabal-bin -o cabal-bin
169 bootstrapping.conf: cabal-bin
171 -cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
172 cd filepath && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
173 cd filepath && $(CABAL) build --distpref=dist-bootstrapping
174 cd filepath && $(CABAL) install --distpref=dist-bootstrapping --inplace
175 -cd Cabal && $(CABAL) clean --distpref=dist-bootstrapping
176 cd Cabal && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
177 cd Cabal && $(CABAL) build --distpref=dist-bootstrapping
178 cd Cabal && $(CABAL) install --distpref=dist-bootstrapping --inplace
179 -cd hpc && $(CABAL) clean --distpref=dist-bootstrapping
180 cd hpc && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
181 cd hpc && $(CABAL) build --distpref=dist-bootstrapping
182 cd hpc && $(CABAL) install --distpref=dist-bootstrapping --inplace
185 ifBuildable/ifBuildable: ifBuildable.hs
186 -$(RM) -rf ifBuildable
188 $(CP) ifBuildable.hs ifBuildable/
190 cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable
192 cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
195 .PHONY: all build configure
199 ifeq "$(HADDOCK_DOCS)" "YES"
203 .PHONY: rebuild.library.%
204 .PHONY: remake.library.%
206 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
207 rebuild.library.%: clean.library.% build.library.%
209 $(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
210 remake.library.%: clean.library.% make.library.%
212 # NB. we're depending on make chasing dependencies from left to right here.
213 # This bit goes wrong with 'make -j'.
214 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
216 configure: $(foreach SUBDIR,$(SUBDIRS), \
217 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
219 .PHONY: build.library.%
220 .PHONY: make.library.%
222 # We should depend on %/%.cabal here (and in other rules), but make
223 # makes that difficult.
225 ALL_CONFIGURE_FLAGS = \
226 $(INSTALL_DIRS_CONFIGURE_FLAGS) \
227 $(USE_STAGE1_CONFIGURE_FLAGS) \
228 $(COMMON_CONFIGURE_FLAGS) \
229 --haddock-options="--use-contents=../index.html \
230 --use-index=../doc-index.html" \
233 $(foreach SUBDIR,$(SUBDIRS), \
234 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
235 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: cabal-bin \
237 -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
238 $(MKDIRHIER) `dirname $@`
239 ( cd $* && $(CABAL) configure $(ALL_CONFIGURE_FLAGS) ) \
240 && touch $@ || touch $*/unbuildable
241 # We don't touch $@ if configure failed as we would prefer to try
242 # configuring it next time round, rather than assuming it'll still fail.
243 # This is particularly important for bootlibs, where failure means the
246 # Build the library using 'make'
247 # We re-run 'setup makefile' each time, just in case any preprocessing
248 # needs to be done. However, we're careful not to overwrite GNUmakefile
249 # if it hasn't changed, so that dependency-generation isn't forced
251 # Packages in $(SUBDIRS_BUILD) need to use the build.* rules instead of
252 # make.*, so filter them out and use an alternate rule below instead.
253 $(foreach SUBDIR,$(filter-out $(SUBDIRS_BUILD),$(SUBDIRS)),make.library.$(SUBDIR)):\
254 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
255 cabal-bin ifBuildable/ifBuildable bootstrapping.conf
256 if $(IFBUILDABLE) $*; then \
258 cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
259 mv GNUmakefile GNUmakefile.tmp; \
260 $(CABAL) makefile -f GNUmakefile; \
261 cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
262 $(MAKE) $(MFLAGS) && \
263 $(CABAL) register --inplace; \
266 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
268 # Alternate rule, as described above
269 $(foreach SUBDIR,$(SUBDIRS_BUILD),make.library.$(SUBDIR)):\
270 make.library.%: build.library.%
272 # Build the library using 'setup build' (not the default)
273 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
274 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
275 cabal-bin ifBuildable/ifBuildable bootstrapping.conf
276 if $(IFBUILDABLE) $*; then \
278 $(CABAL) build $(BUILD_FLAGS); \
279 $(CABAL) register --inplace; \
286 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
287 sh gen_contents_index --inplace
289 # Making hyperlinked source only works if we have hscolour
290 ifneq "$(HSCOLOUR)" ""
291 CABAL_HADDOCK_FLAGS=--hyperlink-source
294 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
295 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
296 cabal-bin ifBuildable/ifBuildable bootstrapping.conf
297 if $(IFBUILDABLE) $*; then \
298 cd $* && $(CABAL) haddock --html-location='../$$pkg' \
299 $(CABAL_HADDOCK_FLAGS); \
301 ifneq "$(HSCOLOUR)" ""
302 # We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
304 if $(IFBUILDABLE) $*; then cp hscolour.css $*/dist/doc/html/*/src/; fi
307 .PHONY: distclean clean clean.library.%
311 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
312 -cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
313 -cd Cabal && $(CABAL) clean --distpref=dist-bootstrapping
314 -cd hpc && $(CABAL) clean --distpref=dist-bootstrapping
315 $(RM) -rf bootstrapping/*
316 $(RM) -f bootstrapping.conf bootstrapping.conf.old
317 $(RM) -f bootstrapping.conf.tmp bootstrapping.conf.tmp.old
318 $(RM) -f cabal-bin cabal-bin.exe
319 $(RM) -rf ifBuildable
320 $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
321 $(RM) -f haddock* *.gif
324 $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
326 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
328 $(RM) -f stamp/configure.library.*.$* $*/unbuildable
329 -cd $* && $(CABAL) clean
330 $(RM) -f $*/Setup $*/Setup.exe $*/Setup.hi $*/Setup.o
331 $(RM) $*/GNUmakefile $*/Makefile.local
334 # -----------------------------------------------------------------------------
336 .PHONY: install install-docs install.library.%
338 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
339 ifeq "$(HADDOCK_DOCS)" "YES"
340 $(INSTALL_DIR) $(DESTDIR)$(html_installed_root)
341 $(INSTALL_DATA) index.html doc-index*.html $(DESTDIR)$(html_installed_root)
342 $(INSTALL_SCRIPT) gen_contents_index $(DESTDIR)$(html_installed_root)
344 $(INSTALL_DATA) base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
345 $(INSTALL_DATA) base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
346 $(INSTALL_DATA) base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
349 # Cabal doesn't let us ask to install docs only, so do nothing here
353 # Ideally this would depend on a stamp/build.library.%, but if it does
354 # then we can't change the libraries and then just rerun make.
355 # Thus if you install without building then it will just break.
357 # prefix and (on Windows) htmldir use $topdir when configuring, so we
358 # need to tell installPackage the real path to use when installing.
360 # We also need to pass all the other directories in, as they can be
361 # overridden when installing a bindist.
363 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
364 install.library.%: ifBuildable/ifBuildable
365 if $(IFBUILDABLE) $*; then \
367 $(INSTALL_PACKAGE) install '$(GHC_PKG_PROG)' '$(DESTDIR)$(libdir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' ; \
370 .PHONY: binary-dist binary-dist.library.%
372 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
374 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
375 mkdir $(BIN_DIST_LIBDIR)/ifBuildable
376 cp ifBuildable/ifBuildable $(BIN_DIST_LIBDIR)/ifBuildable
377 cp Makefile $(BIN_DIST_LIBDIR)
378 ifeq "$(HADDOCK_DOCS)" "YES"
379 cp gen_contents_index $(BIN_DIST_LIBDIR)
380 cp index.html $(BIN_DIST_LIBDIR)
381 cp doc-index*.html $(BIN_DIST_LIBDIR)
383 cp -pR stamp $(BIN_DIST_LIBDIR)
385 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
386 binary-dist.library.%:
387 if $(IFBUILDABLE) $*; then \
388 $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*; \
390 cp $*.cabal $(BIN_DIST_LIBDIR)/$* && \
391 cp LICENSE $(BIN_DIST_LIBDIR)/$* && \
392 cp -R dist $(BIN_DIST_LIBDIR)/$* && \
393 $(FIND) . -name "*.buildinfo" -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
394 $(FIND) . -name unbuildable -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
395 (cp -RL include $(BIN_DIST_LIBDIR)/$* || true) && \
396 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
397 \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
398 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
399 \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
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: