Add missing libraries/Makefile dependencies on ifBuildable/ifBuildable
[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 ifeq "$(GhcLibsWithObjectIO)" "YES"
64 SUBDIRS += $(wildcard ObjectIO)
65 endif
66 endif
67
68 # -----------------------------------------------------------------------------
69
70 empty=
71 space=$(empty) $(empty)
72
73 ifeq "$(Windows)" "YES"
74 dot_bat=.bat
75 else
76 dot_bat=
77 endif
78
79 CONFIGURE_OPTS =
80 CONFIGURE_STAMP_EXTRAS :=
81
82 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
83 CONFIGURE_OPTS += --enable-library-profiling
84 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
85 endif
86
87 ifeq "$(SplitObjs)" "YES"
88 CONFIGURE_OPTS += --enable-split-objs
89 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
90 endif
91
92 BOOTSTRAPPING_CABAL = bootstrapping.cabal
93
94 .PHONY: subdirs
95
96 subdirs:
97         @echo $(SUBDIRS)
98
99 .PHONY: boot
100
101 boot: ifBuildable/ifBuildable \
102           $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup)
103         # XXX Hideous hacks:
104         $(GENPRIMOP) --make-haskell-source < ../compiler/prelude/primops.txt > base/GHC/Prim.hs
105         $(GENPRIMOP) --make-haskell-wrappers < ../compiler/prelude/primops.txt > base/GHC/PrimopWrappers.hs
106
107 # We build the Setup program in a setup subdirectory to stop it trying
108 # to use bits of base and Cabal when we build those packages.
109 # This also makes it slightly easier to clean.
110
111 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
112
113 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
114 %/setup/Setup: stamp/$(BOOTSTRAPPING_CABAL)
115         -$(RM) -rf $*/setup
116         mkdir $*/setup
117         $(CP) $*/Setup.*hs $*/setup
118         cd $*/setup && $(GHC) -Wall --make -i../../$(BOOTSTRAPPING_CABAL) Setup.*hs -o Setup
119
120 ifBuildable/ifBuildable: ifBuildable.hs stamp/$(BOOTSTRAPPING_CABAL)
121         -$(RM) -rf ifBuildable
122         mkdir ifBuildable
123         $(CP) ifBuildable.hs ifBuildable/
124         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
125
126 stamp/$(BOOTSTRAPPING_CABAL):
127         $(RM) -rf $(BOOTSTRAPPING_CABAL)
128         $(CP) -R Cabal $(BOOTSTRAPPING_CABAL)
129         $(FIND) $(BOOTSTRAPPING_CABAL) \( -name "*.o" -o -name "*.hi" \) -exec $(RM) -f {} \;
130         touch $@
131
132 .PHONY: all build configure
133
134 all: build
135
136 ifneq "$(NO_HADDOCK_DOCS)" "YES"
137 all: doc
138 endif
139
140 build: $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR))
141
142 configure: $(foreach SUBDIR,$(SUBDIRS), \
143              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
144
145 .PHONY: build.library.%
146
147 # We should depend on %/%.cabal here (and in other rules), but make
148 # makes that difficult.
149
150 $(foreach SUBDIR,$(SUBDIRS), \
151                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
152 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
153         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
154         ( cd $* && setup/Setup configure \
155                    $(CONFIGURE_OPTS) \
156                    --prefix=$(prefix) \
157                    --with-compiler=../../compiler/ghc-inplace$(dot_bat) \
158                    --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace$(dot_bat) \
159                    --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace$(dot_bat) \
160                    --with-ld=$(LD) \
161                    --datasubdir=ghc \
162                    --haddock-args="--use-contents=../index.html \
163                                    --use-index=../doc-index.html" \
164                    $(addprefix --configure-option=,$(CONFIGURE_ARGS)) \
165                    --configure-option=--with-cc=$(CC) ) \
166               && touch $@ || touch $*/unbuildable
167 # We don't touch $@ if configure failed as we would prefer to try
168 # configuring it next time round, rather than assuming it'll still fail.
169 # This is particularly important for corelibs, where failure means the
170 # build dies!
171
172 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
173 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
174                  %/setup/Setup ifBuildable/ifBuildable
175         ifBuildable/ifBuildable $* setup/Setup build \
176                                         $(addprefix --ghc-option=,$(GhcLibHcOpts))
177         ifBuildable/ifBuildable $* setup/Setup register --inplace
178
179 .PHONY: doc
180
181 DOC_SUBDIRS = $(filter-out haskell98,$(SUBDIRS))
182
183 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
184         sh gen_contents_index
185
186 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
187 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
188                %/setup/Setup ifBuildable/ifBuildable
189         ifBuildable/ifBuildable $* setup/Setup haddock
190
191 .PHONY: install install-docs install.library.%
192
193 INSTALL_DIR=$(prefix)/share/ghc/doc/html/
194
195 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
196 ifneq "$(NO_HADDOCK_DOCS)" "YES"
197         $(INSTALL_DATA)   index.html doc-index.html                       $(INSTALL_DIR)
198         $(INSTALL_SCRIPT) gen_contents_index                                      $(INSTALL_DIR)
199         # Hacks:
200         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.css $(INSTALL_DIR)
201         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.js  $(INSTALL_DIR)
202         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.gif $(INSTALL_DIR)
203 endif
204
205 # Cabal doesn't let us ask to install docs only, so do nothing here
206 install-docs:
207         @:
208
209 # Ideally this would depend on a stamp/build.library.%, but if it does
210 # then we can't change the libraries and then just rerun make.
211 # Thus if you install without building then it will just break.
212 $(foreach SUBDIR,$(SUBDIRS),stamp/configure.library.install.$(SUBDIR)): \
213 stamp/configure.library.install.%: %/setup/Setup ifBuildable/ifBuildable
214         -$(RM) -f stamp/configure.library.*.$*
215         ifBuildable/ifBuildable $* setup/Setup configure \
216                                             $(CONFIGURE_OPTS) \
217                                             --prefix=$(prefix) \
218                                             --with-compiler=$(bindir)/ghc \
219                                             --datasubdir=ghc
220         touch $@
221
222 # We need to reconfigure as we now need to register with the normal ghc-pkg
223 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
224 install.library.%: stamp/configure.library.install.% \
225                    %/setup/Setup ifBuildable/ifBuildable
226         ifBuildable/ifBuildable $* setup/Setup install
227
228 .PHONY: distclean clean clean.library.%
229
230 distclean: clean
231
232 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
233         $(RM) -f stamp/$(BOOTSTRAPPING_CABAL)
234         $(RM) -rf $(BOOTSTRAPPING_CABAL)
235         $(RM) -rf ifBuildable
236         $(RM) -f libraries.txt index.html doc-index.html
237
238 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
239 clean.library.%:
240         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
241         -cd $* && setup/Setup clean
242         $(RM) -rf $*/setup
243