All installed Haskell prgms have an inplace and an installed version
[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 time)
66 SUBDIRS += $(wildcard OpenGL)
67 SUBDIRS += $(wildcard GLUT)
68 SUBDIRS += $(wildcard OpenAL)
69 SUBDIRS += $(wildcard ALUT)
70 SUBDIRS += $(wildcard stm)
71 SUBDIRS += $(wildcard xhtml)
72 SUBDIRS += $(wildcard cgi)
73 ifeq "$(GhcLibsWithObjectIO)" "YES"
74 SUBDIRS += $(wildcard ObjectIO)
75 endif
76 SUBDIRS += $(wildcard parallel)
77 SUBDIRS += $(wildcard ndp)
78 endif
79
80 # -----------------------------------------------------------------------------
81
82 empty=
83 space=$(empty) $(empty)
84
85 # -----------------------------------------------------------------------------
86
87 ifeq "$(RelocatableBuild)" "YES"
88 # On Windows we want to make moveable bindists, but we need to tell
89 # ghc-pkg where the haddock docs are. Therefore we completely ignore
90 # where the user tells us to put the haddock documentation and put it
91 # somewhere whose relative location we know. When installing we need
92 # to give Cabal a real path, though.
93 iprefix             = $$topdir
94 ibindir             = $$topdir
95 ilibdir             = $$topdir
96 ilibexecdir         = $$topdir
97 idynlibdir          = $$topdir
98 idatadir            = $$topdir
99 idocdir             = $$topdir/doc/libraries/$$pkg
100 ihaddockdir         = $$topdir/doc/libraries/$$pkg
101 ihtmldir            = $$httptopdir/doc/libraries/$$pkg
102 html_installed_root = $(prefix)/doc/libraries
103 else
104 # On non-Windows we can just give absolute paths all the time, and
105 # thus obey the htmldir that we are given.
106 iprefix             = $(prefix)
107 ibindir             = $(bindir)
108 ilibdir             = $(libdir)
109 ilibexecdir         = $(libexecdir)
110 idynlibdir          = $(dynlibdir)
111 idatadir            = $(datadir)
112 idocdir             = $(docdir)/libraries/$$pkg
113 ihaddockdir         = $(htmldir)/libraries/$$pkg
114 ihtmldir            = $(htmldir)/libraries/$$pkg
115 html_installed_root = $(htmldir)/libraries
116 endif
117
118 ifneq "$(DOING_BIN_DIST)" "YES"
119
120 CONFIGURE_OPTS =
121 CONFIGURE_STAMP_EXTRAS :=
122
123 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
124 CONFIGURE_OPTS += --enable-library-profiling
125 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
126 endif
127
128 ifneq "$(findstring $(space)dyn$(space), $(space)$(GhcLibWays)$(space))" ""
129 CONFIGURE_OPTS += --enable-shared
130 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
131 endif
132
133 ifeq "$(SplitObjs)" "YES"
134 CONFIGURE_OPTS += --enable-split-objs
135 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
136 endif
137
138 ifneq "$(HSCOLOUR)" ""
139 CONFIGURE_OPTS += --with-hscolour=$(HSCOLOUR)
140 endif
141
142 BOOTSTRAP_LIBS = Cabal filepath
143 BOOTSTRAP_STAMPS = $(addprefix stamp/bootstrapping.,$(BOOTSTRAP_LIBS))
144 BOOTSTRAP_INC_1_UP = -DCABAL_VERSION=1,3 $(addprefix -i../bootstrapping.,$(BOOTSTRAP_LIBS))
145 BOOTSTRAP_INC_2_UP = -DCABAL_VERSION=1,3 $(addprefix -i../../bootstrapping.,$(BOOTSTRAP_LIBS))
146
147 .PHONY: subdirs
148
149 subdirs:
150         @echo $(SUBDIRS)
151
152 .PHONY: boot
153
154 boot: $(BOOTSTRAP_STAMPS) ifBuildable/ifBuildable \
155           $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
156           installPackage/installPackage
157
158 # We build the Setup program in a setup subdirectory to stop it trying
159 # to use bits of base and Cabal when we build those packages.
160 # This also makes it slightly easier to clean.
161
162 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
163
164 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
165 %/setup/Setup: $(BOOTSTRAP_STAMPS)
166         -$(RM) -rf $*/setup
167         mkdir $*/setup
168         $(CP) $*/Setup.*hs $*/setup
169         cd $*/setup && $(GHC) -Wall -cpp --make Setup.*hs -o Setup \
170                               $(BOOTSTRAP_INC_2_UP)
171
172 installPackage/installPackage: installPackage.hs $(BOOTSTRAP_STAMPS)
173         -$(RM) -rf installPackage
174         mkdir installPackage
175         $(CP) installPackage.hs installPackage/
176 ifeq "$(stage)" "2"
177         cd installPackage && ../$(HC) -Wall -cpp \
178                                     --make installPackage -o installPackage \
179                                     $(BOOTSTRAP_INC_1_UP)
180 else
181         cd installPackage && $(GHC) -Wall -cpp \
182                                     --make installPackage -o installPackage \
183                                     $(BOOTSTRAP_INC_1_UP)
184 endif
185 # TODO: The conditional is yucky, but we need to be able to build with stage1
186 #       for bindists and as installPackages/ has no Makefile, it seems hard
187 #       to make this nicer.
188
189 ifBuildable/ifBuildable: ifBuildable.hs
190         -$(RM) -rf ifBuildable
191         mkdir ifBuildable
192         $(CP) ifBuildable.hs ifBuildable/
193 ifeq "$(stage)" "2"
194         cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable
195 else
196         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
197 endif
198
199 $(BOOTSTRAP_STAMPS): stamp/bootstrapping.%:
200         $(RM) -rf bootstrapping.$*
201         $(CP) -R $* bootstrapping.$*
202         $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
203                                  -exec $(RM) -f {} \;
204         touch $@
205
206 .PHONY: all build configure
207
208 all: build
209
210 ifeq "$(HADDOCK_DOCS)" "YES"
211 all: doc
212 endif
213
214 .PHONY: rebuild.library.%
215
216 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
217 rebuild.library.%: clean.library.% make.library.%
218
219 # NB. we're depending on make chasing dependencies from left to right here.
220 # This bit goes wrong with 'make -j'.
221 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
222 build: installPackage/installPackage
223
224 configure: $(foreach SUBDIR,$(SUBDIRS), \
225              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
226
227 .PHONY: build.library.%
228 .PHONY: make.library.%
229
230 # We should depend on %/%.cabal here (and in other rules), but make
231 # makes that difficult.
232
233 # We put non-existant paths in when configuring, as we require that
234 # builds don't depend on these paths when making bindists.
235
236 # We rely on all the CONFIGURE_ARGS being quoted with '...', and there
237 # being no 's inside the values.
238 FLAGGED_CONFIGURE_ARGS = $(subst $(space)',\
239                                  $(space)--configure-option=',\
240                                  $(space)$(CONFIGURE_ARGS))
241
242 $(foreach SUBDIR,$(SUBDIRS), \
243                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
244 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
245         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
246         ( cd $* && setup/Setup configure \
247                    $(CONFIGURE_OPTS) \
248                    --prefix=/NONEXISTANT \
249                    --bindir=/NONEXISTANT \
250                    --libdir=/NONEXISTANT \
251                    --libsubdir='$$pkgid' \
252                    --libexecdir=/NONEXISTANT \
253                    --datadir=/NONEXISTANT \
254                    --docdir=/NONEXISTANT \
255                            --haddockdir=/NONEXISTANT \
256                    --htmldir=/NONEXISTANT \
257                    --with-compiler=../../compiler/stage1/ghc-inplace \
258                    --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace \
259                    --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace \
260                    --with-ld=$(LD) \
261                    --haddock-options="--use-contents=../index.html \
262                                    --use-index=../doc-index.html" \
263                    $(FLAGGED_CONFIGURE_ARGS) \
264                    --configure-option=--with-cc=$(CC) ) \
265               && touch $@ || touch $*/unbuildable
266 # We don't touch $@ if configure failed as we would prefer to try
267 # configuring it next time round, rather than assuming it'll still fail.
268 # This is particularly important for bootlibs, where failure means the
269 # build dies!
270
271 # Build the library using 'make'
272 # We re-run 'setup makefile' each time, just in case any preprocessing
273 # needs to be done.  However, we're careful not to overwrite GNUmakefile
274 # if it hasn't changed, so that dependency-generation isn't forced
275 # every time.
276 $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR)):\
277 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
278                 %/setup/Setup ifBuildable/ifBuildable installPackage/installPackage
279         if ifBuildable/ifBuildable $*; then \
280           cd $* && \
281           cmp -s ../Makefile.local Makefile.local || cp ../Makefile.local .; \
282           mv GNUmakefile GNUmakefile.tmp; \
283           setup/Setup makefile -f GNUmakefile; \
284           cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
285           $(MAKE) $(MFLAGS) && \
286           ../installPackage/installPackage register --inplace; \
287         fi
288
289 # Build the library using 'setup build' (not the default)
290 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
291 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
292                  %/setup/Setup ifBuildable/ifBuildable
293         if ifBuildable/ifBuildable $*; then \
294           cd $* && \
295           setup/Setup build $(addprefix --ghc-option=,$(GhcLibHcOpts)); \
296         fi
297
298 .PHONY: doc html
299
300 html: doc
301
302 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
303         sh gen_contents_index --inplace
304
305 # Making hyperlinked source only works if we have hscolour
306 ifneq "$(HSCOLOUR)" ""
307 CABAL_HADDOCK_FLAGS=--hyperlink-source
308 endif
309
310 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
311 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
312                %/setup/Setup ifBuildable/ifBuildable
313         if ifBuildable/ifBuildable $*; then \
314           cd $* && setup/Setup haddock --html-location='../$$pkg' \
315                                        $(CABAL_HADDOCK_FLAGS); \
316         fi
317 ifneq "$(HSCOLOUR)" ""
318         if ifBuildable/ifBuildable $*; then cp hscolour.css $*/dist/doc/html/$*/src/; fi
319 endif
320
321 .PHONY: distclean clean clean.library.%
322
323 distclean: clean
324
325 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
326         $(RM) -f stamp/bootstrapping.*
327         $(RM) -rf bootstrapping.*
328         $(RM) -rf ifBuildable
329         $(RM) -rf installPackage
330         $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
331         $(RM) -f haddock* *.gif
332
333 distclean:
334         $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
335
336 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
337 clean.library.%:
338         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
339         -cd $* && setup/Setup clean
340         $(RM) -rf $*/setup
341         $(RM) $*/GNUmakefile $*/Makefile.local
342 endif
343
344 # -----------------------------------------------------------------------------
345
346 .PHONY: install install-docs install.library.%
347
348 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
349 ifeq "$(HADDOCK_DOCS)" "YES"
350         $(INSTALL_DIR)                                                     $(DESTDIR)$(html_installed_root)
351         $(INSTALL_DATA)   index.html doc-index*.html                       $(DESTDIR)$(html_installed_root)
352         $(INSTALL_SCRIPT) gen_contents_index                               $(DESTDIR)$(html_installed_root)
353         # Hacks:
354         $(INSTALL_DATA)   base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
355         $(INSTALL_DATA)   base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
356         $(INSTALL_DATA)   base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
357 endif
358
359 # Cabal doesn't let us ask to install docs only, so do nothing here
360 install-docs:
361         @:
362
363 # Ideally this would depend on a stamp/build.library.%, but if it does
364 # then we can't change the libraries and then just rerun make.
365 # Thus if you install without building then it will just break.
366
367 # prefix and (on Windows) htmldir use $topdir when configuring, so we
368 # need to tell installPackage the real path to use when installing.
369
370 # We also need to pass all the other directories in, as they can be
371 # overridden when installing a bindist.
372
373 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
374 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
375         if ifBuildable/ifBuildable $*; then \
376           cd $* && \
377           ../installPackage/installPackage install '$(GHC_PKG_PROG)' '$(DESTDIR)$(libdir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' ; \
378         fi
379
380 .PHONY: binary-dist binary-dist.library.%
381
382 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
383
384 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
385         mkdir                               $(BIN_DIST_LIBDIR)/installPackage
386         cp        installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
387         mkdir                               $(BIN_DIST_LIBDIR)/ifBuildable
388         cp        ifBuildable/ifBuildable       $(BIN_DIST_LIBDIR)/ifBuildable
389         cp    Makefile                      $(BIN_DIST_LIBDIR)
390 ifeq "$(HADDOCK_DOCS)" "YES"
391         cp    gen_contents_index            $(BIN_DIST_LIBDIR)
392         cp    index.html                    $(BIN_DIST_LIBDIR)
393         cp    doc-index*.html               $(BIN_DIST_LIBDIR)
394 endif
395         cp -pR stamp                         $(BIN_DIST_LIBDIR)
396
397 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
398 binary-dist.library.%:
399         if ifBuildable/ifBuildable $*; then \
400           $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*; \
401           cd $* && \
402           cp    $*.cabal      $(BIN_DIST_LIBDIR)/$* && \
403           cp    LICENSE       $(BIN_DIST_LIBDIR)/$* && \
404           cp -R dist          $(BIN_DIST_LIBDIR)/$* && \
405           $(FIND) . -name "*.buildinfo" -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
406           $(FIND) . -name unbuildable -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
407           (cp -RL include      $(BIN_DIST_LIBDIR)/$* || true) && \
408           $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
409              \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
410           $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
411              \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
412              -exec rm {} \; ; \
413         fi
414
415 # Ignore some doc targets that we don't support
416 # The root recurses into us when these targets are made
417 .PHONY: html-no-chunks chm HxS fo dvi ps pdf
418 html-no-chunks chm HxS fo dvi ps pdf:
419         @:
420