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