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