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