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