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