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