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