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 rebuild.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 = base array packedstring containers bytestring
42 SUBDIRS += 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 readline 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 X11)
66 SUBDIRS += $(wildcard time)
67 ifeq "$(Windows)" "NO"
68 # HGL is not working on Win32, so omit it for now. Better not to ship it
69 # at all than to ship a broken version.
70 SUBDIRS += $(wildcard HGL)
72 SUBDIRS += $(wildcard OpenGL)
73 SUBDIRS += $(wildcard GLUT)
74 SUBDIRS += $(wildcard OpenAL)
75 SUBDIRS += $(wildcard ALUT)
76 SUBDIRS += $(wildcard stm)
77 SUBDIRS += $(wildcard xhtml)
78 SUBDIRS += $(wildcard cgi)
79 SUBDIRS += $(wildcard arrows)
80 ifeq "$(GhcLibsWithObjectIO)" "YES"
81 SUBDIRS += $(wildcard ObjectIO)
83 SUBDIRS += $(wildcard parallel)
84 SUBDIRS += $(wildcard ndp)
87 # -----------------------------------------------------------------------------
90 space=$(empty) $(empty)
92 # -----------------------------------------------------------------------------
94 ifeq "$(RelocatableBuild)" "YES"
95 # On Windows we want to make moveable bindists, but we need to tell
96 # ghc-pkg where the haddock docs are. Therefore we completely ignore
97 # where the user tells us to put the haddock documentation and put it
98 # somewhere whose relative location we know. When installing we need
99 # to give Cabal a real path, though.
103 ilibexecdir = $$topdir
105 idocdir = $$topdir/doc/libraries/$$pkgid
106 iinterfacedir = $$topdir/doc/libraries/$$pkgid
107 ihtmldir = $$httptopdir/doc/libraries/$$pkgid
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 idatadir = $(datadir)
117 idocdir = $(docdir)/libraries/$$pkgid
118 iinterfacedir = $(htmldir)/libraries/$$pkgid
119 ihtmldir = $(htmldir)/libraries/$$pkgid
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 ifneq "$(findstring $(space)dyn$(space), $(space)$(GhcLibWays)$(space))" ""
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
143 BOOTSTRAP_LIBS = Cabal filepath
144 BOOTSTRAP_STAMPS = $(addprefix stamp/bootstrapping.,$(BOOTSTRAP_LIBS))
145 BOOTSTRAP_INC_1_UP = -DCABAL_VERSION=1,3 $(addprefix -i../bootstrapping.,$(BOOTSTRAP_LIBS))
146 BOOTSTRAP_INC_2_UP = -DCABAL_VERSION=1,3 $(addprefix -i../../bootstrapping.,$(BOOTSTRAP_LIBS))
155 boot: $(BOOTSTRAP_STAMPS) ifBuildable/ifBuildable \
156 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
157 installPackage/installPackage
159 # We build the Setup program in a setup subdirectory to stop it trying
160 # to use bits of base and Cabal when we build those packages.
161 # This also makes it slightly easier to clean.
163 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
165 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
166 %/setup/Setup: $(BOOTSTRAP_STAMPS)
169 $(CP) $*/Setup.*hs $*/setup
170 cd $*/setup && $(GHC) -Wall -cpp --make Setup.*hs -o Setup \
171 $(BOOTSTRAP_INC_2_UP)
173 installPackage/installPackage: installPackage.hs $(BOOTSTRAP_STAMPS)
174 -$(RM) -rf installPackage
176 $(CP) installPackage.hs installPackage/
177 cd installPackage && $(GHC) -Wall -cpp \
178 --make installPackage -o installPackage \
179 $(BOOTSTRAP_INC_1_UP)
181 ifBuildable/ifBuildable: ifBuildable.hs
182 -$(RM) -rf ifBuildable
184 $(CP) ifBuildable.hs ifBuildable/
185 cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
187 $(BOOTSTRAP_STAMPS): stamp/bootstrapping.%:
188 $(RM) -rf bootstrapping.$*
189 $(CP) -R $* bootstrapping.$*
190 $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
194 .PHONY: all build configure
198 ifeq "$(HADDOCK_DOCS)" "YES"
202 .PHONY: rebuild.library.%
204 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
205 rebuild.library.%: clean.library.% make.library.%
207 # NB. we're depending on make chasing dependencies from left to right here.
208 # This bit goes wrong with 'make -j'.
209 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
210 build: installPackage/installPackage
212 configure: $(foreach SUBDIR,$(SUBDIRS), \
213 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
215 .PHONY: build.library.%
216 .PHONY: make.library.%
218 # We should depend on %/%.cabal here (and in other rules), but make
219 # makes that difficult.
221 # We put non-existant paths in when configuring, as we require that
222 # builds don't depend on these paths when making bindists.
224 # We rely on all the CONFIGURE_ARGS being quoted with '...', and there
225 # being no 's inside the values.
226 FLAGGED_CONFIGURE_ARGS = $(subst $(space)',\
227 $(space)--configure-option=',\
228 $(space)$(CONFIGURE_ARGS))
230 $(foreach SUBDIR,$(SUBDIRS), \
231 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
232 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
233 -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
234 ( cd $* && setup/Setup configure \
236 --prefix=/NONEXISTANT \
237 --bindir=/NONEXISTANT \
238 --libdir=/NONEXISTANT \
239 --libsubdir='$$pkgid' \
240 --libexecdir=/NONEXISTANT \
241 --datadir=/NONEXISTANT \
242 --docdir=/NONEXISTANT \
243 --interfacedir=/NONEXISTANT \
244 --htmldir=/NONEXISTANT \
245 --with-compiler=../../compiler/stage1/ghc-inplace \
246 --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace \
247 --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace \
249 --haddock-options="--use-contents=../index.html \
250 --use-index=../doc-index.html" \
251 $(FLAGGED_CONFIGURE_ARGS) \
252 --configure-option=--with-cc=$(CC) ) \
253 && touch $@ || touch $*/unbuildable
254 # We don't touch $@ if configure failed as we would prefer to try
255 # configuring it next time round, rather than assuming it'll still fail.
256 # This is particularly important for bootlibs, where failure means the
259 # Build the library using 'make'
260 $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR)):\
261 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
263 %/setup/Setup ifBuildable/ifBuildable
264 if ifBuildable/ifBuildable $*; then \
266 $(MAKE) $(MFLAGS) && \
267 setup/Setup register --inplace; \
270 # Build the library using 'setup build' (not the default)
271 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
272 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
273 %/setup/Setup ifBuildable/ifBuildable
274 if ifBuildable/ifBuildable $*; then \
276 setup/Setup build $(addprefix --ghc-option=,$(GhcLibHcOpts)); \
279 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/GNUmakefile):\
280 %/GNUmakefile: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
281 %/setup/Setup ifBuildable/ifBuildable
284 if ifBuildable/ifBuildable $*; then \
285 cd $* && setup/Setup makefile -f GNUmakefile; \
290 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
291 sh gen_contents_index --inplace
293 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
294 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
295 %/setup/Setup ifBuildable/ifBuildable
296 if ifBuildable/ifBuildable $*; then \
297 cd $* && setup/Setup haddock --html-location='../$$pkgid'; \
300 .PHONY: distclean clean clean.library.%
304 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
305 $(RM) -f stamp/bootstrapping.*
306 $(RM) -rf bootstrapping.*
307 $(RM) -rf ifBuildable
308 $(RM) -rf installPackage
309 $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
310 $(RM) -f haddock* *.gif
313 $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
315 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
317 $(RM) -f stamp/configure.library.*.$* $*/unbuildable
318 -cd $* && setup/Setup clean
320 $(RM) $*/GNUmakefile $*/Makefile.local
323 # -----------------------------------------------------------------------------
325 .PHONY: install install-docs install.library.%
327 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
328 ifeq "$(HADDOCK_DOCS)" "YES"
329 $(INSTALL_DIR) $(DESTDIR)$(html_installed_root)
330 $(INSTALL_DATA) index.html doc-index*.html $(DESTDIR)$(html_installed_root)
331 $(INSTALL_SCRIPT) gen_contents_index $(DESTDIR)$(html_installed_root)
333 $(INSTALL_DATA) base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
334 $(INSTALL_DATA) base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
335 $(INSTALL_DATA) base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
338 # Cabal doesn't let us ask to install docs only, so do nothing here
342 # Ideally this would depend on a stamp/build.library.%, but if it does
343 # then we can't change the libraries and then just rerun make.
344 # Thus if you install without building then it will just break.
346 # prefix and (on Windows) htmldir use $topdir when configuring, so we
347 # need to tell installPackage the real path to use when installing.
349 # We also need to pass all the other directories in, as they can be
350 # overridden when installing a bindist.
352 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
353 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
354 if ifBuildable/ifBuildable $*; then \
356 ../installPackage/installPackage '$(GHC_PKG_PROG)' '$(DESTDIR)$(libdir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(iinterfacedir)' ; \
359 .PHONY: binary-dist binary-dist.library.%
361 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
363 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
364 mkdir $(BIN_DIST_LIBDIR)/installPackage
365 cp installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
366 mkdir $(BIN_DIST_LIBDIR)/ifBuildable
367 cp ifBuildable/ifBuildable $(BIN_DIST_LIBDIR)/ifBuildable
368 cp Makefile $(BIN_DIST_LIBDIR)
369 ifeq "$(HADDOCK_DOCS)" "YES"
370 cp gen_contents_index $(BIN_DIST_LIBDIR)
371 cp index.html $(BIN_DIST_LIBDIR)
372 cp doc-index*.html $(BIN_DIST_LIBDIR)
374 cp -pR stamp $(BIN_DIST_LIBDIR)
375 # This gets used in the compiler directory to see if GHC should
376 # depend on the readline package or not
377 $(MKDIRHIER) $(BIN_DIST_LIBDIR)/readline
378 cp readline/config.mk $(BIN_DIST_LIBDIR)/readline
380 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
381 binary-dist.library.%:
382 if ifBuildable/ifBuildable $*; then \
383 $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*; \
385 cp $*.cabal $(BIN_DIST_LIBDIR)/$* && \
386 cp LICENSE $(BIN_DIST_LIBDIR)/$* && \
387 cp -R dist $(BIN_DIST_LIBDIR)/$* && \
388 $(FIND) . -name "*.buildinfo" -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
389 (cp -RL include $(BIN_DIST_LIBDIR)/$* || true) && \
390 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
391 \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
392 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
393 \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \