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