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