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