FIX #1559, #1560. Rearrange the way we do ifBuildable...
[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
24
25 default_target: all
26
27 # make doesn't give us an easy way to get the libraries built in
28 # dependency order the first time, but not rebuild base (for example)
29 # when we want to rebuild another library later.
30 # So for now we just don't do anything in parallel in here.
31 .NOTPARALLEL:
32
33 # Ideally we'd just include something to give us variables
34 # for paths and arguments to tools etc, and those set in mk/build.mk.
35 TOP=..
36 include $(TOP)/mk/boilerplate.mk
37
38 SUBDIRS = base old-locale old-time filepath directory process pretty \
39           hpc template-haskell readline Cabal random haskell98
40
41 ifeq "$(GhcLibsWithUnix)" "YES"
42 SUBDIRS += unix
43 endif
44 ifeq "$(Windows)" "YES"
45 SUBDIRS += $(wildcard Win32)
46 endif
47
48 # Set GhcBootLibs=YES from the command line to work with just the libraries
49 # needed to bootstrap GHC.
50 ifneq "$(GhcBootLibs)" "YES"
51 SUBDIRS += $(wildcard regex-base)
52 SUBDIRS += $(wildcard regex-posix)
53 SUBDIRS += $(wildcard regex-compat)
54 SUBDIRS += $(wildcard parsec)
55 SUBDIRS += $(wildcard haskell-src)
56 SUBDIRS += $(wildcard html)
57 SUBDIRS += $(wildcard network)
58 SUBDIRS += $(wildcard QuickCheck)
59 SUBDIRS += $(wildcard HUnit)
60 SUBDIRS += $(wildcard mtl)
61 SUBDIRS += $(wildcard fgl)
62 SUBDIRS += $(wildcard X11)
63 SUBDIRS += $(wildcard time)
64 ifeq "$(Windows)" "NO"
65 # HGL is not working on Win32, so omit it for now.  Better not to ship it
66 # at all than to ship a broken version.
67 SUBDIRS += $(wildcard HGL)
68 endif
69 SUBDIRS += $(wildcard OpenGL)
70 SUBDIRS += $(wildcard GLUT)
71 SUBDIRS += $(wildcard OpenAL)
72 SUBDIRS += $(wildcard ALUT)
73 SUBDIRS += $(wildcard stm)
74 SUBDIRS += $(wildcard xhtml)
75 SUBDIRS += $(wildcard cgi)
76 SUBDIRS += $(wildcard arrows)
77 ifeq "$(GhcLibsWithObjectIO)" "YES"
78 SUBDIRS += $(wildcard ObjectIO)
79 endif
80 SUBDIRS += $(wildcard parallel)
81 SUBDIRS += $(wildcard ndp)
82 endif
83
84 # -----------------------------------------------------------------------------
85
86 empty=
87 space=$(empty) $(empty)
88
89 # -----------------------------------------------------------------------------
90
91 ifneq "$(DOING_BIN_DIST)" "YES"
92
93 CONFIGURE_OPTS =
94 CONFIGURE_STAMP_EXTRAS :=
95
96 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
97 CONFIGURE_OPTS += --enable-library-profiling
98 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
99 endif
100
101 ifeq "$(SplitObjs)" "YES"
102 CONFIGURE_OPTS += --enable-split-objs
103 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
104 endif
105
106 BOOTSTRAP_LIBS = Cabal filepath
107 BOOTSTRAP_STAMPS = $(addprefix stamp/bootstrapping.,$(BOOTSTRAP_LIBS))
108 BOOTSTRAP_INC_1_UP = $(addprefix -i../bootstrapping.,$(BOOTSTRAP_LIBS))
109 BOOTSTRAP_INC_2_UP = $(addprefix -i../../bootstrapping.,$(BOOTSTRAP_LIBS))
110
111 .PHONY: subdirs
112
113 subdirs:
114         @echo $(SUBDIRS)
115
116 .PHONY: boot
117
118 boot: $(BOOTSTRAP_STAMPS) ifBuildable/ifBuildable \
119           $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
120           installPackage/installPackage
121
122 # We build the Setup program in a setup subdirectory to stop it trying
123 # to use bits of base and Cabal when we build those packages.
124 # This also makes it slightly easier to clean.
125
126 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
127
128 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
129 %/setup/Setup: $(BOOTSTRAP_STAMPS)
130         -$(RM) -rf $*/setup
131         mkdir $*/setup
132         $(CP) $*/Setup.*hs $*/setup
133         cd $*/setup && $(GHC) -Wall -cpp --make Setup.*hs -o Setup \
134                               $(BOOTSTRAP_INC_2_UP)
135
136 installPackage/installPackage: installPackage.hs $(BOOTSTRAP_STAMPS)
137         -$(RM) -rf installPackage
138         mkdir installPackage
139         $(CP) installPackage.hs installPackage/
140         cd installPackage && $(GHC) -Wall -cpp \
141                                     --make installPackage -o installPackage \
142                                     $(BOOTSTRAP_INC_1_UP)
143
144 ifBuildable/ifBuildable: ifBuildable.hs
145         -$(RM) -rf ifBuildable
146         mkdir ifBuildable
147         $(CP) ifBuildable.hs ifBuildable/
148         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
149
150 $(BOOTSTRAP_STAMPS): stamp/bootstrapping.%:
151         $(RM) -rf bootstrapping.$*
152         $(CP) -R $* bootstrapping.$*
153         $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
154                                  -exec $(RM) -f {} \;
155         touch $@
156
157 .PHONY: all build configure
158
159 all: build
160
161 ifeq "$(HADDOCK_DOCS)" "YES"
162 all: doc
163 endif
164
165 .PHONY: rebuild.library.%
166
167 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
168 rebuild.library.%: clean.library.% make.library.%
169
170 # NB. we're depending on make chasing dependencies from left to right here.
171 # This bit goes wrong with 'make -j'.
172 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
173 build: installPackage/installPackage
174
175 configure: $(foreach SUBDIR,$(SUBDIRS), \
176              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
177
178 .PHONY: build.library.%
179 .PHONY: make.library.%
180
181 # We should depend on %/%.cabal here (and in other rules), but make
182 # makes that difficult.
183
184 # We explicitly set datadir to "$prefix/share" as, while that is the
185 # default on Linux, on Windows it defaults to
186 # "C:\\Program Files\\Common Files"
187
188 # We also set libsubdir differently on Windows and non-Windows, as on
189 # non-Windows the path we deduce is highre up than the path passed to
190 # the executable with the shell script on non-Windows. This should
191 # probably be tidied up so that we can always pass the same libsubdir.
192 ifeq "$(Windows)" "YES"
193 DATA_REL_DIR = .
194 datadir      = $$prefix
195 libsubdir    = $$pkgid
196 else
197 DATA_REL_DIR = share/ghc
198 datadir      = $$prefix/share/ghc
199 libsubdir    = $$compiler/lib/$$pkgid
200 endif
201 DOC_ROOT     = $(prefix)/$(DATA_REL_DIR)/doc/html/
202
203 # We rely on all the CONFIGURE_ARGS being quoted with '...', and there
204 # being no 's inside the values.
205 FLAGGED_CONFIGURE_ARGS = $(subst $(space)',\
206                                  $(space)--configure-option=',\
207                                  $(space)$(CONFIGURE_ARGS))
208
209 $(foreach SUBDIR,$(SUBDIRS), \
210                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
211 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
212         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
213         ( cd $* && setup/Setup configure \
214                    $(CONFIGURE_OPTS) \
215                    --prefix='$$topdir' \
216                    --datadir='$(datadir)' \
217                    --datasubdir='.' \
218                    --libsubdir='$(libsubdir)' \
219                    --with-compiler=../../compiler/stage1/ghc-inplace$ \
220                    --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace$ \
221                    --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace \
222                    --with-ld=$(LD) \
223                    --haddock-args="--use-contents=../index.html \
224                                    --use-index=../doc-index.html" \
225                    $(FLAGGED_CONFIGURE_ARGS) \
226                    --configure-option=--with-cc=$(CC) ) \
227               && touch $@ || touch $*/unbuildable
228 # We don't touch $@ if configure failed as we would prefer to try
229 # configuring it next time round, rather than assuming it'll still fail.
230 # This is particularly important for corelibs, where failure means the
231 # build dies!
232
233 # Build the library using 'make'
234 $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR)):\
235 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
236                 %/GNUmakefile \
237                 %/setup/Setup ifBuildable/ifBuildable
238         if ifBuildable/ifBuildable $*; then \
239           cd $* && \
240           $(MAKE) $(MFLAGS) && \
241           setup/Setup register --inplace; \
242         fi
243
244 # Build the library using 'setup build' (not the default)
245 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
246 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
247                  %/setup/Setup ifBuildable/ifBuildable
248         if ifBuildable/ifBuildable $*; then \
249           cd $* && \
250           setup/Setup build $(addprefix --ghc-option=,$(GhcLibHcOpts)); \
251         fi
252
253 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/GNUmakefile):\
254 %/GNUmakefile: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
255                  %/setup/Setup ifBuildable/ifBuildable
256         $(RM) $*/GNUmakefile
257         cp Makefile.local $*
258         if ifBuildable/ifBuildable $*; then \
259            cd $* && setup/Setup makefile -f GNUmakefile; \
260         fi
261
262 .PHONY: doc
263
264 DOC_SUBDIRS = $(filter-out haskell98,$(SUBDIRS))
265
266 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
267         sh gen_contents_index
268
269 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
270 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
271                %/setup/Setup ifBuildable/ifBuildable
272         if ifBuildable/ifBuildable $*; then \
273           cd $* && setup/Setup haddock; \
274         fi
275
276 .PHONY: distclean clean clean.library.%
277
278 distclean: clean
279
280 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
281         $(RM) -f stamp/bootstrapping.*
282         $(RM) -rf bootstrapping.*
283         $(RM) -rf ifBuildable
284         $(RM) -rf installPackage
285         $(RM) -f libraries.txt index.html doc-index.html
286
287 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
288 clean.library.%:
289         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
290         -cd $* && setup/Setup clean
291         $(RM) -rf $*/setup
292         $(RM) $*/GNUmakefile $*/Makefile.local
293 endif
294
295 # -----------------------------------------------------------------------------
296
297 .PHONY: install install-docs install.library.%
298
299 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
300 ifeq "$(HADDOCK_DOCS)" "YES"
301         $(INSTALL_DIR)                              $(DOC_ROOT)
302         $(INSTALL_DATA)   index.html doc-index.html $(DOC_ROOT)
303         $(INSTALL_SCRIPT) gen_contents_index        $(DOC_ROOT)
304         # Hacks:
305         $(INSTALL_DATA)   $(DOC_ROOT)/base/*.css    $(DOC_ROOT)
306         $(INSTALL_DATA)   $(DOC_ROOT)/base/*.js     $(DOC_ROOT)
307         $(INSTALL_DATA)   $(DOC_ROOT)/base/*.gif    $(DOC_ROOT)
308 endif
309
310 # Cabal doesn't let us ask to install docs only, so do nothing here
311 install-docs:
312         @:
313
314 # Ideally this would depend on a stamp/build.library.%, but if it does
315 # then we can't change the libraries and then just rerun make.
316 # Thus if you install without building then it will just break.
317 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
318 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
319         if ifBuildable/ifBuildable $*; then \
320           cd $* && \
321           ../installPackage/installPackage $(prefix) $(bindir)/ghc-pkg; \
322         fi
323
324 .PHONY: binary-dist binary-dist.library.%
325
326 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
327
328 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
329         mkdir                               $(BIN_DIST_LIBDIR)/installPackage
330         cp        installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
331         mkdir                               $(BIN_DIST_LIBDIR)/ifBuildable
332         cp        ifBuildable/ifBuildable       $(BIN_DIST_LIBDIR)/ifBuildable
333         cp    Makefile                      $(BIN_DIST_LIBDIR)
334         cp    gen_contents_index            $(BIN_DIST_LIBDIR)
335         cp    index.html                    $(BIN_DIST_LIBDIR)
336         cp    doc-index.html                $(BIN_DIST_LIBDIR)
337         cp -a stamp                         $(BIN_DIST_LIBDIR)
338
339 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
340 binary-dist.library.%:
341         $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*
342         if ifBuildable/ifBuildable $*; then \
343           cd $* && \
344           cp    $*.cabal      $(BIN_DIST_LIBDIR)/$* && \
345           cp -a dist          $(BIN_DIST_LIBDIR)/$* && \
346         # Euch \
347           (cp -aL include      $(BIN_DIST_LIBDIR)/$* || :) && \
348           $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
349              \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
350           $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
351              \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
352              -exec rm {} \; ; \
353         fi