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