Don't compile Cabal with -cpp -fffi
[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 CABAL_GHC_FLAGS = -Wall
172
173 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
174 %/setup/Setup: $(BOOTSTRAP_STAMPS)
175         -$(RM) -rf $*/setup
176         mkdir $*/setup
177         $(CP) $*/Setup.*hs $*/setup
178         cd $*/setup && $(GHC) $(CABAL_GHC_FLAGS) --make Setup.*hs -o Setup \
179                               $(BOOTSTRAP_INC)
180
181 installPackage/installPackage: installPackage.hs $(BOOTSTRAP_STAMPS)
182         -$(RM) -rf installPackage
183         mkdir installPackage
184         $(CP) installPackage.hs installPackage/
185 ifeq "$(stage)" "2"
186         cd installPackage && ../$(HC) $(CABAL_GHC_FLAGS) \
187                                     --make installPackage -o installPackage \
188                                     $(BOOTSTRAP_INC) $(DEPLOYMENT_OPTS)
189 else
190         cd installPackage && $(GHC) $(CABAL_GHC_FLAGS) \
191                                     --make installPackage -o installPackage \
192                                     $(BOOTSTRAP_INC)
193 endif
194 # TODO: The conditional is yucky, but we need to be able to build with stage1
195 #       for bindists and as installPackages/ has no Makefile, it seems hard
196 #       to make this nicer.
197
198 ifBuildable/ifBuildable: ifBuildable.hs
199         -$(RM) -rf ifBuildable
200         mkdir ifBuildable
201         $(CP) ifBuildable.hs ifBuildable/
202 ifeq "$(stage)" "2"
203         cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable \
204                                  $(DEPLOYMENT_OPTS)
205 else
206         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
207 endif
208
209 IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/libraries/boot-packages
210
211 $(BOOTSTRAP_STAMPS): stamp/bootstrapping.%:
212         $(RM) -rf bootstrapping.$*
213         $(CP) -R $* bootstrapping.$*
214         $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
215                                  -exec $(RM) -f {} \;
216         touch $@
217
218 .PHONY: all build configure
219
220 all: build
221
222 ifeq "$(HADDOCK_DOCS)" "YES"
223 all: doc
224 endif
225
226 .PHONY: rebuild.library.%
227 .PHONY: remake.library.%
228
229 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
230 rebuild.library.%: clean.library.% build.library.%
231
232 $(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
233 remake.library.%: clean.library.% make.library.%
234
235 # NB. we're depending on make chasing dependencies from left to right here.
236 # This bit goes wrong with 'make -j'.
237 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
238 build: installPackage/installPackage
239
240 configure: $(foreach SUBDIR,$(SUBDIRS), \
241              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
242
243 .PHONY: build.library.%
244 .PHONY: make.library.%
245
246 # We should depend on %/%.cabal here (and in other rules), but make
247 # makes that difficult.
248
249 # We put non-existant paths in when configuring, as we require that
250 # builds don't depend on these paths when making bindists.
251
252 # We rely on all the CONFIGURE_ARGS being quoted with '...', and there
253 # being no 's inside the values.
254 FLAGGED_CONFIGURE_ARGS = $(subst $(space)',\
255                                  $(space)--configure-option=',\
256                                  $(space)$(CONFIGURE_ARGS))
257
258 ifeq "$(Windows)" "YES"
259 NONEXISTENT=c:/NONEXISTENT
260 else
261 NONEXISTENT=/NONEXISTENT
262 endif
263
264 ALL_CONFIGURE_FLAGS = \
265                    $(CONFIGURE_OPTS) \
266                    --prefix=$(NONEXISTENT) \
267                    --bindir=$(NONEXISTENT) \
268                    --libdir=$(NONEXISTENT) \
269                    --libsubdir='$$pkgid' \
270                    --libexecdir=$(NONEXISTENT) \
271                    --datadir=$(NONEXISTENT) \
272                    --docdir=$(NONEXISTENT) \
273                            --haddockdir=$(NONEXISTENT) \
274                    --htmldir=$(NONEXISTENT) \
275                    --with-compiler=$(FPTOOLS_TOP_ABS)/compiler/stage1/ghc-inplace \
276                    --with-hc-pkg=$(FPTOOLS_TOP_ABS)/utils/ghc-pkg/ghc-pkg-inplace \
277                    --with-hsc2hs=$(FPTOOLS_TOP_ABS)/utils/hsc2hs/hsc2hs-inplace \
278                    --with-ld=$(LD) \
279                    --haddock-options="--use-contents=../index.html \
280                                       --use-index=../doc-index.html" \
281                    $(FLAGGED_CONFIGURE_ARGS) \
282                    --configure-option=--with-cc=$(CC)
283
284 $(foreach SUBDIR,$(SUBDIRS), \
285                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
286 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
287         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
288         $(MKDIRHIER) `dirname $@`
289         ( cd $* && setup/Setup configure $(ALL_CONFIGURE_FLAGS) ) \
290               && touch $@ || touch $*/unbuildable
291 # We don't touch $@ if configure failed as we would prefer to try
292 # configuring it next time round, rather than assuming it'll still fail.
293 # This is particularly important for bootlibs, where failure means the
294 # build dies!
295
296 # Build the library using 'make'
297 # We re-run 'setup makefile' each time, just in case any preprocessing
298 # needs to be done.  However, we're careful not to overwrite GNUmakefile
299 # if it hasn't changed, so that dependency-generation isn't forced
300 # every time.
301 # Packages in $(SUBDIRS_BUILD) need to use the build.* rules instead of
302 # make.*, so filter them out and use an alternate rule below instead.
303 $(foreach SUBDIR,$(filter-out $(SUBDIRS_BUILD),$(SUBDIRS)),make.library.$(SUBDIR)):\
304 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
305                 %/setup/Setup ifBuildable/ifBuildable installPackage/installPackage
306         if $(IFBUILDABLE) $*; then \
307           cd $* && \
308           cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
309           mv GNUmakefile GNUmakefile.tmp; \
310           setup/Setup makefile -f GNUmakefile; \
311           cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
312           $(MAKE) $(MFLAGS) && \
313           setup/Setup register --inplace; \
314         fi
315
316 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
317
318 # Alternate rule, as described above
319 $(foreach SUBDIR,$(SUBDIRS_BUILD),make.library.$(SUBDIR)):\
320 make.library.%: build.library.%
321
322 # Build the library using 'setup build' (not the default)
323 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
324 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
325                  %/setup/Setup ifBuildable/ifBuildable
326         if $(IFBUILDABLE) $*; then \
327           cd $* && \
328           setup/Setup build $(addprefix --ghc-option=,$(GhcLibHcOpts)); \
329           setup/Setup register --inplace; \
330         fi
331
332 .PHONY: doc html
333
334 html: doc
335
336 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
337         sh gen_contents_index --inplace
338
339 # Making hyperlinked source only works if we have hscolour
340 ifneq "$(HSCOLOUR)" ""
341 CABAL_HADDOCK_FLAGS=--hyperlink-source
342 endif
343
344 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
345 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
346                %/setup/Setup ifBuildable/ifBuildable
347         if $(IFBUILDABLE) $*; then \
348           cd $* && setup/Setup haddock --html-location='../$$pkg' \
349                                        $(CABAL_HADDOCK_FLAGS); \
350         fi
351 ifneq "$(HSCOLOUR)" ""
352 # We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
353 # mismatch
354         if $(IFBUILDABLE) $*; then cp hscolour.css $*/dist/doc/html/*/src/; fi
355 endif
356
357 .PHONY: distclean clean clean.library.%
358
359 distclean: clean
360
361 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
362         $(RM) -f stamp/bootstrapping.*
363         $(RM) -rf bootstrapping.*
364         $(RM) -rf ifBuildable
365         $(RM) -rf installPackage
366         $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
367         $(RM) -f haddock* *.gif
368
369 distclean:
370         $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
371
372 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
373 clean.library.%:
374         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
375         -cd $* && setup/Setup clean
376         $(RM) -rf $*/setup
377         $(RM) $*/GNUmakefile $*/Makefile.local
378 endif
379
380 # -----------------------------------------------------------------------------
381
382 .PHONY: install install-docs install.library.%
383
384 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
385 ifeq "$(HADDOCK_DOCS)" "YES"
386         $(INSTALL_DIR)                                                     $(DESTDIR)$(html_installed_root)
387         $(INSTALL_DATA)   index.html doc-index*.html                       $(DESTDIR)$(html_installed_root)
388         $(INSTALL_SCRIPT) gen_contents_index                               $(DESTDIR)$(html_installed_root)
389         # Hacks:
390         $(INSTALL_DATA)   base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
391         $(INSTALL_DATA)   base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
392         $(INSTALL_DATA)   base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
393 endif
394
395 # Cabal doesn't let us ask to install docs only, so do nothing here
396 install-docs:
397         @:
398
399 # Ideally this would depend on a stamp/build.library.%, but if it does
400 # then we can't change the libraries and then just rerun make.
401 # Thus if you install without building then it will just break.
402
403 # prefix and (on Windows) htmldir use $topdir when configuring, so we
404 # need to tell installPackage the real path to use when installing.
405
406 # We also need to pass all the other directories in, as they can be
407 # overridden when installing a bindist.
408
409 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
410 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
411         if $(IFBUILDABLE) $*; then \
412           cd $* && \
413           $(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)' ; \
414         fi
415
416 .PHONY: binary-dist binary-dist.library.%
417
418 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
419
420 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
421         mkdir                               $(BIN_DIST_LIBDIR)/installPackage
422         cp        installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
423         mkdir                               $(BIN_DIST_LIBDIR)/ifBuildable
424         cp        ifBuildable/ifBuildable       $(BIN_DIST_LIBDIR)/ifBuildable
425         cp    Makefile                      $(BIN_DIST_LIBDIR)
426 ifeq "$(HADDOCK_DOCS)" "YES"
427         cp    gen_contents_index            $(BIN_DIST_LIBDIR)
428         cp    index.html                    $(BIN_DIST_LIBDIR)
429         cp    doc-index*.html               $(BIN_DIST_LIBDIR)
430 endif
431         cp -pR stamp                         $(BIN_DIST_LIBDIR)
432
433 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
434 binary-dist.library.%:
435         if $(IFBUILDABLE) $*; then \
436           $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*; \
437           cd $* && \
438           cp    $*.cabal      $(BIN_DIST_LIBDIR)/$* && \
439           cp    LICENSE       $(BIN_DIST_LIBDIR)/$* && \
440           cp -R dist          $(BIN_DIST_LIBDIR)/$* && \
441           $(FIND) . -name "*.buildinfo" -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
442           $(FIND) . -name unbuildable -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
443           (cp -RL include      $(BIN_DIST_LIBDIR)/$* || true) && \
444           $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
445              \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
446           $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
447              \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
448              -exec rm {} \; ; \
449         fi
450
451 # Ignore some doc targets that we don't support
452 # The root recurses into us when these targets are made
453 .PHONY: html-no-chunks chm HxS fo dvi ps pdf
454 html-no-chunks chm HxS fo dvi ps pdf:
455         @:
456