Makefile 14.3 KB
Newer Older
1

2 3 4 5 6 7 8 9 10
# To do a fresh build:
#
#   make clean
#   make boot
#   make
#
# To rebuild a particular library <package>:
#
#   make clean.library.<package>
11
#   make make.library.<package>
12 13 14
#
# or the following is equivalent:
#
15
#   make remake.library.<package>
16 17 18 19 20
#
# To add a new library to the tree, do
#
#   darcs get http://darcs.haskell.org/packages/foo
#   [ -e foo/configure.ac ] && ( cd foo && autoreconf )
21
#   make make.library.foo
22

23
.PHONY: default_target show
24

25
default_target: all
26

27 28 29
show:
	@echo '$(VALUE)="$($(VALUE))"'

30 31 32 33 34 35
# make doesn't give us an easy way to get the libraries built in
# dependency order the first time, but not rebuild base (for example)
# when we want to rebuild another library later.
# So for now we just don't do anything in parallel in here.
.NOTPARALLEL:

Ian Lynagh's avatar
Ian Lynagh committed
36 37
# Ideally we'd just include something to give us variables
# for paths and arguments to tools etc, and those set in mk/build.mk.
Ian Lynagh's avatar
Ian Lynagh committed
38
TOP=..
Ian Lynagh's avatar
Ian Lynagh committed
39
include $(TOP)/mk/boilerplate.mk
Ian Lynagh's avatar
Ian Lynagh committed
40
include $(TOP)/mk/cabal-flags.mk
Simon Marlow's avatar
Simon Marlow committed
41

42 43
# Any libraries listed here should also be in ../packages

44 45
SUBDIRS  = ghc-prim $(INTEGER_LIBRARY) base array packedstring
SUBDIRS += containers bytestring old-locale old-time filepath directory
46 47 48
ifeq "$(GhcLibsWithUnix)" "YES"
SUBDIRS += unix
endif
49 50 51
ifeq "$(Windows)" "YES"
SUBDIRS += $(wildcard Win32)
endif
Ian Lynagh's avatar
Ian Lynagh committed
52
SUBDIRS += process pretty hpc template-haskell editline Cabal random haskell98
53 54 55 56

# Set GhcBootLibs=YES from the command line to work with just the libraries
# needed to bootstrap GHC.
ifneq "$(GhcBootLibs)" "YES"
57 58 59 60
SUBDIRS += $(wildcard regex-base)
SUBDIRS += $(wildcard regex-posix)
SUBDIRS += $(wildcard regex-compat)
SUBDIRS += $(wildcard parsec)
61
SUBDIRS += $(wildcard haskell-src)
62
SUBDIRS += $(wildcard html)
63 64 65 66
SUBDIRS += $(wildcard network)
SUBDIRS += $(wildcard QuickCheck)
SUBDIRS += $(wildcard HUnit)
SUBDIRS += $(wildcard mtl)
67
SUBDIRS += $(wildcard time)
68
SUBDIRS += $(wildcard stm)
69
SUBDIRS += $(wildcard xhtml)
Ian Lynagh's avatar
Ian Lynagh committed
70
SUBDIRS += $(wildcard parallel)
71
SUBDIRS_BUILD += $(wildcard dph/dph-base)
72
SUBDIRS_BUILD += $(wildcard dph/dph-prim-interface)
73 74 75
SUBDIRS_BUILD += $(wildcard dph/dph-prim-seq)
SUBDIRS_BUILD += $(wildcard dph/dph-prim-par)
SUBDIRS_BUILD += $(wildcard dph/dph)
76 77
endif

78 79
SUBDIRS += $(SUBDIRS_BUILD)

80 81
# -----------------------------------------------------------------------------

Ian Lynagh's avatar
Ian Lynagh committed
82 83
empty=
space=$(empty) $(empty)
84

Ian Lynagh's avatar
Ian Lynagh committed
85 86
# -----------------------------------------------------------------------------

87 88 89 90
ifeq "$(ghc_ge_609)" "YES"
GhcLibHcOpts += -fno-warn-deprecated-flags
endif

Ian Lynagh's avatar
Ian Lynagh committed
91
ifeq "$(RelocatableBuild)" "YES"
92 93 94 95 96
# On Windows we want to make moveable bindists, but we need to tell
# ghc-pkg where the haddock docs are. Therefore we completely ignore
# where the user tells us to put the haddock documentation and put it
# somewhere whose relative location we know. When installing we need
# to give Cabal a real path, though.
97 98 99 100
iprefix             = $$topdir
ibindir             = $$topdir
ilibdir             = $$topdir
ilibexecdir         = $$topdir
Clemens Fruhwirth's avatar
Clemens Fruhwirth committed
101
idynlibdir          = $$topdir
102
idatadir            = $$topdir
103
idocdir             = $$topdir/doc/libraries/$$pkg
Clemens Fruhwirth's avatar
Clemens Fruhwirth committed
104
ihaddockdir         = $$topdir/doc/libraries/$$pkg
105
ihtmldir            = $$httptopdir/doc/libraries/$$pkg
106
html_installed_root = $(prefix)/doc/libraries
107 108 109
else
# On non-Windows we can just give absolute paths all the time, and
# thus obey the htmldir that we are given.
110 111 112 113
iprefix             = $(prefix)
ibindir             = $(bindir)
ilibdir             = $(libdir)
ilibexecdir         = $(libexecdir)
Clemens Fruhwirth's avatar
Clemens Fruhwirth committed
114
idynlibdir          = $(dynlibdir)
115
idatadir            = $(datadir)
116
idocdir             = $(docdir)/libraries/$$pkg
Clemens Fruhwirth's avatar
Clemens Fruhwirth committed
117
ihaddockdir         = $(htmldir)/libraries/$$pkg
118
ihtmldir            = $(htmldir)/libraries/$$pkg
119
html_installed_root = $(htmldir)/libraries
120 121
endif

Ian Lynagh's avatar
Ian Lynagh committed
122 123
ifneq "$(DOING_BIN_DIST)" "YES"

Ian Lynagh's avatar
Ian Lynagh committed
124 125
CONFIGURE_OPTS =
CONFIGURE_STAMP_EXTRAS :=
126

Ian Lynagh's avatar
Ian Lynagh committed
127 128 129 130 131
ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
CONFIGURE_OPTS += --enable-library-profiling
CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
endif

132
ifeq "$(BuildSharedLibs)" "YES"
133 134 135 136
CONFIGURE_OPTS += --enable-shared
CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
endif

137 138 139 140 141
ifeq "$(SplitObjs)" "YES"
CONFIGURE_OPTS += --enable-split-objs
CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
endif

142 143 144 145 146
.PHONY: subdirs

subdirs:
	@echo $(SUBDIRS)

147
HERE_ABS=$(FPTOOLS_TOP_ABS)/libraries
Ian Lynagh's avatar
Ian Lynagh committed
148

Ian Lynagh's avatar
Ian Lynagh committed
149
IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/packages
Ian Lynagh's avatar
Ian Lynagh committed
150

151
CABAL_GHC_FLAGS = -Wall
Ian Lynagh's avatar
Ian Lynagh committed
152 153 154
ifeq "$(ghc_ge_605)" "NO"
CABAL_GHC_FLAGS += -cpp
endif
155

156 157 158 159
# Euch, hideous hack:
CABAL_VERSION = $(shell grep "^Version:" Cabal/Cabal.cabal | sed -e "s/^Version: //" -e 's/\./,/g')

BOOTSTRAPPING_FLAGS = $(CABAL_GHC_FLAGS) -DCABAL_VERSION=$(CABAL_VERSION) -odir $(HERE_ABS)/bootstrapping -hidir $(HERE_ABS)/bootstrapping -i$(HERE_ABS)/Cabal -i$(HERE_ABS)/filepath -i$(HERE_ABS)/hpc
Ian Lynagh's avatar
Ian Lynagh committed
160

161 162
.PHONY: boot

Ian Lynagh's avatar
Ian Lynagh committed
163
boot: ifBuildable/ifBuildable cabal-bin bootstrapping.conf
164

165
cabal-bin: cabal-bin.hs
166
	mkdir $(HERE_ABS)/bootstrapping
167 168
	$(GHC) $(BOOTSTRAPPING_FLAGS) --make cabal-bin -o cabal-bin

Ian Lynagh's avatar
Ian Lynagh committed
169
bootstrapping.conf: cabal-bin
170 171
	echo "[]" > $@.tmp
	-cd filepath && $(CABAL) clean     --distpref=dist-bootstrapping
172
	cd filepath && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
173 174 175
	cd filepath && $(CABAL) build     --distpref=dist-bootstrapping
	cd filepath && $(CABAL) install   --distpref=dist-bootstrapping --inplace
	-cd Cabal    && $(CABAL) clean     --distpref=dist-bootstrapping
176
	cd Cabal    && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
177 178
	cd Cabal    && $(CABAL) build     --distpref=dist-bootstrapping
	cd Cabal    && $(CABAL) install   --distpref=dist-bootstrapping --inplace
Ian Lynagh's avatar
Ian Lynagh committed
179 180 181 182
	-cd hpc    && $(CABAL) clean     --distpref=dist-bootstrapping
	cd hpc    && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
	cd hpc    && $(CABAL) build     --distpref=dist-bootstrapping
	cd hpc    && $(CABAL) install   --distpref=dist-bootstrapping --inplace
183
	mv $@.tmp $@
184

185
ifBuildable/ifBuildable: ifBuildable.hs
Ian Lynagh's avatar
Ian Lynagh committed
186 187 188
	-$(RM) -rf ifBuildable
	mkdir ifBuildable
	$(CP) ifBuildable.hs ifBuildable/
189
ifeq "$(stage)" "2"
190
	cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable
191
else
192
	cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
193
endif
Ian Lynagh's avatar
Ian Lynagh committed
194

Ian Lynagh's avatar
Ian Lynagh committed
195 196 197
.PHONY: all build configure

all: build
198

199
ifeq "$(HADDOCK_DOCS)" "YES"
Ian Lynagh's avatar
Ian Lynagh committed
200 201 202
all: doc
endif

203
.PHONY: rebuild.library.%
204
.PHONY: remake.library.%
205 206

$(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
207 208 209 210
rebuild.library.%: clean.library.% build.library.%

$(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
remake.library.%: clean.library.% make.library.%
211

Simon Marlow's avatar
Simon Marlow committed
212 213
# NB. we're depending on make chasing dependencies from left to right here.
# This bit goes wrong with 'make -j'.
214
build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
Ian Lynagh's avatar
Ian Lynagh committed
215 216 217 218 219

configure: $(foreach SUBDIR,$(SUBDIRS), \
             stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))

.PHONY: build.library.%
220
.PHONY: make.library.%
Ian Lynagh's avatar
Ian Lynagh committed
221 222 223 224

# We should depend on %/%.cabal here (and in other rules), but make
# makes that difficult.

225
ALL_CONFIGURE_FLAGS = \
226 227 228
               $(INSTALL_DIRS_CONFIGURE_FLAGS) \
               $(USE_STAGE1_CONFIGURE_FLAGS) \
               $(COMMON_CONFIGURE_FLAGS) \
229
	           --haddock-options="--use-contents=../index.html \
230
	                              --use-index=../doc-index.html" \
Ian Lynagh's avatar
Ian Lynagh committed
231
	           $(CONFIGURE_OPTS)
232 233 234

$(foreach SUBDIR,$(SUBDIRS), \
		  stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
235 236
stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: cabal-bin \
                                                          bootstrapping.conf
237
	-$(RM) -f stamp/configure.library.*.$* $*/unbuildable
238
	$(MKDIRHIER) `dirname $@`
239
	( cd $* && $(CABAL) configure $(ALL_CONFIGURE_FLAGS) ) \
240 241 242
	      && touch $@ || touch $*/unbuildable
# We don't touch $@ if configure failed as we would prefer to try
# configuring it next time round, rather than assuming it'll still fail.
243
# This is particularly important for bootlibs, where failure means the
244
# build dies!
Ian Lynagh's avatar
Ian Lynagh committed
245

246
# Build the library using 'make'
247 248 249 250
# We re-run 'setup makefile' each time, just in case any preprocessing
# needs to be done.  However, we're careful not to overwrite GNUmakefile
# if it hasn't changed, so that dependency-generation isn't forced
# every time.
251 252 253
# Packages in $(SUBDIRS_BUILD) need to use the build.* rules instead of
# make.*, so filter them out and use an alternate rule below instead.
$(foreach SUBDIR,$(filter-out $(SUBDIRS_BUILD),$(SUBDIRS)),make.library.$(SUBDIR)):\
254
make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
255
                cabal-bin ifBuildable/ifBuildable bootstrapping.conf
256
	if $(IFBUILDABLE) $*; then \
257
	  cd $* && \
258
	  cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
259
	  mv GNUmakefile GNUmakefile.tmp; \
260
	  $(CABAL) makefile -f GNUmakefile; \
261
	  cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
262
	  $(MAKE) $(MFLAGS) && \
263
	  $(CABAL) register --inplace; \
264
	fi
265

266 267
MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local

268 269 270
# Alternate rule, as described above
$(foreach SUBDIR,$(SUBDIRS_BUILD),make.library.$(SUBDIR)):\
make.library.%: build.library.%
Ian Lynagh's avatar
Ian Lynagh committed
271

272
# Build the library using 'setup build' (not the default)
Ian Lynagh's avatar
Ian Lynagh committed
273 274
$(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
275
                 cabal-bin ifBuildable/ifBuildable bootstrapping.conf
276
	if $(IFBUILDABLE) $*; then \
277
	  cd $* && \
Ian Lynagh's avatar
Ian Lynagh committed
278
	  $(CABAL) build $(BUILD_FLAGS); \
279
	  $(CABAL) register --inplace; \
280
	fi
Ian Lynagh's avatar
Ian Lynagh committed
281

282 283 284
.PHONY: doc html

html: doc
Ian Lynagh's avatar
Ian Lynagh committed
285 286

doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
287
	sh gen_contents_index --inplace
Ian Lynagh's avatar
Ian Lynagh committed
288

289 290 291 292 293
# Making hyperlinked source only works if we have hscolour
ifneq "$(HSCOLOUR)" ""
CABAL_HADDOCK_FLAGS=--hyperlink-source
endif

Ian Lynagh's avatar
Ian Lynagh committed
294 295
$(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
296
               cabal-bin ifBuildable/ifBuildable bootstrapping.conf
297
	if $(IFBUILDABLE) $*; then \
298 299
	  cd $* && $(CABAL) haddock --html-location='../$$pkg' \
	                            $(CABAL_HADDOCK_FLAGS); \
300
	fi
301
ifneq "$(HSCOLOUR)" ""
302 303
# We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
# mismatch
304
	if $(IFBUILDABLE) $*; then cp hscolour.css $*/dist/doc/html/*/src/; fi
305
endif
Ian Lynagh's avatar
Ian Lynagh committed
306

Ian Lynagh's avatar
Ian Lynagh committed
307 308 309 310 311
.PHONY: distclean clean clean.library.%

distclean: clean

clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
312 313
	-cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
	-cd Cabal    && $(CABAL) clean --distpref=dist-bootstrapping
Ian Lynagh's avatar
Ian Lynagh committed
314
	-cd hpc      && $(CABAL) clean --distpref=dist-bootstrapping
315
	$(RM) -rfd bootstrapping
316 317
	$(RM) -f bootstrapping.conf     bootstrapping.conf.old
	$(RM) -f bootstrapping.conf.tmp bootstrapping.conf.tmp.old
Ian Lynagh's avatar
Ian Lynagh committed
318
	$(RM) -f cabal-bin cabal-bin.exe
Ian Lynagh's avatar
Ian Lynagh committed
319
	$(RM) -rf ifBuildable
320
	$(RM) -f libraries.txt index.html doc-index.html doc-index*.html
Simon Marlow's avatar
Simon Marlow committed
321
	$(RM) -f haddock* *.gif
Ian Lynagh's avatar
Ian Lynagh committed
322

Simon Marlow's avatar
Simon Marlow committed
323 324 325
distclean:
	$(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)

Ian Lynagh's avatar
Ian Lynagh committed
326 327 328
$(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
clean.library.%:
	$(RM) -f stamp/configure.library.*.$* $*/unbuildable
329 330
	-cd $* && $(CABAL) clean
	$(RM) -f $*/Setup $*/Setup.exe $*/Setup.hi $*/Setup.o
331
	$(RM) $*/GNUmakefile $*/Makefile.local
Ian Lynagh's avatar
Ian Lynagh committed
332 333 334 335
endif

# -----------------------------------------------------------------------------

336
.PHONY: install install-docs install.library.%
Ian Lynagh's avatar
Ian Lynagh committed
337 338

install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
339
ifeq "$(HADDOCK_DOCS)" "YES"
340 341 342
	$(INSTALL_DIR)                                                     $(DESTDIR)$(html_installed_root)
	$(INSTALL_DATA)   index.html doc-index*.html                       $(DESTDIR)$(html_installed_root)
	$(INSTALL_SCRIPT) gen_contents_index                               $(DESTDIR)$(html_installed_root)
Ian Lynagh's avatar
Ian Lynagh committed
343
	# Hacks:
344 345 346
	$(INSTALL_DATA)   base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
	$(INSTALL_DATA)   base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
	$(INSTALL_DATA)   base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
347
endif
Ian Lynagh's avatar
Ian Lynagh committed
348

349 350 351 352
# Cabal doesn't let us ask to install docs only, so do nothing here
install-docs:
	@:

Ian Lynagh's avatar
Ian Lynagh committed
353 354 355
# Ideally this would depend on a stamp/build.library.%, but if it does
# then we can't change the libraries and then just rerun make.
# Thus if you install without building then it will just break.
356 357 358 359

# prefix and (on Windows) htmldir use $topdir when configuring, so we
# need to tell installPackage the real path to use when installing.

360 361 362
# We also need to pass all the other directories in, as they can be
# overridden when installing a bindist.

Ian Lynagh's avatar
Ian Lynagh committed
363
$(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
364
install.library.%: ifBuildable/ifBuildable
365
	if $(IFBUILDABLE) $*; then \
366
	  cd $* && \
367
	  $(INSTALL_PACKAGE) install '$(GHC_PKG_PROG)' '$(DESTDIR)$(libdir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' ; \
368
	fi
Ian Lynagh's avatar
Ian Lynagh committed
369

370 371 372 373
.PHONY: binary-dist binary-dist.library.%

BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries

374
binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
Ian Lynagh's avatar
Ian Lynagh committed
375 376
	mkdir                               $(BIN_DIST_LIBDIR)/ifBuildable
	cp 	  ifBuildable/ifBuildable       $(BIN_DIST_LIBDIR)/ifBuildable
377
	cp    Makefile                      $(BIN_DIST_LIBDIR)
378
ifeq "$(HADDOCK_DOCS)" "YES"
379 380
	cp    gen_contents_index            $(BIN_DIST_LIBDIR)
	cp    index.html                    $(BIN_DIST_LIBDIR)
381
	cp    doc-index*.html               $(BIN_DIST_LIBDIR)
382
endif
383
	cp -pR stamp                         $(BIN_DIST_LIBDIR)
384 385 386

$(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
binary-dist.library.%:
387
	if $(IFBUILDABLE) $*; then \
Ian Lynagh's avatar
Ian Lynagh committed
388
	  $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*; \
389 390
	  cd $* && \
	  cp    $*.cabal      $(BIN_DIST_LIBDIR)/$* && \
391
	  cp    LICENSE       $(BIN_DIST_LIBDIR)/$* && \
392
	  cp -R dist          $(BIN_DIST_LIBDIR)/$* && \
393
	  $(FIND) . -name "*.buildinfo" -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
394
	  $(FIND) . -name unbuildable -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
395
	  (cp -RL include      $(BIN_DIST_LIBDIR)/$* || true) && \
396 397 398
	  $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
	     \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
	  $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
399
	     \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
400 401
	     -exec rm {} \; ; \
	fi
402 403 404 405 406 407 408

# Ignore some doc targets that we don't support
# The root recurses into us when these targets are made
.PHONY: html-no-chunks chm HxS fo dvi ps pdf
html-no-chunks chm HxS fo dvi ps pdf:
	@: