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 docdir := $(docdir)/libraries/$$pkgid
95 ifeq "$(Windows)" "YES"
96 # On Windows we want to make moveable bindists, but we need to tell
97 # ghc-pkg where the haddock docs are. Therefore we completely ignore
98 # where the user tells us to put the haddock documentation and put it
99 # somewhere whose relative location we know. When installing we need
100 # to give Cabal a real path, though.
101 htmldir_configure = $$topdir/doc/libraries/$$pkgid
102 htmldir_install = $(prefix)/doc/libraries/$$pkgid
104 # On non-Windows we can just give absolute paths all the time, and
105 # thus obey the htmldir that we are given.
106 htmldir_configure = $(htmldir)/libraries/$$pkgid
107 htmldir_install = $(htmldir_configure)
110 ifneq "$(DOING_BIN_DIST)" "YES"
113 CONFIGURE_STAMP_EXTRAS :=
115 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
116 CONFIGURE_OPTS += --enable-library-profiling
117 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
120 ifneq "$(findstring $(space)dyn$(space), $(space)$(GhcLibWays)$(space))" ""
121 CONFIGURE_OPTS += --enable-shared
122 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
125 ifeq "$(SplitObjs)" "YES"
126 CONFIGURE_OPTS += --enable-split-objs
127 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
130 BOOTSTRAP_LIBS = Cabal filepath
131 BOOTSTRAP_STAMPS = $(addprefix stamp/bootstrapping.,$(BOOTSTRAP_LIBS))
132 BOOTSTRAP_INC_1_UP = $(addprefix -i../bootstrapping.,$(BOOTSTRAP_LIBS))
133 BOOTSTRAP_INC_2_UP = $(addprefix -i../../bootstrapping.,$(BOOTSTRAP_LIBS))
142 boot: $(BOOTSTRAP_STAMPS) ifBuildable/ifBuildable \
143 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
144 installPackage/installPackage
146 # We build the Setup program in a setup subdirectory to stop it trying
147 # to use bits of base and Cabal when we build those packages.
148 # This also makes it slightly easier to clean.
150 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
152 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
153 %/setup/Setup: $(BOOTSTRAP_STAMPS)
156 $(CP) $*/Setup.*hs $*/setup
157 cd $*/setup && $(GHC) -Wall -cpp --make Setup.*hs -o Setup \
158 $(BOOTSTRAP_INC_2_UP)
160 installPackage/installPackage: installPackage.hs $(BOOTSTRAP_STAMPS)
161 -$(RM) -rf installPackage
163 $(CP) installPackage.hs installPackage/
164 cd installPackage && $(GHC) -Wall -cpp \
165 --make installPackage -o installPackage \
166 $(BOOTSTRAP_INC_1_UP)
168 ifBuildable/ifBuildable: ifBuildable.hs
169 -$(RM) -rf ifBuildable
171 $(CP) ifBuildable.hs ifBuildable/
172 cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
174 $(BOOTSTRAP_STAMPS): stamp/bootstrapping.%:
175 $(RM) -rf bootstrapping.$*
176 $(CP) -R $* bootstrapping.$*
177 $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
181 .PHONY: all build configure
185 ifeq "$(HADDOCK_DOCS)" "YES"
189 .PHONY: rebuild.library.%
191 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
192 rebuild.library.%: clean.library.% make.library.%
194 # NB. we're depending on make chasing dependencies from left to right here.
195 # This bit goes wrong with 'make -j'.
196 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
197 build: installPackage/installPackage
199 configure: $(foreach SUBDIR,$(SUBDIRS), \
200 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
202 .PHONY: build.library.%
203 .PHONY: make.library.%
205 # We should depend on %/%.cabal here (and in other rules), but make
206 # makes that difficult.
208 # We explicitly set datadir to a sensible value, as Cabal (used to?) use
209 # "C:\\Program Files\\Common Files"
212 # We also set libsubdir differently on Windows and non-Windows, as on
213 # non-Windows the path we deduce is higher up than the path passed to
214 # the executable with the shell script on non-Windows. This should
215 # probably be tidied up so that we can always pass the same libsubdir.
216 ifeq "$(Windows)" "YES"
219 libsubdir = $$compiler/lib/$$pkgid
222 # We rely on all the CONFIGURE_ARGS being quoted with '...', and there
223 # being no 's inside the values.
224 FLAGGED_CONFIGURE_ARGS = $(subst $(space)',\
225 $(space)--configure-option=',\
226 $(space)$(CONFIGURE_ARGS))
228 $(foreach SUBDIR,$(SUBDIRS), \
229 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
230 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
231 -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
232 ( cd $* && setup/Setup configure \
234 --prefix='$$topdir' \
235 --bindir='$(bindir)' \
236 --libdir='$(libdir)' \
237 --libsubdir='$(libsubdir)' \
238 --libexecdir='$(libexecdir)' \
239 --datadir='$(datadir)' \
240 --docdir='$(docdir)' \
241 --htmldir='$(htmldir_configure)' \
242 --with-compiler=../../compiler/stage1/ghc-inplace \
243 --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace \
244 --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace \
246 --haddock-options="--use-contents=../index.html \
247 --use-index=../doc-index.html" \
248 $(FLAGGED_CONFIGURE_ARGS) \
249 --configure-option=--with-cc=$(CC) ) \
250 && touch $@ || touch $*/unbuildable
251 # We don't touch $@ if configure failed as we would prefer to try
252 # configuring it next time round, rather than assuming it'll still fail.
253 # This is particularly important for corelibs, where failure means the
256 # Build the library using 'make'
257 $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR)):\
258 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
260 %/setup/Setup ifBuildable/ifBuildable
261 if ifBuildable/ifBuildable $*; then \
263 $(MAKE) $(MFLAGS) && \
264 setup/Setup register --inplace; \
267 # Build the library using 'setup build' (not the default)
268 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
269 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
270 %/setup/Setup ifBuildable/ifBuildable
271 if ifBuildable/ifBuildable $*; then \
273 setup/Setup build $(addprefix --ghc-option=,$(GhcLibHcOpts)); \
276 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/GNUmakefile):\
277 %/GNUmakefile: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
278 %/setup/Setup ifBuildable/ifBuildable
281 if ifBuildable/ifBuildable $*; then \
282 cd $* && setup/Setup makefile -f GNUmakefile; \
287 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
288 sh gen_contents_index
290 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
291 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
292 %/setup/Setup ifBuildable/ifBuildable
293 if ifBuildable/ifBuildable $*; then \
294 cd $* && setup/Setup haddock --html-location='../$$pkg'; \
297 .PHONY: distclean clean clean.library.%
301 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
302 $(RM) -f stamp/bootstrapping.*
303 $(RM) -rf bootstrapping.*
304 $(RM) -rf ifBuildable
305 $(RM) -rf installPackage
306 $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
308 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
310 $(RM) -f stamp/configure.library.*.$* $*/unbuildable
311 -cd $* && setup/Setup clean
313 $(RM) $*/GNUmakefile $*/Makefile.local
316 # -----------------------------------------------------------------------------
318 .PHONY: install install-docs install.library.%
320 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
321 ifeq "$(HADDOCK_DOCS)" "YES"
322 $(INSTALL_DIR) $(DESTDIR)$(htmldir_install)
323 $(INSTALL_DATA) index.html doc-index*.html $(DESTDIR)$(htmldir_install)
324 $(INSTALL_SCRIPT) gen_contents_index $(DESTDIR)$(htmldir_install)
326 $(INSTALL_DATA) $(DESTDIR)$(htmldir_install)/base-*/*.css $(DESTDIR)$(htmldir_install)
327 $(INSTALL_DATA) $(DESTDIR)$(htmldir_install)/base-*/*.js $(DESTDIR)$(htmldir_install)
328 $(INSTALL_DATA) $(DESTDIR)$(htmldir_install)/base-*/*.gif $(DESTDIR)$(htmldir_install)
331 # Cabal doesn't let us ask to install docs only, so do nothing here
335 # Ideally this would depend on a stamp/build.library.%, but if it does
336 # then we can't change the libraries and then just rerun make.
337 # Thus if you install without building then it will just break.
339 # prefix and (on Windows) htmldir use $topdir when configuring, so we
340 # need to tell installPackage the real path to use when installing.
342 # We also need to pass all the other directories in, as they can be
343 # overridden when installing a bindist.
345 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
346 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
347 if ifBuildable/ifBuildable $*; then \
349 ../installPackage/installPackage '$(DESTDIR)' '$(prefix)' '$(bindir)' '$(libdir)' '$(libexecdir)' '$(datadir)' '$(docdir)' '$(htmldir_install)' '$(GHC_PKG_PROG)' '$(DESTDIR)$(libdir)/package.conf' ; \
352 .PHONY: binary-dist binary-dist.library.%
354 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
356 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
357 mkdir $(BIN_DIST_LIBDIR)/installPackage
358 cp installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
359 mkdir $(BIN_DIST_LIBDIR)/ifBuildable
360 cp ifBuildable/ifBuildable $(BIN_DIST_LIBDIR)/ifBuildable
361 cp Makefile $(BIN_DIST_LIBDIR)
362 ifeq "$(HADDOCK_DOCS)" "YES"
363 cp gen_contents_index $(BIN_DIST_LIBDIR)
364 cp index.html $(BIN_DIST_LIBDIR)
365 cp doc-index*.html $(BIN_DIST_LIBDIR)
367 cp -pR stamp $(BIN_DIST_LIBDIR)
369 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
370 binary-dist.library.%:
371 if ifBuildable/ifBuildable $*; then \
372 $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*; \
374 cp $*.cabal $(BIN_DIST_LIBDIR)/$* && \
375 cp LICENSE $(BIN_DIST_LIBDIR)/$* && \
376 cp -R dist $(BIN_DIST_LIBDIR)/$* && \
377 (cp -RL include $(BIN_DIST_LIBDIR)/$* || true) && \
378 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
379 \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
380 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
381 \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \