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