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