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