Explicitly set datadir
[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 endif
76
77 # -----------------------------------------------------------------------------
78
79 empty=
80 space=$(empty) $(empty)
81
82 # -----------------------------------------------------------------------------
83
84 ifneq "$(DOING_BIN_DIST)" "YES"
85
86 CONFIGURE_OPTS =
87 CONFIGURE_STAMP_EXTRAS :=
88
89 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
90 CONFIGURE_OPTS += --enable-library-profiling
91 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
92 endif
93
94 ifeq "$(SplitObjs)" "YES"
95 CONFIGURE_OPTS += --enable-split-objs
96 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
97 endif
98
99 BOOTSTRAP_LIBS = Cabal filepath
100 BOOTSTRAP_STAMPS = $(addprefix stamp/bootstrapping.,$(BOOTSTRAP_LIBS))
101 BOOTSTRAP_INC_1_UP = $(addprefix -i../bootstrapping.,$(BOOTSTRAP_LIBS))
102 BOOTSTRAP_INC_2_UP = $(addprefix -i../../bootstrapping.,$(BOOTSTRAP_LIBS))
103
104 .PHONY: subdirs
105
106 subdirs:
107         @echo $(SUBDIRS)
108
109 .PHONY: boot
110
111 boot: $(BOOTSTRAP_STAMPS) ifBuildable/ifBuildable \
112           $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
113           installPackage/installPackage
114
115 # We build the Setup program in a setup subdirectory to stop it trying
116 # to use bits of base and Cabal when we build those packages.
117 # This also makes it slightly easier to clean.
118
119 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
120
121 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
122 %/setup/Setup: $(BOOTSTRAP_STAMPS)
123         -$(RM) -rf $*/setup
124         mkdir $*/setup
125         $(CP) $*/Setup.*hs $*/setup
126         cd $*/setup && $(GHC) -Wall -cpp --make Setup.*hs -o Setup \
127                               $(BOOTSTRAP_INC_2_UP)
128
129 installPackage/installPackage: installPackage.hs $(BOOTSTRAP_STAMPS)
130         -$(RM) -rf installPackage
131         mkdir installPackage
132         $(CP) installPackage.hs installPackage/
133         cd installPackage && $(GHC) -Wall -cpp \
134                                     --make installPackage -o installPackage \
135                                     $(BOOTSTRAP_INC_1_UP)
136
137 ifBuildable/ifBuildable: ifBuildable.hs
138         -$(RM) -rf ifBuildable
139         mkdir ifBuildable
140         $(CP) ifBuildable.hs ifBuildable/
141         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
142
143 $(BOOTSTRAP_STAMPS): stamp/bootstrapping.%:
144         $(RM) -rf bootstrapping.$*
145         $(CP) -R $* bootstrapping.$*
146         $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
147                                  -exec $(RM) -f {} \;
148         touch $@
149
150 .PHONY: all build configure
151
152 all: build
153
154 ifneq "$(NO_HADDOCK_DOCS)" "YES"
155 all: doc
156 endif
157
158 .PHONY: rebuild.library.%
159
160 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
161 rebuild.library.%: clean.library.% build.library.%
162
163 build: $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR))
164 build: installPackage/installPackage
165
166 configure: $(foreach SUBDIR,$(SUBDIRS), \
167              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
168
169 .PHONY: build.library.%
170
171 # We should depend on %/%.cabal here (and in other rules), but make
172 # makes that difficult.
173
174 # We explicitly set datadir to "$prefix/share" as, while that is the
175 # default on Linux, on Windows it defaults to
176 # "C:\\Program Files\\Common Files"
177
178 $(foreach SUBDIR,$(SUBDIRS), \
179                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
180 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
181         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
182         ( cd $* && setup/Setup configure \
183                    $(CONFIGURE_OPTS) \
184                    --prefix='$$topdir' \
185                    --datadir='$$prefix/share' \
186                    --libsubdir='$$compiler/lib/$$pkgid' \
187                    --with-compiler=../../compiler/ghc-inplace$(dot_bat) \
188                    --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace$(dot_bat) \
189                    --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace$(dot_bat) \
190                    --with-ld=$(LD) \
191                    --datasubdir=ghc \
192                    --haddock-args="--use-contents=../index.html \
193                                    --use-index=../doc-index.html" \
194                    $(addprefix --configure-option=,$(CONFIGURE_ARGS)) \
195                    --configure-option=--with-cc=$(CC) ) \
196               && touch $@ || touch $*/unbuildable
197 # We don't touch $@ if configure failed as we would prefer to try
198 # configuring it next time round, rather than assuming it'll still fail.
199 # This is particularly important for corelibs, where failure means the
200 # build dies!
201
202 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
203 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
204                  %/setup/Setup ifBuildable/ifBuildable
205         ifBuildable/ifBuildable $* setup/Setup build \
206                                         $(addprefix --ghc-option=,$(GhcLibHcOpts))
207         ifBuildable/ifBuildable $* setup/Setup register --inplace
208
209 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/CabalMakefile):\
210 %/CabalMakefile: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
211                  %/setup/Setup ifBuildable/ifBuildable
212         $(RM) $*/CabalMakefile
213         ifBuildable/ifBuildable $* setup/Setup makefile -f CabalMakefile \
214                                      $(addprefix --ghc-option=,$(GhcLibHcOpts))
215
216 .PHONY: doc
217
218 DOC_SUBDIRS = $(filter-out haskell98,$(SUBDIRS))
219
220 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
221         sh gen_contents_index
222
223 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
224 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
225                %/setup/Setup ifBuildable/ifBuildable
226         ifBuildable/ifBuildable $* setup/Setup haddock
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.*
234         $(RM) -rf bootstrapping.*
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 endif
244
245 # -----------------------------------------------------------------------------
246
247 .PHONY: install install-docs install.library.%
248
249 ROOT=$(prefix)/share/ghc/doc/html/
250
251 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
252 ifneq "$(NO_HADDOCK_DOCS)" "YES"
253         $(INSTALL_DIR)                                            $(ROOT)
254         $(INSTALL_DATA)   index.html doc-index.html               $(ROOT)
255         $(INSTALL_SCRIPT) gen_contents_index                      $(ROOT)
256         # Hacks:
257         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.css $(ROOT)
258         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.js  $(ROOT)
259         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.gif $(ROOT)
260 endif
261
262 # Cabal doesn't let us ask to install docs only, so do nothing here
263 install-docs:
264         @:
265
266 # Ideally this would depend on a stamp/build.library.%, but if it does
267 # then we can't change the libraries and then just rerun make.
268 # Thus if you install without building then it will just break.
269 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
270 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
271         ifBuildable/ifBuildable $* ../installPackage/installPackage $(prefix) $(bindir)/ghc-pkg
272
273 .PHONY: binary-dist binary-dist.library.%
274
275 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
276
277 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
278         mkdir                               $(BIN_DIST_LIBDIR)/installPackage
279         cp        installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
280         mkdir                               $(BIN_DIST_LIBDIR)/ifBuildable
281         cp        ifBuildable/ifBuildable       $(BIN_DIST_LIBDIR)/ifBuildable
282         cp    Makefile                      $(BIN_DIST_LIBDIR)
283         cp    gen_contents_index            $(BIN_DIST_LIBDIR)
284         cp    index.html                    $(BIN_DIST_LIBDIR)
285         cp    doc-index.html                $(BIN_DIST_LIBDIR)
286         cp -a stamp                         $(BIN_DIST_LIBDIR)
287
288 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
289 binary-dist.library.%:
290         $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*
291         ifBuildable/ifBuildable $* cp    $*.cabal      $(BIN_DIST_LIBDIR)/$*
292         ifBuildable/ifBuildable $* cp .setup-config    $(BIN_DIST_LIBDIR)/$*
293         ifBuildable/ifBuildable $* cp -a dist          $(BIN_DIST_LIBDIR)/$*
294         # Euch
295         ifBuildable/ifBuildable $* cp -aL include      $(BIN_DIST_LIBDIR)/$* || :
296         ifBuildable/ifBuildable $* $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
297              \( -name "*_split" -o -name "autogen" \) | xargs rm -rf
298         ifBuildable/ifBuildable $* $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
299              \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
300              -exec rm {} \;
301