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