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