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