5110687c6e9822cb0791c773bb2803410422a559
[ghc-hetmet.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 #   [ -f foo/configure.ac ] && ( cd foo && autoreconf )
21 #   make make.library.foo
22
23 .PHONY: default_target
24
25 default_target: all
26
27 # make doesn't give us an easy way to get the libraries built in
28 # dependency order the first time, but not rebuild base (for example)
29 # when we want to rebuild another library later.
30 # So for now we just don't do anything in parallel in here.
31 .NOTPARALLEL:
32
33 # Ideally we'd just include something to give us variables
34 # for paths and arguments to tools etc, and those set in mk/build.mk.
35 TOP=..
36 include $(TOP)/mk/boilerplate.mk
37 include $(TOP)/mk/cabal-flags.mk
38
39 # Any libraries listed here should also be in ../packages
40
41 SUBDIRS  = ghc-prim $(INTEGER_LIBRARY) base syb base3-compat array packedstring
42 SUBDIRS += containers bytestring old-locale old-time filepath 
43 ifeq "$(GhcLibsWithUnix)" "YES"
44 SUBDIRS += unix
45 endif
46 ifeq "$(Windows)" "YES"
47 SUBDIRS += $(wildcard Win32)
48 endif
49 SUBDIRS += directory 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 time)
65 SUBDIRS += $(wildcard stm)
66 SUBDIRS += $(wildcard xhtml)
67 SUBDIRS += $(wildcard parallel)
68 ifneq "$(wildcard dph)" ""
69 SUBDIRS += dph/dph-base
70 SUBDIRS += dph/dph-prim-interface
71 SUBDIRS += dph/dph-prim-seq
72 SUBDIRS += dph/dph-prim-par
73 SUBDIRS += dph/dph-seq
74 SUBDIRS += dph/dph-par
75 endif
76 endif
77
78 # -----------------------------------------------------------------------------
79
80 empty=
81 space=$(empty) $(empty)
82
83 # -----------------------------------------------------------------------------
84
85 ifeq "$(ghc_ge_609)" "YES"
86 GhcLibHcOpts += -fno-warn-deprecated-flags
87 endif
88
89 IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/packages
90
91 ifneq "$(DOING_BIN_DIST)" "YES"
92
93 CONFIGURE_OPTS =
94 CONFIGURE_STAMP_EXTRAS :=
95
96 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
97 CONFIGURE_OPTS += --enable-library-profiling
98 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
99 endif
100
101 ifeq "$(BuildSharedLibs)" "YES"
102 CONFIGURE_OPTS += --enable-shared
103 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
104 endif
105
106 ifeq "$(SplitObjs)" "YES"
107 CONFIGURE_OPTS += --enable-split-objs
108 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
109 endif
110
111 .PHONY: subdirs
112
113 subdirs:
114         @echo $(SUBDIRS)
115
116 HERE_ABS=$(FPTOOLS_TOP_ABS)/libraries
117
118 CABAL_GHC_FLAGS = -Wall
119
120 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
121
122 .PHONY: boot
123
124 boot: ifBuildable/ifBuildable cabal-bin bootstrapping.conf
125
126 cabal-bin: cabal-bin.hs
127         -mkdir bootstrapping
128         $(GHC) $(BOOTSTRAPPING_FLAGS) --make cabal-bin -o cabal-bin
129
130 bootstrapping.conf: cabal-bin
131         echo "[]" > $@.tmp
132         -cd extensible-exceptions && $(CABAL) clean     --distpref=dist-bootstrapping
133         cd extensible-exceptions && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
134         cd extensible-exceptions && $(CABAL) build     --distpref=dist-bootstrapping
135         cd extensible-exceptions && $(CABAL) install   --distpref=dist-bootstrapping --inplace
136         -cd filepath && $(CABAL) clean     --distpref=dist-bootstrapping
137         cd filepath && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
138         cd filepath && $(CABAL) build     --distpref=dist-bootstrapping
139         cd filepath && $(CABAL) install   --distpref=dist-bootstrapping --inplace
140         -cd Cabal    && $(CABAL) clean     --distpref=dist-bootstrapping
141         cd Cabal    && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
142         cd Cabal    && $(CABAL) build     --distpref=dist-bootstrapping
143         cd Cabal    && $(CABAL) install   --distpref=dist-bootstrapping --inplace
144         -cd hpc    && $(CABAL) clean     --distpref=dist-bootstrapping
145         cd hpc    && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
146         cd hpc    && $(CABAL) build     --distpref=dist-bootstrapping
147         cd hpc    && $(CABAL) install   --distpref=dist-bootstrapping --inplace
148         mv $@.tmp $@
149
150 ifBuildable/ifBuildable: ifBuildable.hs
151         -$(RM) -rf ifBuildable
152         mkdir ifBuildable
153         $(CP) ifBuildable.hs ifBuildable/
154 ifeq "$(stage)" "2"
155         cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable
156 else
157         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
158 endif
159
160 .PHONY: all build configure
161
162 all: build
163
164 .PHONY: rebuild.library.%
165 .PHONY: remake.library.%
166
167 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
168 rebuild.library.%: clean.library.% build.library.%
169
170 $(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
171 remake.library.%: clean.library.% make.library.%
172
173 # NB. we're depending on make chasing dependencies from left to right here.
174 # This bit goes wrong with 'make -j'.
175 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
176
177 configure: $(foreach SUBDIR,$(SUBDIRS), \
178              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
179
180 .PHONY: build.library.%
181 .PHONY: make.library.%
182
183 # We should depend on %/%.cabal here (and in other rules), but make
184 # makes that difficult.
185
186 ALL_CONFIGURE_FLAGS = \
187                $(INSTALL_DIRS_CONFIGURE_FLAGS) \
188                $(USE_STAGE1_CONFIGURE_FLAGS) \
189                $(COMMON_CONFIGURE_FLAGS) \
190                    --haddock-options="--use-contents=../index.html \
191                                       --use-index=../doc-index.html" \
192                    $(CONFIGURE_OPTS)
193
194 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-par: \
195     dph/dph-par
196
197 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-seq: \
198     dph/dph-seq
199
200 dph/%:
201         $(MAKE) -C dph $*
202
203 $(foreach SUBDIR,$(SUBDIRS), \
204                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
205 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: cabal-bin
206         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
207         $(MKDIRHIER) `dirname $@`
208         ( cd $* && $(CABAL) configure $(ALL_CONFIGURE_FLAGS) ) \
209               && touch $@ || touch $*/unbuildable
210 # We don't touch $@ if configure failed as we would prefer to try
211 # configuring it next time round, rather than assuming it'll still fail.
212 # This is particularly important for bootlibs, where failure means the
213 # build dies!
214
215 # Build the library using 'make'
216 # We re-run 'setup makefile' each time, just in case any preprocessing
217 # needs to be done.  However, we're careful not to overwrite GNUmakefile
218 # if it hasn't changed, so that dependency-generation isn't forced
219 # every time.
220 $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR)):\
221 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
222                 cabal-bin ifBuildable/ifBuildable
223         if $(IFBUILDABLE) $*; then \
224           cd $* && \
225           cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
226           mv GNUmakefile GNUmakefile.tmp; \
227           $(CABAL) makefile -f GNUmakefile; \
228           cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
229           $(MAKE) $(MFLAGS) && \
230           $(CABAL) register --inplace; \
231         fi
232
233 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
234
235 # Build the library using 'setup build' (not the default)
236 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
237 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
238                  cabal-bin ifBuildable/ifBuildable
239         if $(IFBUILDABLE) $*; then \
240           cd $* && \
241           $(CABAL) build $(BUILD_FLAGS); \
242           $(CABAL) register --inplace; \
243         fi
244
245 .PHONY: doc html
246
247 html: doc
248
249 # No docs for compat libraries for now.
250 DOC_SUBDIRS = $(filter-out %-compat, $(SUBDIRS))
251
252 doc: $(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR))
253         sh gen_contents_index --inplace
254
255 # Making hyperlinked source only works if we have hscolour
256 ifneq "$(HSCOLOUR)" ""
257 CABAL_HADDOCK_FLAGS += --hyperlink-source
258 endif
259 CABAL_HADDOCK_FLAGS += --with-haddock=$(FPTOOLS_TOP_ABS)/utils/haddock/install-inplace/bin/haddock
260
261 $(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR)):\
262 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
263                cabal-bin ifBuildable/ifBuildable
264         if $(IFBUILDABLE) $*; then \
265           cd $* && $(CABAL) haddock --html-location='../$$pkg' \
266                                     $(CABAL_HADDOCK_FLAGS); \
267         fi
268 ifneq "$(HSCOLOUR)" ""
269 # We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
270 # mismatch
271 # XXX We also need to check that the directory exists, as e.g. dph disables
272 # haddock, so the directory doesn't get made. We should remove this once
273 # we can always haddock everything.
274         if $(IFBUILDABLE) $* && [ -d $*/dist/doc/html/*/src/ ]; then cp hscolour.css $*/dist/doc/html/*/src/; fi
275 endif
276
277 .PHONY: maintainer-clean distclean clean clean.library.%
278
279 maintainer-clean: clean
280 distclean: clean
281
282 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
283         -cd extensible-exceptions && $(CABAL) clean --distpref=dist-bootstrapping
284         -cd filepath              && $(CABAL) clean --distpref=dist-bootstrapping
285         -cd Cabal                 && $(CABAL) clean --distpref=dist-bootstrapping
286         -cd hpc                   && $(CABAL) clean --distpref=dist-bootstrapping
287         $(RM) -rf bootstrapping
288         $(RM) -f bootstrapping.conf     bootstrapping.conf.old
289         $(RM) -f bootstrapping.conf.tmp bootstrapping.conf.tmp.old
290         $(RM) -f cabal-bin cabal-bin.exe
291         $(RM) -rf ifBuildable
292         $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
293         $(RM) -f haddock* *.gif
294         $(RM) -rf stamp/*
295 ifneq "$(wildcard dph)" ""
296         $(MAKE) -C dph clean
297 endif
298
299 maintainer-clean distclean:
300         $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
301
302 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
303 clean.library.%:
304         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
305         -cd $* && $(CABAL) clean
306         $(RM) -f $*/Setup $*/Setup.exe $*/Setup.hi $*/Setup.o
307         $(RM) $*/GNUmakefile $*/Makefile.local
308 endif
309
310 # -----------------------------------------------------------------------------
311
312 .PHONY: install install-docs install.library.%
313
314 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
315 ifeq "$(HADDOCK_DOCS)" "YES"
316         $(INSTALL_DIR)                                                     $(DESTDIR)$(html_installed_root)
317         $(INSTALL_DATA)   index.html doc-index*.html                       $(DESTDIR)$(html_installed_root)
318         $(INSTALL_SCRIPT) gen_contents_index                               $(DESTDIR)$(html_installed_root)
319         $(INSTALL_DATA)   prologue.txt                                     $(DESTDIR)$(html_installed_root)
320         # Hacks:
321         $(INSTALL_DATA)   base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
322         $(INSTALL_DATA)   base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
323         $(INSTALL_DATA)   base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
324 endif
325
326 # Cabal doesn't let us ask to install docs only, so do nothing here
327 install-docs:
328         @:
329
330 # Ideally this would depend on a stamp/build.library.%, but if it does
331 # then we can't change the libraries and then just rerun make.
332 # Thus if you install without building then it will just break.
333
334 # prefix and (on Windows) htmldir use $topdir when configuring, so we
335 # need to tell installPackage the real path to use when installing.
336
337 # We also need to pass all the other directories in, as they can be
338 # overridden when installing a bindist.
339
340 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
341 install.library.%: ifBuildable/ifBuildable
342         if $(IFBUILDABLE) $*; then \
343           cd $* && \
344           $(INSTALL_PACKAGE) install '$(GHC_PKG_INSTALL_PROG)' '$(DESTDIR)$(datadir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' ; \
345         fi
346
347 .PHONY: binary-dist binary-dist.library.%
348
349 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
350
351 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
352 ifeq "$(WHERE_AM_I)" ""
353         echo "I don't know where I am" >&2
354         exit 1
355 endif
356         echo $(WHERE_AM_I)/Makefile >> $(BIN_DIST_LIST)
357 # XXX This needs to be changed: This ifBuildable is built with the
358 # bootstrapping compiler, so isn't OS X friendly. It should be made into
359 # a Cabal package if we keep it. However, once we drop extralibs we can
360 # probably remove it anyway.
361         echo $(WHERE_AM_I)/ifBuildable/ifBuildable >> $(BIN_DIST_LIST)
362         for FILE in dph/dph-prim-interface/interface/*.h dph/dph/LICENSE; do if [ -f $$FILE ]; then echo $(WHERE_AM_I)/$$FILE >> $(BIN_DIST_LIST); fi; done
363 ifeq "$(HADDOCK_DOCS)" "YES"
364         for FILE in gen_contents_index prologue.txt index.html doc-index*.html; do echo $(WHERE_AM_I)/$$FILE >> $(BIN_DIST_LIST); done
365 endif
366
367 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
368 binary-dist.library.%:
369         if $(IFBUILDABLE) $*; then \
370           $(MAKE) -C $* -f Makefile.local binary-dist BINDIST_EXTRAS="$*.cabal LICENSE $*.buildinfo unbuildable" WHERE_AM_I=$(WHERE_AM_I)/$*; \
371         fi
372
373 # Ignore some doc targets that we don't support
374 # The root recurses into us when these targets are made
375 .PHONY: html-no-chunks chm HxS fo dvi ps pdf
376 html-no-chunks chm HxS fo dvi ps pdf:
377         @:
378