Cope with libraries in libraries/foo/bar rather than just libraries/foo
[ghc.git] / libraries / Makefile
1
2 # To do a fresh build:
3 #
4 # make clean
5 # make boot
6 # make
7 #
8 # To rebuild a particular library <package>:
9 #
10 # make clean.library.<package>
11 # make make.library.<package>
12 #
13 # or the following is equivalent:
14 #
15 # make remake.library.<package>
16 #
17 # To add a new library to the tree, do
18 #
19 # darcs get http://darcs.haskell.org/packages/foo
20 # [ -e foo/configure.ac ] && ( cd foo && autoreconf )
21 # make make.library.foo
22
23 .PHONY: default_target show
24
25 default_target: all
26
27 show:
28 @echo '$(VALUE)="$($(VALUE))"'
29
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.
34 .NOTPARALLEL:
35
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.
38 TOP=..
39 include $(TOP)/mk/boilerplate.mk
40
41 SUBDIRS = ghc-prim $(INTEGER_LIBRARY) base array packedstring
42 SUBDIRS += containers bytestring old-locale old-time filepath directory
43 ifeq "$(GhcLibsWithUnix)" "YES"
44 SUBDIRS += unix
45 endif
46 ifeq "$(Windows)" "YES"
47 SUBDIRS += $(wildcard Win32)
48 endif
49 SUBDIRS += process pretty hpc template-haskell editline Cabal random haskell98
50
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)
75 endif
76 SUBDIRS += $(wildcard parallel)
77 SUBDIRS += $(wildcard ndp)
78 endif
79
80 # -----------------------------------------------------------------------------
81
82 empty=
83 space=$(empty) $(empty)
84
85 # -----------------------------------------------------------------------------
86
87 ifeq "$(RelocatableBuild)" "YES"
88 # On Windows we want to make moveable bindists, but we need to tell
89 # ghc-pkg where the haddock docs are. Therefore we completely ignore
90 # where the user tells us to put the haddock documentation and put it
91 # somewhere whose relative location we know. When installing we need
92 # to give Cabal a real path, though.
93 iprefix = $$topdir
94 ibindir = $$topdir
95 ilibdir = $$topdir
96 ilibexecdir = $$topdir
97 idynlibdir = $$topdir
98 idatadir = $$topdir
99 idocdir = $$topdir/doc/libraries/$$pkg
100 ihaddockdir = $$topdir/doc/libraries/$$pkg
101 ihtmldir = $$httptopdir/doc/libraries/$$pkg
102 html_installed_root = $(prefix)/doc/libraries
103 else
104 # On non-Windows we can just give absolute paths all the time, and
105 # thus obey the htmldir that we are given.
106 iprefix = $(prefix)
107 ibindir = $(bindir)
108 ilibdir = $(libdir)
109 ilibexecdir = $(libexecdir)
110 idynlibdir = $(dynlibdir)
111 idatadir = $(datadir)
112 idocdir = $(docdir)/libraries/$$pkg
113 ihaddockdir = $(htmldir)/libraries/$$pkg
114 ihtmldir = $(htmldir)/libraries/$$pkg
115 html_installed_root = $(htmldir)/libraries
116 endif
117
118 ifneq "$(DOING_BIN_DIST)" "YES"
119
120 CONFIGURE_OPTS =
121 CONFIGURE_STAMP_EXTRAS :=
122
123 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
124 CONFIGURE_OPTS += --enable-library-profiling
125 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
126 endif
127
128 ifneq "$(findstring $(space)dyn$(space), $(space)$(GhcLibWays)$(space))" ""
129 CONFIGURE_OPTS += --enable-shared
130 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
131 endif
132
133 ifeq "$(SplitObjs)" "YES"
134 CONFIGURE_OPTS += --enable-split-objs
135 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
136 endif
137
138 ifneq "$(HSCOLOUR)" ""
139 CONFIGURE_OPTS += --with-hscolour=$(HSCOLOUR)
140 endif
141
142 BOOTSTRAP_LIBS = Cabal filepath
143 BOOTSTRAP_STAMPS = $(addprefix stamp/bootstrapping.,$(BOOTSTRAP_LIBS))
144 BOOTSTRAP_INC = -DCABAL_VERSION=1,3 $(addprefix -i$(FPTOOLS_TOP_ABS)/libraries/bootstrapping.,$(BOOTSTRAP_LIBS))
145 DEPLOYMENT_OPTS = $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS)) \
146 $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
147
148 .PHONY: subdirs
149
150 subdirs:
151 @echo $(SUBDIRS)
152
153 .PHONY: boot
154
155 boot: $(BOOTSTRAP_STAMPS) ifBuildable/ifBuildable \
156 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
157 installPackage/installPackage
158
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.
162
163 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
164
165 # -fffi is only needed for GHC 6.4 at the time of writing
166 CABAL_GHC_FLAGS = -Wall -cpp -fffi
167
168 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
169 %/setup/Setup: $(BOOTSTRAP_STAMPS)
170 -$(RM) -rf $*/setup
171 mkdir $*/setup
172 $(CP) $*/Setup.*hs $*/setup
173 cd $*/setup && $(GHC) $(CABAL_GHC_FLAGS) --make Setup.*hs -o Setup \
174 $(BOOTSTRAP_INC)
175
176 installPackage/installPackage: installPackage.hs $(BOOTSTRAP_STAMPS)
177 -$(RM) -rf installPackage
178 mkdir installPackage
179 $(CP) installPackage.hs installPackage/
180 ifeq "$(stage)" "2"
181 cd installPackage && ../$(HC) $(CABAL_GHC_FLAGS) \
182 --make installPackage -o installPackage \
183 $(BOOTSTRAP_INC) $(DEPLOYMENT_OPTS)
184 else
185 cd installPackage && $(GHC) $(CABAL_GHC_FLAGS) \
186 --make installPackage -o installPackage \
187 $(BOOTSTRAP_INC)
188 endif
189 # TODO: The conditional is yucky, but we need to be able to build with stage1
190 # for bindists and as installPackages/ has no Makefile, it seems hard
191 # to make this nicer.
192
193 ifBuildable/ifBuildable: ifBuildable.hs
194 -$(RM) -rf ifBuildable
195 mkdir ifBuildable
196 $(CP) ifBuildable.hs ifBuildable/
197 ifeq "$(stage)" "2"
198 cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable \
199 $(DEPLOYMENT_OPTS)
200 else
201 cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
202 endif
203
204 IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/libraries/boot-packages
205
206 $(BOOTSTRAP_STAMPS): stamp/bootstrapping.%:
207 $(RM) -rf bootstrapping.$*
208 $(CP) -R $* bootstrapping.$*
209 $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
210 -exec $(RM) -f {} \;
211 touch $@
212
213 .PHONY: all build configure
214
215 all: build
216
217 ifeq "$(HADDOCK_DOCS)" "YES"
218 all: doc
219 endif
220
221 .PHONY: rebuild.library.%
222 .PHONY: remake.library.%
223
224 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
225 rebuild.library.%: clean.library.% build.library.%
226
227 $(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
228 remake.library.%: clean.library.% make.library.%
229
230 # NB. we're depending on make chasing dependencies from left to right here.
231 # This bit goes wrong with 'make -j'.
232 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
233 build: installPackage/installPackage
234
235 configure: $(foreach SUBDIR,$(SUBDIRS), \
236 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
237
238 .PHONY: build.library.%
239 .PHONY: make.library.%
240
241 # We should depend on %/%.cabal here (and in other rules), but make
242 # makes that difficult.
243
244 # We put non-existant paths in when configuring, as we require that
245 # builds don't depend on these paths when making bindists.
246
247 # We rely on all the CONFIGURE_ARGS being quoted with '...', and there
248 # being no 's inside the values.
249 FLAGGED_CONFIGURE_ARGS = $(subst $(space)',\
250 $(space)--configure-option=',\
251 $(space)$(CONFIGURE_ARGS))
252
253 ifeq "$(Windows)" "YES"
254 NONEXISTENT=c:/NONEXISTENT
255 else
256 NONEXISTENT=/NONEXISTENT
257 endif
258
259 ALL_CONFIGURE_FLAGS = \
260 $(CONFIGURE_OPTS) \
261 --prefix=$(NONEXISTENT) \
262 --bindir=$(NONEXISTENT) \
263 --libdir=$(NONEXISTENT) \
264 --libsubdir='$$pkgid' \
265 --libexecdir=$(NONEXISTENT) \
266 --datadir=$(NONEXISTENT) \
267 --docdir=$(NONEXISTENT) \
268 --haddockdir=$(NONEXISTENT) \
269 --htmldir=$(NONEXISTENT) \
270 --with-compiler=$(FPTOOLS_TOP_ABS)/compiler/stage1/ghc-inplace \
271 --with-hc-pkg=$(FPTOOLS_TOP_ABS)/utils/ghc-pkg/ghc-pkg-inplace \
272 --with-hsc2hs=$(FPTOOLS_TOP_ABS)/utils/hsc2hs/hsc2hs-inplace \
273 --with-ld=$(LD) \
274 --haddock-options="--use-contents=../index.html \
275 --use-index=../doc-index.html" \
276 $(FLAGGED_CONFIGURE_ARGS) \
277 --configure-option=--with-cc=$(CC)
278
279 $(foreach SUBDIR,$(SUBDIRS), \
280 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
281 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
282 -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
283 $(MKDIRHIER) `dirname $@`
284 ( cd $* && setup/Setup configure $(ALL_CONFIGURE_FLAGS) ) \
285 && touch $@ || touch $*/unbuildable
286 # We don't touch $@ if configure failed as we would prefer to try
287 # configuring it next time round, rather than assuming it'll still fail.
288 # This is particularly important for bootlibs, where failure means the
289 # build dies!
290
291 # Build the library using 'make'
292 # We re-run 'setup makefile' each time, just in case any preprocessing
293 # needs to be done. However, we're careful not to overwrite GNUmakefile
294 # if it hasn't changed, so that dependency-generation isn't forced
295 # every time.
296 # I doubt that the makefile way will work with ndp, so filter it out and use
297 # a rule below to call build.library.ndp instead
298 $(foreach SUBDIR,$(filter-out ndp,$(SUBDIRS)),make.library.$(SUBDIR)):\
299 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
300 %/setup/Setup ifBuildable/ifBuildable installPackage/installPackage
301 if $(IFBUILDABLE) $*; then \
302 cd $* && \
303 cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
304 mv GNUmakefile GNUmakefile.tmp; \
305 setup/Setup makefile -f GNUmakefile; \
306 cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
307 $(MAKE) $(MFLAGS) && \
308 setup/Setup register --inplace; \
309 fi
310
311 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
312
313 # Hack for ndp, as described above
314 make.library.ndp: build.library.ndp
315
316 # Build the library using 'setup build' (not the default)
317 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
318 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
319 %/setup/Setup ifBuildable/ifBuildable
320 if $(IFBUILDABLE) $*; then \
321 cd $* && \
322 setup/Setup build $(addprefix --ghc-option=,$(GhcLibHcOpts)); \
323 setup/Setup register --inplace; \
324 fi
325
326 .PHONY: doc html
327
328 html: doc
329
330 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
331 sh gen_contents_index --inplace
332
333 # Making hyperlinked source only works if we have hscolour
334 ifneq "$(HSCOLOUR)" ""
335 CABAL_HADDOCK_FLAGS=--hyperlink-source
336 endif
337
338 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
339 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
340 %/setup/Setup ifBuildable/ifBuildable
341 if $(IFBUILDABLE) $*; then \
342 cd $* && setup/Setup haddock --html-location='../$$pkg' \
343 $(CABAL_HADDOCK_FLAGS); \
344 fi
345 ifneq "$(HSCOLOUR)" ""
346 # We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
347 # mismatch
348 if $(IFBUILDABLE) $*; then cp hscolour.css $*/dist/doc/html/*/src/; fi
349 endif
350
351 .PHONY: distclean clean clean.library.%
352
353 distclean: clean
354
355 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
356 $(RM) -f stamp/bootstrapping.*
357 $(RM) -rf bootstrapping.*
358 $(RM) -rf ifBuildable
359 $(RM) -rf installPackage
360 $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
361 $(RM) -f haddock* *.gif
362
363 distclean:
364 $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
365
366 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
367 clean.library.%:
368 $(RM) -f stamp/configure.library.*.$* $*/unbuildable
369 -cd $* && setup/Setup clean
370 $(RM) -rf $*/setup
371 $(RM) $*/GNUmakefile $*/Makefile.local
372 endif
373
374 # -----------------------------------------------------------------------------
375
376 .PHONY: install install-docs install.library.%
377
378 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
379 ifeq "$(HADDOCK_DOCS)" "YES"
380 $(INSTALL_DIR) $(DESTDIR)$(html_installed_root)
381 $(INSTALL_DATA) index.html doc-index*.html $(DESTDIR)$(html_installed_root)
382 $(INSTALL_SCRIPT) gen_contents_index $(DESTDIR)$(html_installed_root)
383 # Hacks:
384 $(INSTALL_DATA) base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
385 $(INSTALL_DATA) base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
386 $(INSTALL_DATA) base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
387 endif
388
389 # Cabal doesn't let us ask to install docs only, so do nothing here
390 install-docs:
391 @:
392
393 # Ideally this would depend on a stamp/build.library.%, but if it does
394 # then we can't change the libraries and then just rerun make.
395 # Thus if you install without building then it will just break.
396
397 # prefix and (on Windows) htmldir use $topdir when configuring, so we
398 # need to tell installPackage the real path to use when installing.
399
400 # We also need to pass all the other directories in, as they can be
401 # overridden when installing a bindist.
402
403 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
404 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
405 if $(IFBUILDABLE) $*; then \
406 cd $* && \
407 $(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)' ; \
408 fi
409
410 .PHONY: binary-dist binary-dist.library.%
411
412 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
413
414 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
415 mkdir $(BIN_DIST_LIBDIR)/installPackage
416 cp installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
417 mkdir $(BIN_DIST_LIBDIR)/ifBuildable
418 cp ifBuildable/ifBuildable $(BIN_DIST_LIBDIR)/ifBuildable
419 cp Makefile $(BIN_DIST_LIBDIR)
420 ifeq "$(HADDOCK_DOCS)" "YES"
421 cp gen_contents_index $(BIN_DIST_LIBDIR)
422 cp index.html $(BIN_DIST_LIBDIR)
423 cp doc-index*.html $(BIN_DIST_LIBDIR)
424 endif
425 cp -pR stamp $(BIN_DIST_LIBDIR)
426
427 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
428 binary-dist.library.%:
429 if $(IFBUILDABLE) $*; then \
430 $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*; \
431 cd $* && \
432 cp $*.cabal $(BIN_DIST_LIBDIR)/$* && \
433 cp LICENSE $(BIN_DIST_LIBDIR)/$* && \
434 cp -R dist $(BIN_DIST_LIBDIR)/$* && \
435 $(FIND) . -name "*.buildinfo" -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
436 $(FIND) . -name unbuildable -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
437 (cp -RL include $(BIN_DIST_LIBDIR)/$* || true) && \
438 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
439 \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
440 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
441 \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
442 -exec rm {} \; ; \
443 fi
444
445 # Ignore some doc targets that we don't support
446 # The root recurses into us when these targets are made
447 .PHONY: html-no-chunks chm HxS fo dvi ps pdf
448 html-no-chunks chm HxS fo dvi ps pdf:
449 @:
450