add a rule for creating makefiles as <dir>/CabalMakefile
[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-locale old-time directory process filepath pretty \
31           template-haskell 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 BOOTSTRAP_LIBS = Cabal filepath
100 BOOTSTRAP_STAMPS = $(addprefix stamp/bootstrapping.,$(BOOTSTRAP_LIBS))
101 BOOTSTRAP_INC_1_UP = $(addprefix -i../bootstrapping.,$(BOOTSTRAP_LIBS))
102 BOOTSTRAP_INC_2_UP = $(addprefix -i../../bootstrapping.,$(BOOTSTRAP_LIBS))
103
104 .PHONY: subdirs
105
106 subdirs:
107         @echo $(SUBDIRS)
108
109 .PHONY: boot
110
111 boot: $(BOOTSTRAP_STAMPS) ifBuildable/ifBuildable \
112           $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
113           installPackage/installPackage
114
115 # We build the Setup program in a setup subdirectory to stop it trying
116 # to use bits of base and Cabal when we build those packages.
117 # This also makes it slightly easier to clean.
118
119 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
120
121 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
122 %/setup/Setup: $(BOOTSTRAP_STAMPS)
123         -$(RM) -rf $*/setup
124         mkdir $*/setup
125         $(CP) $*/Setup.*hs $*/setup
126         cd $*/setup && $(GHC) -Wall -cpp --make Setup.*hs -o Setup \
127                               $(BOOTSTRAP_INC_2_UP)
128
129 installPackage/installPackage: installPackage.hs $(BOOTSTRAP_STAMPS)
130         -$(RM) -rf installPackage
131         mkdir installPackage
132         $(CP) installPackage.hs installPackage/
133         cd installPackage && $(GHC) -Wall -cpp \
134                                     --make installPackage -o installPackage \
135                                     $(BOOTSTRAP_INC_1_UP)
136
137 ifBuildable/ifBuildable: ifBuildable.hs
138         -$(RM) -rf ifBuildable
139         mkdir ifBuildable
140         $(CP) ifBuildable.hs ifBuildable/
141         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
142
143 $(BOOTSTRAP_STAMPS): stamp/bootstrapping.%:
144         $(RM) -rf bootstrapping.$*
145         $(CP) -R $* bootstrapping.$*
146         $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
147                                  -exec $(RM) -f {} \;
148         touch $@
149
150 .PHONY: all build configure
151
152 all: build
153
154 ifneq "$(NO_HADDOCK_DOCS)" "YES"
155 all: doc
156 endif
157
158 .PHONY: rebuild.library.%
159
160 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
161 rebuild.library.%: clean.library.% build.library.%
162
163 build: $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR))
164 build: installPackage/installPackage
165
166 configure: $(foreach SUBDIR,$(SUBDIRS), \
167              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
168
169 .PHONY: build.library.%
170
171 # We should depend on %/%.cabal here (and in other rules), but make
172 # makes that difficult.
173
174 $(foreach SUBDIR,$(SUBDIRS), \
175                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
176 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
177         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
178         ( cd $* && setup/Setup configure \
179                    $(CONFIGURE_OPTS) \
180                    --prefix=$(prefix) \
181                    --with-compiler=../../compiler/ghc-inplace$(dot_bat) \
182                    --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace$(dot_bat) \
183                    --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace$(dot_bat) \
184                    --with-ld=$(LD) \
185                    --datasubdir=ghc \
186                    --haddock-args="--use-contents=../index.html \
187                                    --use-index=../doc-index.html" \
188                    $(addprefix --configure-option=,$(CONFIGURE_ARGS)) \
189                    --configure-option=--with-cc=$(CC) ) \
190               && touch $@ || touch $*/unbuildable
191 # We don't touch $@ if configure failed as we would prefer to try
192 # configuring it next time round, rather than assuming it'll still fail.
193 # This is particularly important for corelibs, where failure means the
194 # build dies!
195
196 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
197 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
198                  %/setup/Setup ifBuildable/ifBuildable
199         ifBuildable/ifBuildable $* setup/Setup build \
200                                         $(addprefix --ghc-option=,$(GhcLibHcOpts))
201         ifBuildable/ifBuildable $* setup/Setup register --inplace
202
203 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/CabalMakefile):\
204 %/CabalMakefile: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
205                  %/setup/Setup ifBuildable/ifBuildable
206         $(RM) $*/CabalMakefile
207         ifBuildable/ifBuildable $* setup/Setup makefile -f CabalMakefile \
208                                      $(addprefix --ghc-option=,$(GhcLibHcOpts))
209
210 .PHONY: doc
211
212 DOC_SUBDIRS = $(filter-out haskell98,$(SUBDIRS))
213
214 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
215         sh gen_contents_index
216
217 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
218 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
219                %/setup/Setup ifBuildable/ifBuildable
220         ifBuildable/ifBuildable $* setup/Setup haddock
221
222 .PHONY: install install-docs install.library.%
223
224 INSTALL_DIR=$(prefix)/share/ghc/doc/html/
225
226 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
227 ifneq "$(NO_HADDOCK_DOCS)" "YES"
228         $(INSTALL_DATA)   index.html doc-index.html                       $(INSTALL_DIR)
229         $(INSTALL_SCRIPT) gen_contents_index                                      $(INSTALL_DIR)
230         # Hacks:
231         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.css $(INSTALL_DIR)
232         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.js  $(INSTALL_DIR)
233         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.gif $(INSTALL_DIR)
234 endif
235
236 # Cabal doesn't let us ask to install docs only, so do nothing here
237 install-docs:
238         @:
239
240 # Ideally this would depend on a stamp/build.library.%, but if it does
241 # then we can't change the libraries and then just rerun make.
242 # Thus if you install without building then it will just break.
243 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
244 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
245         ifBuildable/ifBuildable $* ../installPackage/installPackage
246
247 .PHONY: binary-dist binary-dist.library.%
248
249 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
250
251 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
252         mkdir                               $(BIN_DIST_LIBDIR)/installPackage
253         cp        installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
254         cp    Makefile                      $(BIN_DIST_LIBDIR)
255         cp    gen_contents_index            $(BIN_DIST_LIBDIR)
256         cp    index.html                    $(BIN_DIST_LIBDIR)
257         cp    doc-index.html                $(BIN_DIST_LIBDIR)
258         cp -a stamp                         $(BIN_DIST_LIBDIR)
259
260 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
261 binary-dist.library.%:
262         $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*
263         ifBuildable/ifBuildable $* cp    $*.cabal      $(BIN_DIST_LIBDIR)/$*
264         ifBuildable/ifBuildable $* cp -a dist          $(BIN_DIST_LIBDIR)/$*
265         ifBuildable/ifBuildable $* $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
266              \( -name "*_split" -o -name "autogen" \) | xargs rm -rf
267         ifBuildable/ifBuildable $* $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
268              \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
269              -exec rm {} \;
270
271 .PHONY: distclean clean clean.library.%
272
273 distclean: clean
274
275 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
276         $(RM) -f stamp/bootstrapping.*
277         $(RM) -rf bootstrapping.*
278         $(RM) -rf ifBuildable
279         $(RM) -f libraries.txt index.html doc-index.html
280
281 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
282 clean.library.%:
283         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
284         -cd $* && setup/Setup clean
285         $(RM) -rf $*/setup
286