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)
80 SUBDIRS += $(SUBDIRS_BUILD)
82 # -----------------------------------------------------------------------------
85 space=$(empty) $(empty)
87 # -----------------------------------------------------------------------------
89 ifeq "$(RelocatableBuild)" "YES"
90 # On Windows we want to make moveable bindists, but we need to tell
91 # ghc-pkg where the haddock docs are. Therefore we completely ignore
92 # where the user tells us to put the haddock documentation and put it
93 # somewhere whose relative location we know. When installing we need
94 # to give Cabal a real path, though.
98 ilibexecdir = $$topdir
101 idocdir = $$topdir/doc/libraries/$$pkg
102 ihaddockdir = $$topdir/doc/libraries/$$pkg
103 ihtmldir = $$httptopdir/doc/libraries/$$pkg
104 html_installed_root = $(prefix)/doc/libraries
106 # On non-Windows we can just give absolute paths all the time, and
107 # thus obey the htmldir that we are given.
111 ilibexecdir = $(libexecdir)
112 idynlibdir = $(dynlibdir)
113 idatadir = $(datadir)
114 idocdir = $(docdir)/libraries/$$pkg
115 ihaddockdir = $(htmldir)/libraries/$$pkg
116 ihtmldir = $(htmldir)/libraries/$$pkg
117 html_installed_root = $(htmldir)/libraries
120 ifneq "$(DOING_BIN_DIST)" "YES"
123 CONFIGURE_STAMP_EXTRAS :=
125 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
126 CONFIGURE_OPTS += --enable-library-profiling
127 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
130 ifneq "$(findstring $(space)dyn$(space), $(space)$(GhcLibWays)$(space))" ""
131 CONFIGURE_OPTS += --enable-shared
132 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
135 ifeq "$(SplitObjs)" "YES"
136 CONFIGURE_OPTS += --enable-split-objs
137 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
140 ifneq "$(HSCOLOUR)" ""
141 CONFIGURE_OPTS += --with-hscolour=$(HSCOLOUR)
144 BOOTSTRAP_LIBS = Cabal filepath
145 BOOTSTRAP_STAMPS = $(addprefix stamp/bootstrapping.,$(BOOTSTRAP_LIBS))
146 BOOTSTRAP_INC = -DCABAL_VERSION=1,3 $(addprefix -i$(FPTOOLS_TOP_ABS)/libraries/bootstrapping.,$(BOOTSTRAP_LIBS))
147 DEPLOYMENT_OPTS = $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS)) \
148 $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
157 boot: $(BOOTSTRAP_STAMPS) ifBuildable/ifBuildable \
158 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
159 installPackage/installPackage
161 # We build the Setup program in a setup subdirectory to stop it trying
162 # to use bits of base and Cabal when we build those packages.
163 # This also makes it slightly easier to clean.
165 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
167 # -fffi is only needed for GHC 6.4 at the time of writing
168 CABAL_GHC_FLAGS = -Wall -cpp -fffi
170 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
171 %/setup/Setup: $(BOOTSTRAP_STAMPS)
174 $(CP) $*/Setup.*hs $*/setup
175 cd $*/setup && $(GHC) $(CABAL_GHC_FLAGS) --make Setup.*hs -o Setup \
178 installPackage/installPackage: installPackage.hs $(BOOTSTRAP_STAMPS)
179 -$(RM) -rf installPackage
181 $(CP) installPackage.hs installPackage/
183 cd installPackage && ../$(HC) $(CABAL_GHC_FLAGS) \
184 --make installPackage -o installPackage \
185 $(BOOTSTRAP_INC) $(DEPLOYMENT_OPTS)
187 cd installPackage && $(GHC) $(CABAL_GHC_FLAGS) \
188 --make installPackage -o installPackage \
191 # TODO: The conditional is yucky, but we need to be able to build with stage1
192 # for bindists and as installPackages/ has no Makefile, it seems hard
193 # to make this nicer.
195 ifBuildable/ifBuildable: ifBuildable.hs
196 -$(RM) -rf ifBuildable
198 $(CP) ifBuildable.hs ifBuildable/
200 cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable \
203 cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
206 IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/libraries/boot-packages
208 $(BOOTSTRAP_STAMPS): stamp/bootstrapping.%:
209 $(RM) -rf bootstrapping.$*
210 $(CP) -R $* bootstrapping.$*
211 $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
215 .PHONY: all build configure
219 ifeq "$(HADDOCK_DOCS)" "YES"
223 .PHONY: rebuild.library.%
224 .PHONY: remake.library.%
226 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
227 rebuild.library.%: clean.library.% build.library.%
229 $(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
230 remake.library.%: clean.library.% make.library.%
232 # NB. we're depending on make chasing dependencies from left to right here.
233 # This bit goes wrong with 'make -j'.
234 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
235 build: installPackage/installPackage
237 configure: $(foreach SUBDIR,$(SUBDIRS), \
238 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
240 .PHONY: build.library.%
241 .PHONY: make.library.%
243 # We should depend on %/%.cabal here (and in other rules), but make
244 # makes that difficult.
246 # We put non-existant paths in when configuring, as we require that
247 # builds don't depend on these paths when making bindists.
249 # We rely on all the CONFIGURE_ARGS being quoted with '...', and there
250 # being no 's inside the values.
251 FLAGGED_CONFIGURE_ARGS = $(subst $(space)',\
252 $(space)--configure-option=',\
253 $(space)$(CONFIGURE_ARGS))
255 ifeq "$(Windows)" "YES"
256 NONEXISTENT=c:/NONEXISTENT
258 NONEXISTENT=/NONEXISTENT
261 ALL_CONFIGURE_FLAGS = \
263 --prefix=$(NONEXISTENT) \
264 --bindir=$(NONEXISTENT) \
265 --libdir=$(NONEXISTENT) \
266 --libsubdir='$$pkgid' \
267 --libexecdir=$(NONEXISTENT) \
268 --datadir=$(NONEXISTENT) \
269 --docdir=$(NONEXISTENT) \
270 --haddockdir=$(NONEXISTENT) \
271 --htmldir=$(NONEXISTENT) \
272 --with-compiler=$(FPTOOLS_TOP_ABS)/compiler/stage1/ghc-inplace \
273 --with-hc-pkg=$(FPTOOLS_TOP_ABS)/utils/ghc-pkg/ghc-pkg-inplace \
274 --with-hsc2hs=$(FPTOOLS_TOP_ABS)/utils/hsc2hs/hsc2hs-inplace \
276 --haddock-options="--use-contents=../index.html \
277 --use-index=../doc-index.html" \
278 $(FLAGGED_CONFIGURE_ARGS) \
279 --configure-option=--with-cc=$(CC)
281 $(foreach SUBDIR,$(SUBDIRS), \
282 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
283 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
284 -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
285 $(MKDIRHIER) `dirname $@`
286 ( cd $* && setup/Setup configure $(ALL_CONFIGURE_FLAGS) ) \
287 && touch $@ || touch $*/unbuildable
288 # We don't touch $@ if configure failed as we would prefer to try
289 # configuring it next time round, rather than assuming it'll still fail.
290 # This is particularly important for bootlibs, where failure means the
293 # Build the library using 'make'
294 # We re-run 'setup makefile' each time, just in case any preprocessing
295 # needs to be done. However, we're careful not to overwrite GNUmakefile
296 # if it hasn't changed, so that dependency-generation isn't forced
298 # Packages in $(SUBDIRS_BUILD) need to use the build.* rules instead of
299 # make.*, so filter them out and use an alternate rule below instead.
300 $(foreach SUBDIR,$(filter-out $(SUBDIRS_BUILD),$(SUBDIRS)),make.library.$(SUBDIR)):\
301 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
302 %/setup/Setup ifBuildable/ifBuildable installPackage/installPackage
303 if $(IFBUILDABLE) $*; then \
305 cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
306 mv GNUmakefile GNUmakefile.tmp; \
307 setup/Setup makefile -f GNUmakefile; \
308 cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
309 $(MAKE) $(MFLAGS) && \
310 setup/Setup register --inplace; \
313 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
315 # Alternate rule, as described above
316 $(foreach SUBDIR,$(SUBDIRS_BUILD),make.library.$(SUBDIR)):\
317 make.library.%: build.library.%
319 # Build the library using 'setup build' (not the default)
320 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
321 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
322 %/setup/Setup ifBuildable/ifBuildable
323 if $(IFBUILDABLE) $*; then \
325 setup/Setup build $(addprefix --ghc-option=,$(GhcLibHcOpts)); \
326 setup/Setup register --inplace; \
333 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
334 sh gen_contents_index --inplace
336 # Making hyperlinked source only works if we have hscolour
337 ifneq "$(HSCOLOUR)" ""
338 CABAL_HADDOCK_FLAGS=--hyperlink-source
341 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
342 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
343 %/setup/Setup ifBuildable/ifBuildable
344 if $(IFBUILDABLE) $*; then \
345 cd $* && setup/Setup haddock --html-location='../$$pkg' \
346 $(CABAL_HADDOCK_FLAGS); \
348 ifneq "$(HSCOLOUR)" ""
349 # We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
351 if $(IFBUILDABLE) $*; then cp hscolour.css $*/dist/doc/html/*/src/; fi
354 .PHONY: distclean clean clean.library.%
358 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
359 $(RM) -f stamp/bootstrapping.*
360 $(RM) -rf bootstrapping.*
361 $(RM) -rf ifBuildable
362 $(RM) -rf installPackage
363 $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
364 $(RM) -f haddock* *.gif
367 $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
369 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
371 $(RM) -f stamp/configure.library.*.$* $*/unbuildable
372 -cd $* && setup/Setup clean
374 $(RM) $*/GNUmakefile $*/Makefile.local
377 # -----------------------------------------------------------------------------
379 .PHONY: install install-docs install.library.%
381 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
382 ifeq "$(HADDOCK_DOCS)" "YES"
383 $(INSTALL_DIR) $(DESTDIR)$(html_installed_root)
384 $(INSTALL_DATA) index.html doc-index*.html $(DESTDIR)$(html_installed_root)
385 $(INSTALL_SCRIPT) gen_contents_index $(DESTDIR)$(html_installed_root)
387 $(INSTALL_DATA) base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
388 $(INSTALL_DATA) base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
389 $(INSTALL_DATA) base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
392 # Cabal doesn't let us ask to install docs only, so do nothing here
396 # Ideally this would depend on a stamp/build.library.%, but if it does
397 # then we can't change the libraries and then just rerun make.
398 # Thus if you install without building then it will just break.
400 # prefix and (on Windows) htmldir use $topdir when configuring, so we
401 # need to tell installPackage the real path to use when installing.
403 # We also need to pass all the other directories in, as they can be
404 # overridden when installing a bindist.
406 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
407 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
408 if $(IFBUILDABLE) $*; then \
410 $(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)' ; \
413 .PHONY: binary-dist binary-dist.library.%
415 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
417 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
418 mkdir $(BIN_DIST_LIBDIR)/installPackage
419 cp installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
420 mkdir $(BIN_DIST_LIBDIR)/ifBuildable
421 cp ifBuildable/ifBuildable $(BIN_DIST_LIBDIR)/ifBuildable
422 cp Makefile $(BIN_DIST_LIBDIR)
423 ifeq "$(HADDOCK_DOCS)" "YES"
424 cp gen_contents_index $(BIN_DIST_LIBDIR)
425 cp index.html $(BIN_DIST_LIBDIR)
426 cp doc-index*.html $(BIN_DIST_LIBDIR)
428 cp -pR stamp $(BIN_DIST_LIBDIR)
430 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
431 binary-dist.library.%:
432 if $(IFBUILDABLE) $*; then \
433 $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*; \
435 cp $*.cabal $(BIN_DIST_LIBDIR)/$* && \
436 cp LICENSE $(BIN_DIST_LIBDIR)/$* && \
437 cp -R dist $(BIN_DIST_LIBDIR)/$* && \
438 $(FIND) . -name "*.buildinfo" -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
439 $(FIND) . -name unbuildable -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
440 (cp -RL include $(BIN_DIST_LIBDIR)/$* || true) && \
441 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
442 \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
443 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
444 \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
448 # Ignore some doc targets that we don't support
449 # The root recurses into us when these targets are made
450 .PHONY: html-no-chunks chm HxS fo dvi ps pdf
451 html-no-chunks chm HxS fo dvi ps pdf: