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