b04c83b755c5d25f52c48ac00f32694b7e627f9f
[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 build.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 build.library.foo
22
23 .PHONY: default_target
24
25 default_target: build
26
27 # Ideally we'd just include something to give us variables
28 # for paths and arguments to tools etc, and those set in mk/build.mk.
29 TOP=..
30 include $(TOP)/mk/boilerplate.mk
31
32 SUBDIRS = base old-locale old-time directory process filepath pretty \
33           template-haskell readline Cabal random haskell98
34
35 ifeq "$(GhcLibsWithUnix)" "YES"
36 SUBDIRS += unix
37 endif
38 ifeq "$(Windows)" "YES"
39 SUBDIRS += $(wildcard Win32)
40 endif
41
42 # Set GhcBootLibs=YES from the command line to work with just the libraries
43 # needed to bootstrap GHC.
44 ifneq "$(GhcBootLibs)" "YES"
45 SUBDIRS += $(wildcard regex-base)
46 SUBDIRS += $(wildcard regex-posix)
47 SUBDIRS += $(wildcard regex-compat)
48 SUBDIRS += $(wildcard parsec)
49 SUBDIRS += $(wildcard haskell-src)
50 SUBDIRS += $(wildcard html)
51 SUBDIRS += $(wildcard network)
52 SUBDIRS += $(wildcard QuickCheck)
53 SUBDIRS += $(wildcard HUnit)
54 SUBDIRS += $(wildcard mtl)
55 SUBDIRS += $(wildcard fgl)
56 SUBDIRS += $(wildcard X11)
57 SUBDIRS += $(wildcard time)
58 ifeq "$(Windows)" "NO"
59 # HGL is not working on Win32, so omit it for now.  Better not to ship it
60 # at all than to ship a broken version.
61 SUBDIRS += $(wildcard HGL)
62 endif
63 SUBDIRS += $(wildcard OpenGL)
64 SUBDIRS += $(wildcard GLUT)
65 SUBDIRS += $(wildcard OpenAL)
66 SUBDIRS += $(wildcard ALUT)
67 SUBDIRS += $(wildcard stm)
68 SUBDIRS += $(wildcard xhtml)
69 SUBDIRS += $(wildcard cgi)
70 SUBDIRS += $(wildcard arrows)
71 ifeq "$(GhcLibsWithObjectIO)" "YES"
72 SUBDIRS += $(wildcard ObjectIO)
73 endif
74 SUBDIRS += $(wildcard parallel)
75 endif
76
77 # -----------------------------------------------------------------------------
78
79 empty=
80 space=$(empty) $(empty)
81
82 ifeq "$(Windows)" "YES"
83 dot_bat=.bat
84 else
85 dot_bat=
86 endif
87
88 # -----------------------------------------------------------------------------
89
90 ifneq "$(DOING_BIN_DIST)" "YES"
91
92 CONFIGURE_OPTS =
93 CONFIGURE_STAMP_EXTRAS :=
94
95 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
96 CONFIGURE_OPTS += --enable-library-profiling
97 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
98 endif
99
100 ifeq "$(SplitObjs)" "YES"
101 CONFIGURE_OPTS += --enable-split-objs
102 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
103 endif
104
105 BOOTSTRAP_LIBS = Cabal filepath
106 BOOTSTRAP_STAMPS = $(addprefix stamp/bootstrapping.,$(BOOTSTRAP_LIBS))
107 BOOTSTRAP_INC_1_UP = $(addprefix -i../bootstrapping.,$(BOOTSTRAP_LIBS))
108 BOOTSTRAP_INC_2_UP = $(addprefix -i../../bootstrapping.,$(BOOTSTRAP_LIBS))
109
110 .PHONY: subdirs
111
112 subdirs:
113         @echo $(SUBDIRS)
114
115 .PHONY: boot
116
117 boot: $(BOOTSTRAP_STAMPS) ifBuildable/ifBuildable \
118           $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
119           installPackage/installPackage
120
121 # We build the Setup program in a setup subdirectory to stop it trying
122 # to use bits of base and Cabal when we build those packages.
123 # This also makes it slightly easier to clean.
124
125 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
126
127 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
128 %/setup/Setup: $(BOOTSTRAP_STAMPS)
129         -$(RM) -rf $*/setup
130         mkdir $*/setup
131         $(CP) $*/Setup.*hs $*/setup
132         cd $*/setup && $(GHC) -Wall -cpp --make Setup.*hs -o Setup \
133                               $(BOOTSTRAP_INC_2_UP)
134
135 installPackage/installPackage: installPackage.hs $(BOOTSTRAP_STAMPS)
136         -$(RM) -rf installPackage
137         mkdir installPackage
138         $(CP) installPackage.hs installPackage/
139         cd installPackage && $(GHC) -Wall -cpp \
140                                     --make installPackage -o installPackage \
141                                     $(BOOTSTRAP_INC_1_UP)
142
143 ifBuildable/ifBuildable: ifBuildable.hs
144         -$(RM) -rf ifBuildable
145         mkdir ifBuildable
146         $(CP) ifBuildable.hs ifBuildable/
147         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
148
149 $(BOOTSTRAP_STAMPS): stamp/bootstrapping.%:
150         $(RM) -rf bootstrapping.$*
151         $(CP) -R $* bootstrapping.$*
152         $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
153                                  -exec $(RM) -f {} \;
154         touch $@
155
156 .PHONY: all build configure
157
158 all: build
159
160 ifneq "$(NO_HADDOCK_DOCS)" "YES"
161 all: doc
162 endif
163
164 .PHONY: rebuild.library.%
165
166 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
167 rebuild.library.%: clean.library.% build.library.%
168
169 build: $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR))
170 build: installPackage/installPackage
171
172 configure: $(foreach SUBDIR,$(SUBDIRS), \
173              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
174
175 .PHONY: build.library.%
176
177 # We should depend on %/%.cabal here (and in other rules), but make
178 # makes that difficult.
179
180 $(foreach SUBDIR,$(SUBDIRS), \
181                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
182 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
183         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
184         ( cd $* && setup/Setup configure \
185                    $(CONFIGURE_OPTS) \
186                    --prefix='$$topdir' \
187                    --libsubdir='$$compiler/lib/$$pkgid' \
188                    --with-compiler=../../compiler/ghc-inplace$(dot_bat) \
189                    --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace$(dot_bat) \
190                    --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace$(dot_bat) \
191                    --with-ld=$(LD) \
192                    --datasubdir=ghc \
193                    --haddock-args="--use-contents=../index.html \
194                                    --use-index=../doc-index.html" \
195                    $(addprefix --configure-option=,$(CONFIGURE_ARGS)) \
196                    --configure-option=--with-cc=$(CC) ) \
197               && touch $@ || touch $*/unbuildable
198 # We don't touch $@ if configure failed as we would prefer to try
199 # configuring it next time round, rather than assuming it'll still fail.
200 # This is particularly important for corelibs, where failure means the
201 # build dies!
202
203 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
204 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
205                  %/setup/Setup ifBuildable/ifBuildable
206         ifBuildable/ifBuildable $* setup/Setup build \
207                                         $(addprefix --ghc-option=,$(GhcLibHcOpts))
208         ifBuildable/ifBuildable $* setup/Setup register --inplace
209
210 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/CabalMakefile):\
211 %/CabalMakefile: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
212                  %/setup/Setup ifBuildable/ifBuildable
213         $(RM) $*/CabalMakefile
214         ifBuildable/ifBuildable $* setup/Setup makefile -f CabalMakefile \
215                                      $(addprefix --ghc-option=,$(GhcLibHcOpts))
216
217 .PHONY: doc
218
219 DOC_SUBDIRS = $(filter-out haskell98,$(SUBDIRS))
220
221 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
222         sh gen_contents_index
223
224 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
225 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
226                %/setup/Setup ifBuildable/ifBuildable
227         ifBuildable/ifBuildable $* setup/Setup haddock
228
229 .PHONY: distclean clean clean.library.%
230
231 distclean: clean
232
233 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
234         $(RM) -f stamp/bootstrapping.*
235         $(RM) -rf bootstrapping.*
236         $(RM) -rf ifBuildable
237         $(RM) -f libraries.txt index.html doc-index.html
238
239 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
240 clean.library.%:
241         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
242         -cd $* && setup/Setup clean
243         $(RM) -rf $*/setup
244 endif
245
246 # -----------------------------------------------------------------------------
247
248 .PHONY: install install-docs install.library.%
249
250 ROOT=$(prefix)/share/ghc/doc/html/
251
252 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
253 ifneq "$(NO_HADDOCK_DOCS)" "YES"
254         $(INSTALL_DIR)                                            $(ROOT)
255         $(INSTALL_DATA)   index.html doc-index.html               $(ROOT)
256         $(INSTALL_SCRIPT) gen_contents_index                      $(ROOT)
257         # Hacks:
258         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.css $(ROOT)
259         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.js  $(ROOT)
260         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.gif $(ROOT)
261 endif
262
263 # Cabal doesn't let us ask to install docs only, so do nothing here
264 install-docs:
265         @:
266
267 # Ideally this would depend on a stamp/build.library.%, but if it does
268 # then we can't change the libraries and then just rerun make.
269 # Thus if you install without building then it will just break.
270 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
271 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
272         ifBuildable/ifBuildable $* ../installPackage/installPackage $(prefix) $(bindir)/ghc-pkg
273
274 .PHONY: binary-dist binary-dist.library.%
275
276 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
277
278 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
279         mkdir                               $(BIN_DIST_LIBDIR)/installPackage
280         cp        installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
281         mkdir                               $(BIN_DIST_LIBDIR)/ifBuildable
282         cp        ifBuildable/ifBuildable       $(BIN_DIST_LIBDIR)/ifBuildable
283         cp    Makefile                      $(BIN_DIST_LIBDIR)
284         cp    gen_contents_index            $(BIN_DIST_LIBDIR)
285         cp    index.html                    $(BIN_DIST_LIBDIR)
286         cp    doc-index.html                $(BIN_DIST_LIBDIR)
287         cp -a stamp                         $(BIN_DIST_LIBDIR)
288
289 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
290 binary-dist.library.%:
291         $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*
292         ifBuildable/ifBuildable $* cp    $*.cabal      $(BIN_DIST_LIBDIR)/$*
293         ifBuildable/ifBuildable $* cp .setup-config    $(BIN_DIST_LIBDIR)/$*
294         ifBuildable/ifBuildable $* cp -a dist          $(BIN_DIST_LIBDIR)/$*
295         # Euch
296         ifBuildable/ifBuildable $* cp -aL include      $(BIN_DIST_LIBDIR)/$* || :
297         ifBuildable/ifBuildable $* $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
298              \( -name "*_split" -o -name "autogen" \) | xargs rm -rf
299         ifBuildable/ifBuildable $* $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
300              \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
301              -exec rm {} \;
302