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