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