Add parallel extralib
[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 pretty 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 SUBDIRS += $(wildcard parallel)
68 endif
69
70 # -----------------------------------------------------------------------------
71
72 empty=
73 space=$(empty) $(empty)
74
75 ifeq "$(Windows)" "YES"
76 dot_bat=.bat
77 else
78 dot_bat=
79 endif
80
81 CONFIGURE_OPTS =
82 CONFIGURE_STAMP_EXTRAS :=
83
84 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
85 CONFIGURE_OPTS += --enable-library-profiling
86 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
87 endif
88
89 ifeq "$(SplitObjs)" "YES"
90 CONFIGURE_OPTS += --enable-split-objs
91 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
92 endif
93
94 BOOTSTRAPPING_STAMPS = $(addprefix stamp/bootstrapping.,Cabal filepath pretty)
95
96 .PHONY: subdirs
97
98 subdirs:
99         @echo $(SUBDIRS)
100
101 .PHONY: boot
102
103 boot: $(BOOTSTRAPPING_STAMPS) ifBuildable/ifBuildable \
104           $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
105           installPackage/installPackage
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: $(BOOTSTRAPPING_STAMPS)
115         -$(RM) -rf $*/setup
116         mkdir $*/setup
117         $(CP) $*/Setup.*hs $*/setup
118         cd $*/setup && $(GHC) -i../../bootstrapping.Cabal \
119                               -i../../bootstrapping.filepath \
120                               -i../../bootstrapping.pretty \
121                               -Wall -cpp --make Setup.*hs -o Setup
122
123 installPackage/installPackage: installPackage.hs $(BOOTSTRAPPING_STAMPS)
124         -$(RM) -rf installPackage
125         mkdir installPackage
126         $(CP) installPackage.hs installPackage/
127         cd installPackage && $(GHC) -Wall -cpp \
128                                     --make installPackage -o installPackage \
129                               -i../bootstrapping.Cabal \
130                               -i../bootstrapping.filepath \
131                               -i../bootstrapping.pretty
132
133 ifBuildable/ifBuildable: ifBuildable.hs
134         -$(RM) -rf ifBuildable
135         mkdir ifBuildable
136         $(CP) ifBuildable.hs ifBuildable/
137         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
138
139 $(BOOTSTRAPPING_STAMPS): stamp/bootstrapping.%:
140         $(RM) -rf bootstrapping.$*
141         $(CP) -R $* bootstrapping.$*
142         $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
143                                  -exec $(RM) -f {} \;
144         touch $@
145
146 .PHONY: all build configure
147
148 all: build
149
150 ifneq "$(NO_HADDOCK_DOCS)" "YES"
151 all: doc
152 endif
153
154 build: $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR))
155 build: installPackage/installPackage
156
157 configure: $(foreach SUBDIR,$(SUBDIRS), \
158              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
159
160 .PHONY: build.library.%
161
162 # We should depend on %/%.cabal here (and in other rules), but make
163 # makes that difficult.
164
165 $(foreach SUBDIR,$(SUBDIRS), \
166                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
167 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
168         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
169         ( cd $* && setup/Setup configure \
170                    $(CONFIGURE_OPTS) \
171                    --prefix=$(prefix) \
172                    --with-compiler=../../compiler/ghc-inplace$(dot_bat) \
173                    --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace$(dot_bat) \
174                    --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace$(dot_bat) \
175                    --with-ld=$(LD) \
176                    --datasubdir=ghc \
177                    --haddock-args="--use-contents=../index.html \
178                                    --use-index=../doc-index.html" \
179                    $(addprefix --configure-option=,$(CONFIGURE_ARGS)) \
180                    --configure-option=--with-cc=$(CC) ) \
181               && touch $@ || touch $*/unbuildable
182 # We don't touch $@ if configure failed as we would prefer to try
183 # configuring it next time round, rather than assuming it'll still fail.
184 # This is particularly important for corelibs, where failure means the
185 # build dies!
186
187 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
188 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
189                  %/setup/Setup ifBuildable/ifBuildable
190         ifBuildable/ifBuildable $* setup/Setup build \
191                                         $(addprefix --ghc-option=,$(GhcLibHcOpts))
192         ifBuildable/ifBuildable $* setup/Setup register --inplace
193
194 .PHONY: doc
195
196 DOC_SUBDIRS = $(filter-out haskell98,$(SUBDIRS))
197
198 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
199         sh gen_contents_index
200
201 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
202 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
203                %/setup/Setup ifBuildable/ifBuildable
204         ifBuildable/ifBuildable $* setup/Setup haddock
205
206 .PHONY: install install-docs install.library.%
207
208 INSTALL_DIR=$(prefix)/share/ghc/doc/html/
209
210 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
211 ifneq "$(NO_HADDOCK_DOCS)" "YES"
212         $(INSTALL_DATA)   index.html doc-index.html                       $(INSTALL_DIR)
213         $(INSTALL_SCRIPT) gen_contents_index                                      $(INSTALL_DIR)
214         # Hacks:
215         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.css $(INSTALL_DIR)
216         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.js  $(INSTALL_DIR)
217         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.gif $(INSTALL_DIR)
218 endif
219
220 # Cabal doesn't let us ask to install docs only, so do nothing here
221 install-docs:
222         @:
223
224 # Ideally this would depend on a stamp/build.library.%, but if it does
225 # then we can't change the libraries and then just rerun make.
226 # Thus if you install without building then it will just break.
227 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
228 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
229         ifBuildable/ifBuildable $* ../installPackage/installPackage
230
231 .PHONY: binary-dist binary-dist.library.%
232
233 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
234
235 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
236         mkdir                               $(BIN_DIST_LIBDIR)/installPackage
237         cp        installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
238         cp    Makefile                      $(BIN_DIST_LIBDIR)
239         cp    gen_contents_index            $(BIN_DIST_LIBDIR)
240         cp    index.html                    $(BIN_DIST_LIBDIR)
241         cp    doc-index.html                $(BIN_DIST_LIBDIR)
242         cp -a stamp                         $(BIN_DIST_LIBDIR)
243
244 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
245 binary-dist.library.%:
246         $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*
247         ifBuildable/ifBuildable $* cp    $*.cabal      $(BIN_DIST_LIBDIR)/$*
248         ifBuildable/ifBuildable $* cp -a dist          $(BIN_DIST_LIBDIR)/$*
249         ifBuildable/ifBuildable $* $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
250              \( -name "*_split" -o -name "autogen" \) | xargs rm -rf
251         ifBuildable/ifBuildable $* $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
252              \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
253              -exec rm {} \;
254
255 .PHONY: distclean clean clean.library.%
256
257 distclean: clean
258
259 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
260         $(RM) -f stamp/bootstrapping.*
261         $(RM) -rf bootstrapping.*
262         $(RM) -rf ifBuildable
263         $(RM) -f libraries.txt index.html doc-index.html
264
265 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
266 clean.library.%:
267         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
268         -cd $* && setup/Setup clean
269         $(RM) -rf $*/setup
270