MERGED: Define and use $httptopdir for the haddock docs locations
[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 X11)
66 SUBDIRS += $(wildcard time)
67 ifeq "$(Windows)" "NO"
68 # HGL is not working on Win32, so omit it for now.  Better not to ship it
69 # at all than to ship a broken version.
70 SUBDIRS += $(wildcard HGL)
71 endif
72 SUBDIRS += $(wildcard OpenGL)
73 SUBDIRS += $(wildcard GLUT)
74 SUBDIRS += $(wildcard OpenAL)
75 SUBDIRS += $(wildcard ALUT)
76 SUBDIRS += $(wildcard stm)
77 SUBDIRS += $(wildcard xhtml)
78 SUBDIRS += $(wildcard cgi)
79 SUBDIRS += $(wildcard arrows)
80 ifeq "$(GhcLibsWithObjectIO)" "YES"
81 SUBDIRS += $(wildcard ObjectIO)
82 endif
83 SUBDIRS += $(wildcard parallel)
84 SUBDIRS += $(wildcard ndp)
85 endif
86
87 # -----------------------------------------------------------------------------
88
89 empty=
90 space=$(empty) $(empty)
91
92 # -----------------------------------------------------------------------------
93
94 ifeq "$(RelocatableBuild)" "YES"
95 # On Windows we want to make moveable bindists, but we need to tell
96 # ghc-pkg where the haddock docs are. Therefore we completely ignore
97 # where the user tells us to put the haddock documentation and put it
98 # somewhere whose relative location we know. When installing we need
99 # to give Cabal a real path, though.
100 iprefix     = $$topdir
101 ibindir     = $$topdir
102 ilibdir     = $$topdir
103 ilibexecdir = $$topdir
104 idatadir    = $$topdir
105 idocdir     = $$topdir/doc/libraries/$$pkgid
106 ihtmldir    = $$httptopdir/doc/libraries/$$pkgid
107 html_installed_root = $(prefix)/doc/libraries
108 else
109 # On non-Windows we can just give absolute paths all the time, and
110 # thus obey the htmldir that we are given.
111 iprefix     = $(prefix)
112 ibindir     = $(bindir)
113 ilibdir     = $(libdir)
114 ilibexecdir = $(libexecdir)
115 idatadir    = $(datadir)
116 idocdir     = $(docdir)/libraries/$$pkgid
117 ihtmldir    = $(htmldir)/libraries/$$pkgid
118 html_installed_root = $(htmldir)/libraries
119 endif
120
121 ifneq "$(DOING_BIN_DIST)" "YES"
122
123 CONFIGURE_OPTS =
124 CONFIGURE_STAMP_EXTRAS :=
125
126 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
127 CONFIGURE_OPTS += --enable-library-profiling
128 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
129 endif
130
131 ifneq "$(findstring $(space)dyn$(space), $(space)$(GhcLibWays)$(space))" ""
132 CONFIGURE_OPTS += --enable-shared
133 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
134 endif
135
136 ifeq "$(SplitObjs)" "YES"
137 CONFIGURE_OPTS += --enable-split-objs
138 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
139 endif
140
141 BOOTSTRAP_LIBS = Cabal filepath
142 BOOTSTRAP_STAMPS = $(addprefix stamp/bootstrapping.,$(BOOTSTRAP_LIBS))
143 BOOTSTRAP_INC_1_UP = -DCABAL_VERSION=1,3 $(addprefix -i../bootstrapping.,$(BOOTSTRAP_LIBS))
144 BOOTSTRAP_INC_2_UP = -DCABAL_VERSION=1,3 $(addprefix -i../../bootstrapping.,$(BOOTSTRAP_LIBS))
145
146 .PHONY: subdirs
147
148 subdirs:
149         @echo $(SUBDIRS)
150
151 .PHONY: boot
152
153 boot: $(BOOTSTRAP_STAMPS) ifBuildable/ifBuildable \
154           $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
155           installPackage/installPackage
156
157 # We build the Setup program in a setup subdirectory to stop it trying
158 # to use bits of base and Cabal when we build those packages.
159 # This also makes it slightly easier to clean.
160
161 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
162
163 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
164 %/setup/Setup: $(BOOTSTRAP_STAMPS)
165         -$(RM) -rf $*/setup
166         mkdir $*/setup
167         $(CP) $*/Setup.*hs $*/setup
168         cd $*/setup && $(GHC) -Wall -cpp --make Setup.*hs -o Setup \
169                               $(BOOTSTRAP_INC_2_UP)
170
171 installPackage/installPackage: installPackage.hs $(BOOTSTRAP_STAMPS)
172         -$(RM) -rf installPackage
173         mkdir installPackage
174         $(CP) installPackage.hs installPackage/
175         cd installPackage && $(GHC) -Wall -cpp \
176                                     --make installPackage -o installPackage \
177                                     $(BOOTSTRAP_INC_1_UP)
178
179 ifBuildable/ifBuildable: ifBuildable.hs
180         -$(RM) -rf ifBuildable
181         mkdir ifBuildable
182         $(CP) ifBuildable.hs ifBuildable/
183         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
184
185 $(BOOTSTRAP_STAMPS): stamp/bootstrapping.%:
186         $(RM) -rf bootstrapping.$*
187         $(CP) -R $* bootstrapping.$*
188         $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
189                                  -exec $(RM) -f {} \;
190         touch $@
191
192 .PHONY: all build configure
193
194 all: build
195
196 ifeq "$(HADDOCK_DOCS)" "YES"
197 all: doc
198 endif
199
200 .PHONY: rebuild.library.%
201
202 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
203 rebuild.library.%: clean.library.% make.library.%
204
205 # NB. we're depending on make chasing dependencies from left to right here.
206 # This bit goes wrong with 'make -j'.
207 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
208 build: installPackage/installPackage
209
210 configure: $(foreach SUBDIR,$(SUBDIRS), \
211              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
212
213 .PHONY: build.library.%
214 .PHONY: make.library.%
215
216 # We should depend on %/%.cabal here (and in other rules), but make
217 # makes that difficult.
218
219 # We put non-existant paths in when configuring, as we require that
220 # builds don't depend on these paths when making bindists.
221
222 # We rely on all the CONFIGURE_ARGS being quoted with '...', and there
223 # being no 's inside the values.
224 FLAGGED_CONFIGURE_ARGS = $(subst $(space)',\
225                                  $(space)--configure-option=',\
226                                  $(space)$(CONFIGURE_ARGS))
227
228 $(foreach SUBDIR,$(SUBDIRS), \
229                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
230 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
231         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
232         ( cd $* && setup/Setup configure \
233                    $(CONFIGURE_OPTS) \
234                    --prefix=/NONEXISTANT \
235                    --bindir=/NONEXISTANT \
236                    --libdir=/NONEXISTANT \
237                    --libsubdir='$$pkgid' \
238                    --libexecdir=/NONEXISTANT \
239                    --datadir=/NONEXISTANT \
240                    --docdir=/NONEXISTANT \
241                    --htmldir=/NONEXISTANT \
242                    --with-compiler=../../compiler/stage1/ghc-inplace \
243                    --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace \
244                    --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace \
245                    --with-ld=$(LD) \
246                    --haddock-options="--use-contents=../index.html \
247                                    --use-index=../doc-index.html" \
248                    $(FLAGGED_CONFIGURE_ARGS) \
249                    --configure-option=--with-cc=$(CC) ) \
250               && touch $@ || touch $*/unbuildable
251 # We don't touch $@ if configure failed as we would prefer to try
252 # configuring it next time round, rather than assuming it'll still fail.
253 # This is particularly important for bootlibs, where failure means the
254 # build dies!
255
256 # Build the library using 'make'
257 $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR)):\
258 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
259                 %/GNUmakefile \
260                 %/setup/Setup ifBuildable/ifBuildable
261         if ifBuildable/ifBuildable $*; then \
262           cd $* && \
263           $(MAKE) $(MFLAGS) && \
264           setup/Setup register --inplace; \
265         fi
266
267 # Build the library using 'setup build' (not the default)
268 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
269 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
270                  %/setup/Setup ifBuildable/ifBuildable
271         if ifBuildable/ifBuildable $*; then \
272           cd $* && \
273           setup/Setup build $(addprefix --ghc-option=,$(GhcLibHcOpts)); \
274         fi
275
276 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/GNUmakefile):\
277 %/GNUmakefile: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
278                  %/setup/Setup ifBuildable/ifBuildable
279         $(RM) $*/GNUmakefile
280         cp Makefile.local $*
281         if ifBuildable/ifBuildable $*; then \
282            cd $* && setup/Setup makefile -f GNUmakefile; \
283         fi
284
285 .PHONY: doc
286
287 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
288         sh gen_contents_index --inplace
289
290 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
291 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
292                %/setup/Setup ifBuildable/ifBuildable
293         if ifBuildable/ifBuildable $*; then \
294           cd $* && setup/Setup haddock --html-location='../$$pkgid'; \
295         fi
296
297 .PHONY: distclean clean clean.library.%
298
299 distclean: clean
300
301 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
302         $(RM) -f stamp/bootstrapping.*
303         $(RM) -rf bootstrapping.*
304         $(RM) -rf ifBuildable
305         $(RM) -rf installPackage
306         $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
307         $(RM) -f haddock* *.gif
308
309 distclean:
310         $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
311
312 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
313 clean.library.%:
314         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
315         -cd $* && setup/Setup clean
316         $(RM) -rf $*/setup
317         $(RM) $*/GNUmakefile $*/Makefile.local
318 endif
319
320 # -----------------------------------------------------------------------------
321
322 .PHONY: install install-docs install.library.%
323
324 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
325 ifeq "$(HADDOCK_DOCS)" "YES"
326         $(INSTALL_DIR)                                                     $(DESTDIR)$(html_installed_root)
327         $(INSTALL_DATA)   index.html doc-index*.html                       $(DESTDIR)$(html_installed_root)
328         $(INSTALL_SCRIPT) gen_contents_index                               $(DESTDIR)$(html_installed_root)
329         # Hacks:
330         $(INSTALL_DATA)   base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
331         $(INSTALL_DATA)   base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
332         $(INSTALL_DATA)   base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
333 endif
334
335 # Cabal doesn't let us ask to install docs only, so do nothing here
336 install-docs:
337         @:
338
339 # Ideally this would depend on a stamp/build.library.%, but if it does
340 # then we can't change the libraries and then just rerun make.
341 # Thus if you install without building then it will just break.
342
343 # prefix and (on Windows) htmldir use $topdir when configuring, so we
344 # need to tell installPackage the real path to use when installing.
345
346 # We also need to pass all the other directories in, as they can be
347 # overridden when installing a bindist.
348
349 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
350 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
351         if ifBuildable/ifBuildable $*; then \
352           cd $* && \
353           ../installPackage/installPackage '$(GHC_PKG_PROG)' '$(DESTDIR)$(libdir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' ; \
354         fi
355
356 .PHONY: binary-dist binary-dist.library.%
357
358 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
359
360 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
361         mkdir                               $(BIN_DIST_LIBDIR)/installPackage
362         cp        installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
363         mkdir                               $(BIN_DIST_LIBDIR)/ifBuildable
364         cp        ifBuildable/ifBuildable       $(BIN_DIST_LIBDIR)/ifBuildable
365         cp    Makefile                      $(BIN_DIST_LIBDIR)
366 ifeq "$(HADDOCK_DOCS)" "YES"
367         cp    gen_contents_index            $(BIN_DIST_LIBDIR)
368         cp    index.html                    $(BIN_DIST_LIBDIR)
369         cp    doc-index*.html               $(BIN_DIST_LIBDIR)
370 endif
371         cp -pR stamp                         $(BIN_DIST_LIBDIR)
372         # This gets used in the compiler directory to see if GHC should
373         # depend on the readline package or not
374         $(MKDIRHIER) $(BIN_DIST_LIBDIR)/readline
375         cp    readline/config.mk            $(BIN_DIST_LIBDIR)/readline
376
377 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
378 binary-dist.library.%:
379         if ifBuildable/ifBuildable $*; then \
380           $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*; \
381           cd $* && \
382           cp    $*.cabal      $(BIN_DIST_LIBDIR)/$* && \
383           cp    LICENSE       $(BIN_DIST_LIBDIR)/$* && \
384           cp -R dist          $(BIN_DIST_LIBDIR)/$* && \
385           $(FIND) . -name "*.buildinfo" -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
386           (cp -RL include      $(BIN_DIST_LIBDIR)/$* || true) && \
387           $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
388              \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
389           $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
390              \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
391              -exec rm {} \; ; \
392         fi