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