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