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
41 SUBDIRS = ghc-prim $(INTEGER_LIBRARY) base array packedstring
42 SUBDIRS += containers bytestring old-locale old-time filepath directory
43 ifeq "$(GhcLibsWithUnix)" "YES"
46 ifeq "$(Windows)" "YES"
47 SUBDIRS += $(wildcard Win32)
49 SUBDIRS += 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 fgl)
65 SUBDIRS += $(wildcard time)
66 SUBDIRS += $(wildcard OpenGL)
67 SUBDIRS += $(wildcard GLUT)
68 SUBDIRS += $(wildcard OpenAL)
69 SUBDIRS += $(wildcard ALUT)
70 SUBDIRS += $(wildcard stm)
71 SUBDIRS += $(wildcard xhtml)
72 SUBDIRS += $(wildcard cgi)
73 ifeq "$(GhcLibsWithObjectIO)" "YES"
74 SUBDIRS += $(wildcard ObjectIO)
76 SUBDIRS += $(wildcard parallel)
77 SUBDIRS_BUILD += $(wildcard ndp)
78 SUBDIRS_BUILD += $(wildcard dph/dph-base)
79 SUBDIRS_BUILD += $(wildcard dph/dph-prim-seq)
80 SUBDIRS_BUILD += $(wildcard dph/dph-prim-par)
81 SUBDIRS_BUILD += $(wildcard dph/dph)
84 SUBDIRS += $(SUBDIRS_BUILD)
86 # -----------------------------------------------------------------------------
89 space=$(empty) $(empty)
91 # -----------------------------------------------------------------------------
93 ifeq "$(RelocatableBuild)" "YES"
94 # On Windows we want to make moveable bindists, but we need to tell
95 # ghc-pkg where the haddock docs are. Therefore we completely ignore
96 # where the user tells us to put the haddock documentation and put it
97 # somewhere whose relative location we know. When installing we need
98 # to give Cabal a real path, though.
102 ilibexecdir = $$topdir
103 idynlibdir = $$topdir
105 idocdir = $$topdir/doc/libraries/$$pkg
106 ihaddockdir = $$topdir/doc/libraries/$$pkg
107 ihtmldir = $$httptopdir/doc/libraries/$$pkg
108 html_installed_root = $(prefix)/doc/libraries
110 # On non-Windows we can just give absolute paths all the time, and
111 # thus obey the htmldir that we are given.
115 ilibexecdir = $(libexecdir)
116 idynlibdir = $(dynlibdir)
117 idatadir = $(datadir)
118 idocdir = $(docdir)/libraries/$$pkg
119 ihaddockdir = $(htmldir)/libraries/$$pkg
120 ihtmldir = $(htmldir)/libraries/$$pkg
121 html_installed_root = $(htmldir)/libraries
124 ifneq "$(DOING_BIN_DIST)" "YES"
127 CONFIGURE_STAMP_EXTRAS :=
129 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
130 CONFIGURE_OPTS += --enable-library-profiling
131 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
134 ifneq "$(findstring $(space)dyn$(space), $(space)$(GhcLibWays)$(space))" ""
135 CONFIGURE_OPTS += --enable-shared
136 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
139 ifeq "$(SplitObjs)" "YES"
140 CONFIGURE_OPTS += --enable-split-objs
141 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
144 ifneq "$(HSCOLOUR)" ""
145 CONFIGURE_OPTS += --with-hscolour=$(HSCOLOUR)
148 BOOTSTRAP_LIBS = Cabal filepath
149 BOOTSTRAP_STAMPS = $(addprefix stamp/bootstrapping.,$(BOOTSTRAP_LIBS))
150 BOOTSTRAP_INC = -DCABAL_VERSION=1,3 $(addprefix -i$(FPTOOLS_TOP_ABS)/libraries/bootstrapping.,$(BOOTSTRAP_LIBS))
151 DEPLOYMENT_OPTS = $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS)) \
152 $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
161 boot: $(BOOTSTRAP_STAMPS) ifBuildable/ifBuildable \
162 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
163 installPackage/installPackage
165 # We build the Setup program in a setup subdirectory to stop it trying
166 # to use bits of base and Cabal when we build those packages.
167 # This also makes it slightly easier to clean.
169 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
171 # -fffi is only needed for GHC 6.4 at the time of writing
172 CABAL_GHC_FLAGS = -Wall -cpp -fffi
174 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
175 %/setup/Setup: $(BOOTSTRAP_STAMPS)
178 $(CP) $*/Setup.*hs $*/setup
179 cd $*/setup && $(GHC) $(CABAL_GHC_FLAGS) --make Setup.*hs -o Setup \
182 installPackage/installPackage: installPackage.hs $(BOOTSTRAP_STAMPS)
183 -$(RM) -rf installPackage
185 $(CP) installPackage.hs installPackage/
187 cd installPackage && ../$(HC) $(CABAL_GHC_FLAGS) \
188 --make installPackage -o installPackage \
189 $(BOOTSTRAP_INC) $(DEPLOYMENT_OPTS)
191 cd installPackage && $(GHC) $(CABAL_GHC_FLAGS) \
192 --make installPackage -o installPackage \
195 # TODO: The conditional is yucky, but we need to be able to build with stage1
196 # for bindists and as installPackages/ has no Makefile, it seems hard
197 # to make this nicer.
199 ifBuildable/ifBuildable: ifBuildable.hs
200 -$(RM) -rf ifBuildable
202 $(CP) ifBuildable.hs ifBuildable/
204 cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable \
207 cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
210 IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/libraries/boot-packages
212 $(BOOTSTRAP_STAMPS): stamp/bootstrapping.%:
213 $(RM) -rf bootstrapping.$*
214 $(CP) -R $* bootstrapping.$*
215 $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
219 .PHONY: all build configure
223 ifeq "$(HADDOCK_DOCS)" "YES"
227 .PHONY: rebuild.library.%
228 .PHONY: remake.library.%
230 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
231 rebuild.library.%: clean.library.% build.library.%
233 $(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
234 remake.library.%: clean.library.% make.library.%
236 # NB. we're depending on make chasing dependencies from left to right here.
237 # This bit goes wrong with 'make -j'.
238 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
239 build: installPackage/installPackage
241 configure: $(foreach SUBDIR,$(SUBDIRS), \
242 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
244 .PHONY: build.library.%
245 .PHONY: make.library.%
247 # We should depend on %/%.cabal here (and in other rules), but make
248 # makes that difficult.
250 # We put non-existant paths in when configuring, as we require that
251 # builds don't depend on these paths when making bindists.
253 # We rely on all the CONFIGURE_ARGS being quoted with '...', and there
254 # being no 's inside the values.
255 FLAGGED_CONFIGURE_ARGS = $(subst $(space)',\
256 $(space)--configure-option=',\
257 $(space)$(CONFIGURE_ARGS))
259 ifeq "$(Windows)" "YES"
260 NONEXISTENT=c:/NONEXISTENT
262 NONEXISTENT=/NONEXISTENT
265 ALL_CONFIGURE_FLAGS = \
267 --prefix=$(NONEXISTENT) \
268 --bindir=$(NONEXISTENT) \
269 --libdir=$(NONEXISTENT) \
270 --libsubdir='$$pkgid' \
271 --libexecdir=$(NONEXISTENT) \
272 --datadir=$(NONEXISTENT) \
273 --docdir=$(NONEXISTENT) \
274 --haddockdir=$(NONEXISTENT) \
275 --htmldir=$(NONEXISTENT) \
276 --with-compiler=$(FPTOOLS_TOP_ABS)/compiler/stage1/ghc-inplace \
277 --with-hc-pkg=$(FPTOOLS_TOP_ABS)/utils/ghc-pkg/ghc-pkg-inplace \
278 --with-hsc2hs=$(FPTOOLS_TOP_ABS)/utils/hsc2hs/hsc2hs-inplace \
280 --haddock-options="--use-contents=../index.html \
281 --use-index=../doc-index.html" \
282 $(FLAGGED_CONFIGURE_ARGS) \
283 --configure-option=--with-cc=$(CC)
285 $(foreach SUBDIR,$(SUBDIRS), \
286 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
287 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
288 -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
289 $(MKDIRHIER) `dirname $@`
290 ( cd $* && setup/Setup configure $(ALL_CONFIGURE_FLAGS) ) \
291 && touch $@ || touch $*/unbuildable
292 # We don't touch $@ if configure failed as we would prefer to try
293 # configuring it next time round, rather than assuming it'll still fail.
294 # This is particularly important for bootlibs, where failure means the
297 # Build the library using 'make'
298 # We re-run 'setup makefile' each time, just in case any preprocessing
299 # needs to be done. However, we're careful not to overwrite GNUmakefile
300 # if it hasn't changed, so that dependency-generation isn't forced
302 # Packages in $(SUBDIRS_BUILD) need to use the build.* rules instead of
303 # make.*, so filter them out and use an alternate rule below instead.
304 $(foreach SUBDIR,$(filter-out $(SUBDIRS_BUILD),$(SUBDIRS)),make.library.$(SUBDIR)):\
305 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
306 %/setup/Setup ifBuildable/ifBuildable installPackage/installPackage
307 if $(IFBUILDABLE) $*; then \
309 cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
310 mv GNUmakefile GNUmakefile.tmp; \
311 setup/Setup makefile -f GNUmakefile; \
312 cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
313 $(MAKE) $(MFLAGS) && \
314 setup/Setup register --inplace; \
317 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
319 # Alternate rule, as described above
320 $(foreach SUBDIR,$(SUBDIRS_BUILD),make.library.$(SUBDIR)):\
321 make.library.%: build.library.%
323 # Build the library using 'setup build' (not the default)
324 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
325 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
326 %/setup/Setup ifBuildable/ifBuildable
327 if $(IFBUILDABLE) $*; then \
329 setup/Setup build $(addprefix --ghc-option=,$(GhcLibHcOpts)); \
330 setup/Setup register --inplace; \
337 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
338 sh gen_contents_index --inplace
340 # Making hyperlinked source only works if we have hscolour
341 ifneq "$(HSCOLOUR)" ""
342 CABAL_HADDOCK_FLAGS=--hyperlink-source
345 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
346 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
347 %/setup/Setup ifBuildable/ifBuildable
348 if $(IFBUILDABLE) $*; then \
349 cd $* && setup/Setup haddock --html-location='../$$pkg' \
350 $(CABAL_HADDOCK_FLAGS); \
352 ifneq "$(HSCOLOUR)" ""
353 # We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
355 if $(IFBUILDABLE) $*; then cp hscolour.css $*/dist/doc/html/*/src/; fi
358 .PHONY: distclean clean clean.library.%
362 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
363 $(RM) -f stamp/bootstrapping.*
364 $(RM) -rf bootstrapping.*
365 $(RM) -rf ifBuildable
366 $(RM) -rf installPackage
367 $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
368 $(RM) -f haddock* *.gif
371 $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
373 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
375 $(RM) -f stamp/configure.library.*.$* $*/unbuildable
376 -cd $* && setup/Setup clean
378 $(RM) $*/GNUmakefile $*/Makefile.local
381 # -----------------------------------------------------------------------------
383 .PHONY: install install-docs install.library.%
385 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
386 ifeq "$(HADDOCK_DOCS)" "YES"
387 $(INSTALL_DIR) $(DESTDIR)$(html_installed_root)
388 $(INSTALL_DATA) index.html doc-index*.html $(DESTDIR)$(html_installed_root)
389 $(INSTALL_SCRIPT) gen_contents_index $(DESTDIR)$(html_installed_root)
391 $(INSTALL_DATA) base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
392 $(INSTALL_DATA) base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
393 $(INSTALL_DATA) base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
396 # Cabal doesn't let us ask to install docs only, so do nothing here
400 # Ideally this would depend on a stamp/build.library.%, but if it does
401 # then we can't change the libraries and then just rerun make.
402 # Thus if you install without building then it will just break.
404 # prefix and (on Windows) htmldir use $topdir when configuring, so we
405 # need to tell installPackage the real path to use when installing.
407 # We also need to pass all the other directories in, as they can be
408 # overridden when installing a bindist.
410 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
411 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
412 if $(IFBUILDABLE) $*; then \
414 $(FPTOOLS_TOP_ABS)/libraries/installPackage/installPackage install '$(GHC_PKG_PROG)' '$(DESTDIR)$(libdir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' ; \
417 .PHONY: binary-dist binary-dist.library.%
419 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
421 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
422 mkdir $(BIN_DIST_LIBDIR)/installPackage
423 cp installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
424 mkdir $(BIN_DIST_LIBDIR)/ifBuildable
425 cp ifBuildable/ifBuildable $(BIN_DIST_LIBDIR)/ifBuildable
426 cp Makefile $(BIN_DIST_LIBDIR)
427 ifeq "$(HADDOCK_DOCS)" "YES"
428 cp gen_contents_index $(BIN_DIST_LIBDIR)
429 cp index.html $(BIN_DIST_LIBDIR)
430 cp doc-index*.html $(BIN_DIST_LIBDIR)
432 cp -pR stamp $(BIN_DIST_LIBDIR)
434 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
435 binary-dist.library.%:
436 if $(IFBUILDABLE) $*; then \
437 $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*; \
439 cp $*.cabal $(BIN_DIST_LIBDIR)/$* && \
440 cp LICENSE $(BIN_DIST_LIBDIR)/$* && \
441 cp -R dist $(BIN_DIST_LIBDIR)/$* && \
442 $(FIND) . -name "*.buildinfo" -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
443 $(FIND) . -name unbuildable -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
444 (cp -RL include $(BIN_DIST_LIBDIR)/$* || true) && \
445 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
446 \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
447 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
448 \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
452 # Ignore some doc targets that we don't support
453 # The root recurses into us when these targets are made
454 .PHONY: html-no-chunks chm HxS fo dvi ps pdf
455 html-no-chunks chm HxS fo dvi ps pdf: