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