8e0e665e18934c2587b15944352a2f81114ee328
[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 include $(TOP)/mk/cabal-flags.mk
41
42 # Any libraries listed here should also be in ../packages
43
44 SUBDIRS = ghc-prim $(INTEGER_LIBRARY) base array packedstring
45 SUBDIRS += containers bytestring old-locale old-time filepath directory
46 ifeq "$(GhcLibsWithUnix)" "YES"
47 SUBDIRS += unix
48 endif
49 ifeq "$(Windows)" "YES"
50 SUBDIRS += $(wildcard Win32)
51 endif
52 SUBDIRS += process pretty hpc template-haskell editline Cabal random haskell98
53
54 # Set GhcBootLibs=YES from the command line to work with just the libraries
55 # needed to bootstrap GHC.
56 ifneq "$(GhcBootLibs)" "YES"
57 SUBDIRS += $(wildcard regex-base)
58 SUBDIRS += $(wildcard regex-posix)
59 SUBDIRS += $(wildcard regex-compat)
60 SUBDIRS += $(wildcard parsec)
61 SUBDIRS += $(wildcard haskell-src)
62 SUBDIRS += $(wildcard html)
63 SUBDIRS += $(wildcard network)
64 SUBDIRS += $(wildcard QuickCheck)
65 SUBDIRS += $(wildcard HUnit)
66 SUBDIRS += $(wildcard mtl)
67 SUBDIRS += $(wildcard time)
68 SUBDIRS += $(wildcard stm)
69 SUBDIRS += $(wildcard xhtml)
70 SUBDIRS += $(wildcard parallel)
71 SUBDIRS_BUILD += $(wildcard dph/dph-base)
72 SUBDIRS_BUILD += $(wildcard dph/dph-prim-interface)
73 SUBDIRS_BUILD += $(wildcard dph/dph-prim-seq)
74 SUBDIRS_BUILD += $(wildcard dph/dph-prim-par)
75 SUBDIRS_BUILD += $(wildcard dph/dph)
76 endif
77
78 SUBDIRS += $(SUBDIRS_BUILD)
79
80 # -----------------------------------------------------------------------------
81
82 empty=
83 space=$(empty) $(empty)
84
85 # -----------------------------------------------------------------------------
86
87 ifeq "$(ghc_ge_609)" "YES"
88 GhcLibHcOpts += -fno-warn-deprecated-flags
89 endif
90
91 ifeq "$(RelocatableBuild)" "YES"
92 # On Windows we want to make moveable bindists, but we need to tell
93 # ghc-pkg where the haddock docs are. Therefore we completely ignore
94 # where the user tells us to put the haddock documentation and put it
95 # somewhere whose relative location we know. When installing we need
96 # to give Cabal a real path, though.
97 iprefix = $$topdir
98 ibindir = $$topdir
99 ilibdir = $$topdir
100 ilibexecdir = $$topdir
101 idynlibdir = $$topdir
102 idatadir = $$topdir
103 idocdir = $$topdir/doc/libraries/$$pkg
104 ihaddockdir = $$topdir/doc/libraries/$$pkg
105 ihtmldir = $$httptopdir/doc/libraries/$$pkg
106 html_installed_root = $(prefix)/doc/libraries
107 else
108 # On non-Windows we can just give absolute paths all the time, and
109 # thus obey the htmldir that we are given.
110 iprefix = $(prefix)
111 ibindir = $(bindir)
112 ilibdir = $(libdir)
113 ilibexecdir = $(libexecdir)
114 idynlibdir = $(dynlibdir)
115 idatadir = $(datadir)
116 idocdir = $(docdir)/libraries/$$pkg
117 ihaddockdir = $(htmldir)/libraries/$$pkg
118 ihtmldir = $(htmldir)/libraries/$$pkg
119 html_installed_root = $(htmldir)/libraries
120 endif
121
122 ifneq "$(DOING_BIN_DIST)" "YES"
123
124 CONFIGURE_OPTS =
125 CONFIGURE_STAMP_EXTRAS :=
126
127 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
128 CONFIGURE_OPTS += --enable-library-profiling
129 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
130 endif
131
132 ifeq "$(BuildSharedLibs)" "YES"
133 CONFIGURE_OPTS += --enable-shared
134 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
135 endif
136
137 ifeq "$(SplitObjs)" "YES"
138 CONFIGURE_OPTS += --enable-split-objs
139 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
140 endif
141
142 .PHONY: subdirs
143
144 subdirs:
145 @echo $(SUBDIRS)
146
147 HERE_ABS=$(FPTOOLS_TOP_ABS)/libraries
148
149 IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/packages
150
151 CABAL_GHC_FLAGS = -Wall
152 ifeq "$(ghc_ge_605)" "NO"
153 CABAL_GHC_FLAGS += -cpp
154 endif
155
156 # Euch, hideous hack:
157 CABAL_VERSION = $(shell grep "^Version:" Cabal/Cabal.cabal | sed -e "s/^Version: //" -e 's/\./,/g')
158
159 BOOTSTRAPPING_FLAGS = $(CABAL_GHC_FLAGS) -DCABAL_VERSION=$(CABAL_VERSION) -odir $(HERE_ABS)/bootstrapping -hidir $(HERE_ABS)/bootstrapping -i$(HERE_ABS)/Cabal -i$(HERE_ABS)/filepath -i$(HERE_ABS)/hpc
160
161 .PHONY: boot
162
163 boot: ifBuildable/ifBuildable cabal-bin bootstrapping.conf
164
165 cabal-bin: cabal-bin.hs
166 $(GHC) $(BOOTSTRAPPING_FLAGS) --make cabal-bin -o cabal-bin
167
168 bootstrapping.conf: cabal-bin
169 echo "[]" > $@.tmp
170 -cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
171 cd filepath && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
172 cd filepath && $(CABAL) build --distpref=dist-bootstrapping
173 cd filepath && $(CABAL) install --distpref=dist-bootstrapping --inplace
174 -cd Cabal && $(CABAL) clean --distpref=dist-bootstrapping
175 cd Cabal && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
176 cd Cabal && $(CABAL) build --distpref=dist-bootstrapping
177 cd Cabal && $(CABAL) install --distpref=dist-bootstrapping --inplace
178 -cd hpc && $(CABAL) clean --distpref=dist-bootstrapping
179 cd hpc && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
180 cd hpc && $(CABAL) build --distpref=dist-bootstrapping
181 cd hpc && $(CABAL) install --distpref=dist-bootstrapping --inplace
182 mv $@.tmp $@
183
184 ifBuildable/ifBuildable: ifBuildable.hs
185 -$(RM) -rf ifBuildable
186 mkdir ifBuildable
187 $(CP) ifBuildable.hs ifBuildable/
188 ifeq "$(stage)" "2"
189 cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable
190 else
191 cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
192 endif
193
194 .PHONY: all build configure
195
196 all: build
197
198 ifeq "$(HADDOCK_DOCS)" "YES"
199 all: doc
200 endif
201
202 .PHONY: rebuild.library.%
203 .PHONY: remake.library.%
204
205 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
206 rebuild.library.%: clean.library.% build.library.%
207
208 $(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
209 remake.library.%: clean.library.% make.library.%
210
211 # NB. we're depending on make chasing dependencies from left to right here.
212 # This bit goes wrong with 'make -j'.
213 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
214
215 configure: $(foreach SUBDIR,$(SUBDIRS), \
216 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
217
218 .PHONY: build.library.%
219 .PHONY: make.library.%
220
221 # We should depend on %/%.cabal here (and in other rules), but make
222 # makes that difficult.
223
224 ALL_CONFIGURE_FLAGS = \
225 $(INSTALL_DIRS_CONFIGURE_FLAGS) \
226 $(USE_STAGE1_CONFIGURE_FLAGS) \
227 $(COMMON_CONFIGURE_FLAGS) \
228 --haddock-options="--use-contents=../index.html \
229 --use-index=../doc-index.html" \
230 $(CONFIGURE_OPTS)
231
232 $(foreach SUBDIR,$(SUBDIRS), \
233 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
234 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: cabal-bin \
235 bootstrapping.conf
236 -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
237 $(MKDIRHIER) `dirname $@`
238 ( cd $* && $(CABAL) configure $(ALL_CONFIGURE_FLAGS) ) \
239 && touch $@ || touch $*/unbuildable
240 # We don't touch $@ if configure failed as we would prefer to try
241 # configuring it next time round, rather than assuming it'll still fail.
242 # This is particularly important for bootlibs, where failure means the
243 # build dies!
244
245 # Build the library using 'make'
246 # We re-run 'setup makefile' each time, just in case any preprocessing
247 # needs to be done. However, we're careful not to overwrite GNUmakefile
248 # if it hasn't changed, so that dependency-generation isn't forced
249 # every time.
250 # Packages in $(SUBDIRS_BUILD) need to use the build.* rules instead of
251 # make.*, so filter them out and use an alternate rule below instead.
252 $(foreach SUBDIR,$(filter-out $(SUBDIRS_BUILD),$(SUBDIRS)),make.library.$(SUBDIR)):\
253 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
254 cabal-bin ifBuildable/ifBuildable bootstrapping.conf
255 if $(IFBUILDABLE) $*; then \
256 cd $* && \
257 cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
258 mv GNUmakefile GNUmakefile.tmp; \
259 $(CABAL) makefile -f GNUmakefile; \
260 cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
261 $(MAKE) $(MFLAGS) && \
262 $(CABAL) register --inplace; \
263 fi
264
265 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
266
267 # Alternate rule, as described above
268 $(foreach SUBDIR,$(SUBDIRS_BUILD),make.library.$(SUBDIR)):\
269 make.library.%: build.library.%
270
271 # Build the library using 'setup build' (not the default)
272 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
273 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
274 cabal-bin ifBuildable/ifBuildable bootstrapping.conf
275 if $(IFBUILDABLE) $*; then \
276 cd $* && \
277 $(CABAL) build $(BUILD_FLAGS); \
278 $(CABAL) register --inplace; \
279 fi
280
281 .PHONY: doc html
282
283 html: doc
284
285 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
286 sh gen_contents_index --inplace
287
288 # Making hyperlinked source only works if we have hscolour
289 ifneq "$(HSCOLOUR)" ""
290 CABAL_HADDOCK_FLAGS=--hyperlink-source
291 endif
292
293 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
294 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
295 cabal-bin ifBuildable/ifBuildable bootstrapping.conf
296 if $(IFBUILDABLE) $*; then \
297 cd $* && $(CABAL) haddock --html-location='../$$pkg' \
298 $(CABAL_HADDOCK_FLAGS); \
299 fi
300 ifneq "$(HSCOLOUR)" ""
301 # We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
302 # mismatch
303 if $(IFBUILDABLE) $*; then cp hscolour.css $*/dist/doc/html/*/src/; fi
304 endif
305
306 .PHONY: distclean clean clean.library.%
307
308 distclean: clean
309
310 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
311 -cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
312 -cd Cabal && $(CABAL) clean --distpref=dist-bootstrapping
313 -cd hpc && $(CABAL) clean --distpref=dist-bootstrapping
314 $(RM) -rf bootstrapping/*
315 $(RM) -f bootstrapping.conf bootstrapping.conf.old
316 $(RM) -f bootstrapping.conf.tmp bootstrapping.conf.tmp.old
317 $(RM) -f cabal-bin cabal-bin.exe
318 $(RM) -rf ifBuildable
319 $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
320 $(RM) -f haddock* *.gif
321
322 distclean:
323 $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
324
325 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
326 clean.library.%:
327 $(RM) -f stamp/configure.library.*.$* $*/unbuildable
328 -cd $* && $(CABAL) clean
329 $(RM) -f $*/Setup $*/Setup.exe $*/Setup.hi $*/Setup.o
330 $(RM) $*/GNUmakefile $*/Makefile.local
331 endif
332
333 # -----------------------------------------------------------------------------
334
335 .PHONY: install install-docs install.library.%
336
337 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
338 ifeq "$(HADDOCK_DOCS)" "YES"
339 $(INSTALL_DIR) $(DESTDIR)$(html_installed_root)
340 $(INSTALL_DATA) index.html doc-index*.html $(DESTDIR)$(html_installed_root)
341 $(INSTALL_SCRIPT) gen_contents_index $(DESTDIR)$(html_installed_root)
342 # Hacks:
343 $(INSTALL_DATA) base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
344 $(INSTALL_DATA) base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
345 $(INSTALL_DATA) base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
346 endif
347
348 # Cabal doesn't let us ask to install docs only, so do nothing here
349 install-docs:
350 @:
351
352 # Ideally this would depend on a stamp/build.library.%, but if it does
353 # then we can't change the libraries and then just rerun make.
354 # Thus if you install without building then it will just break.
355
356 # prefix and (on Windows) htmldir use $topdir when configuring, so we
357 # need to tell installPackage the real path to use when installing.
358
359 # We also need to pass all the other directories in, as they can be
360 # overridden when installing a bindist.
361
362 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
363 install.library.%: ifBuildable/ifBuildable
364 if $(IFBUILDABLE) $*; then \
365 cd $* && \
366 $(INSTALL_PACKAGE) install '$(GHC_PKG_PROG)' '$(DESTDIR)$(libdir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' ; \
367 fi
368
369 .PHONY: binary-dist binary-dist.library.%
370
371 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
372
373 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
374 mkdir $(BIN_DIST_LIBDIR)/ifBuildable
375 cp ifBuildable/ifBuildable $(BIN_DIST_LIBDIR)/ifBuildable
376 cp Makefile $(BIN_DIST_LIBDIR)
377 ifeq "$(HADDOCK_DOCS)" "YES"
378 cp gen_contents_index $(BIN_DIST_LIBDIR)
379 cp index.html $(BIN_DIST_LIBDIR)
380 cp doc-index*.html $(BIN_DIST_LIBDIR)
381 endif
382 cp -pR stamp $(BIN_DIST_LIBDIR)
383
384 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
385 binary-dist.library.%:
386 if $(IFBUILDABLE) $*; then \
387 $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*; \
388 cd $* && \
389 cp $*.cabal $(BIN_DIST_LIBDIR)/$* && \
390 cp LICENSE $(BIN_DIST_LIBDIR)/$* && \
391 cp -R dist $(BIN_DIST_LIBDIR)/$* && \
392 $(FIND) . -name "*.buildinfo" -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
393 $(FIND) . -name unbuildable -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
394 (cp -RL include $(BIN_DIST_LIBDIR)/$* || true) && \
395 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
396 \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
397 $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
398 \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
399 -exec rm {} \; ; \
400 fi
401
402 # Ignore some doc targets that we don't support
403 # The root recurses into us when these targets are made
404 .PHONY: html-no-chunks chm HxS fo dvi ps pdf
405 html-no-chunks chm HxS fo dvi ps pdf:
406 @:
407