Makefile 7.63 KB
Newer Older
1

2 3 4 5 6 7 8 9 10 11 12
# To do a fresh build:
#
#   make clean
#   make boot
#   make
#
# To rebuild a particular library <package>:
#
#   make clean.library.<package>
#   make build.library.<package>

Ian Lynagh's avatar
Ian Lynagh committed
13
.PHONY: default_target
14

Ian Lynagh's avatar
Ian Lynagh committed
15
default_target: build
16

17 18 19
ifeq "$(IN_BIN_DIST)" "1"
include ../Makefile-vars
else
Ian Lynagh's avatar
Ian Lynagh committed
20 21
# 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
22 23
TOP=.
include $(TOP)/mk/boilerplate.mk
24
endif
Simon Marlow's avatar
Simon Marlow committed
25

26
SUBDIRS = base filepath haskell98 template-haskell readline Cabal
27 28 29 30

ifeq "$(GhcLibsWithUnix)" "YES"
SUBDIRS += unix
endif
31 32 33
ifeq "$(Windows)" "YES"
SUBDIRS += $(wildcard Win32)
endif
34 35 36 37

# Set GhcBootLibs=YES from the command line to work with just the libraries
# needed to bootstrap GHC.
ifneq "$(GhcBootLibs)" "YES"
38 39 40 41
SUBDIRS += $(wildcard regex-base)
SUBDIRS += $(wildcard regex-posix)
SUBDIRS += $(wildcard regex-compat)
SUBDIRS += $(wildcard parsec)
42
SUBDIRS += $(wildcard haskell-src)
43
SUBDIRS += $(wildcard html)
44 45 46 47 48 49
SUBDIRS += $(wildcard network)
SUBDIRS += $(wildcard QuickCheck)
SUBDIRS += $(wildcard HUnit)
SUBDIRS += $(wildcard mtl)
SUBDIRS += $(wildcard fgl)
SUBDIRS += $(wildcard X11)
50
SUBDIRS += $(wildcard time)
Simon Marlow's avatar
Simon Marlow committed
51 52 53
ifeq "$(Windows)" "NO"
# HGL is not working on Win32, so omit it for now.  Better not to ship it
# at all than to ship a broken version.
54
SUBDIRS += $(wildcard HGL)
Simon Marlow's avatar
Simon Marlow committed
55
endif
56 57 58 59 60
SUBDIRS += $(wildcard OpenGL)
SUBDIRS += $(wildcard GLUT)
SUBDIRS += $(wildcard OpenAL)
SUBDIRS += $(wildcard ALUT)
SUBDIRS += $(wildcard stm)
61 62
SUBDIRS += $(wildcard xhtml)
SUBDIRS += $(wildcard cgi)
63
SUBDIRS += $(wildcard arrows)
64 65 66 67 68 69 70
ifeq "$(GhcLibsWithObjectIO)" "YES"
SUBDIRS += $(wildcard ObjectIO)
endif
endif

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

Ian Lynagh's avatar
Ian Lynagh committed
71 72
empty=
space=$(empty) $(empty)
73

74 75 76 77 78 79
ifeq "$(Windows)" "YES"
dot_bat=.bat
else
dot_bat=
endif

Ian Lynagh's avatar
Ian Lynagh committed
80 81
CONFIGURE_OPTS =
CONFIGURE_STAMP_EXTRAS :=
82

Ian Lynagh's avatar
Ian Lynagh committed
83 84 85 86 87
ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
CONFIGURE_OPTS += --enable-library-profiling
CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
endif

88 89 90 91 92
ifeq "$(SplitObjs)" "YES"
CONFIGURE_OPTS += --enable-split-objs
CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
endif

Ian Lynagh's avatar
Ian Lynagh committed
93 94
BOOTSTRAPPING_CABAL = bootstrapping.cabal

95 96 97 98 99
.PHONY: subdirs

subdirs:
	@echo $(SUBDIRS)

Ian Lynagh's avatar
Ian Lynagh committed
100 101
.PHONY: boot

Ian Lynagh's avatar
Ian Lynagh committed
102 103
boot: ifBuildable/ifBuildable \
	  $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup)
Ian Lynagh's avatar
Ian Lynagh committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
	# XXX Hideous hacks:
	$(GENPRIMOP) --make-haskell-source < ../compiler/prelude/primops.txt > base/GHC/Prim.hs
	$(GENPRIMOP) --make-haskell-wrappers < ../compiler/prelude/primops.txt > base/GHC/PrimopWrappers.hs

# We build the Setup program in a setup subdirectory to stop it trying
# to use bits of base and Cabal when we build those packages.
# This also makes it slightly easier to clean.

# We ought to be depending on %/Setup.*hs, but make makes that difficult.

$(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
%/setup/Setup: stamp/$(BOOTSTRAPPING_CABAL)
	-$(RM) -rf $*/setup
	mkdir $*/setup
	$(CP) $*/Setup.*hs $*/setup
119
	cd $*/setup && $(GHC) -Wall --make -i../../$(BOOTSTRAPPING_CABAL) Setup.*hs -o Setup
Ian Lynagh's avatar
Ian Lynagh committed
120

Ian Lynagh's avatar
Ian Lynagh committed
121 122 123 124
ifBuildable/ifBuildable: ifBuildable.hs stamp/$(BOOTSTRAPPING_CABAL)
	-$(RM) -rf ifBuildable
	mkdir ifBuildable
	$(CP) ifBuildable.hs ifBuildable/
125
	cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
Ian Lynagh's avatar
Ian Lynagh committed
126

Ian Lynagh's avatar
Ian Lynagh committed
127 128
stamp/$(BOOTSTRAPPING_CABAL):
	$(RM) -rf $(BOOTSTRAPPING_CABAL)
129
	$(CP) -R Cabal $(BOOTSTRAPPING_CABAL)
Ian Lynagh's avatar
Ian Lynagh committed
130 131 132 133 134 135
	$(FIND) $(BOOTSTRAPPING_CABAL) \( -name "*.o" -o -name "*.hi" \) -exec $(RM) -f {} \;
	touch $@

.PHONY: all build configure

all: build
136 137

ifneq "$(NO_HADDOCK_DOCS)" "YES"
Ian Lynagh's avatar
Ian Lynagh committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
all: doc
endif

build: $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR))

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

.PHONY: build.library.%

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

$(foreach SUBDIR,$(SUBDIRS), \
		  stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
154
	-$(RM) -f stamp/configure.library.*.$* $*/unbuildable
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
	( cd $* && setup/Setup configure \
	           $(CONFIGURE_OPTS) \
	           --prefix=$(prefix) \
	           --with-compiler=../../compiler/ghc-inplace$(dot_bat) \
	           --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace$(dot_bat) \
	           --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace$(dot_bat) \
	           --with-ld=$(LD) \
	           --datasubdir=ghc \
	           --haddock-args="--use-contents=../index.html \
	                           --use-index=../doc-index.html" \
	           $(addprefix --configure-option=,$(CONFIGURE_ARGS)) \
	           --configure-option=--with-cc=$(CC) ) \
	      && 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.
# This is particularly important for corelibs, where failure means the
# build dies!
Ian Lynagh's avatar
Ian Lynagh committed
172 173 174

$(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
175
                 %/setup/Setup ifBuildable/ifBuildable
176
	ifBuildable/ifBuildable $* setup/Setup build \
Ian Lynagh's avatar
Ian Lynagh committed
177
	                                $(addprefix --ghc-option=,$(GhcLibHcOpts))
178
	ifBuildable/ifBuildable $* setup/Setup register --inplace
Ian Lynagh's avatar
Ian Lynagh committed
179 180 181 182 183 184 185 186 187 188

.PHONY: doc

DOC_SUBDIRS = $(filter-out haskell98,$(SUBDIRS))

doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
	sh gen_contents_index

$(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
189
               %/setup/Setup ifBuildable/ifBuildable
190
	ifBuildable/ifBuildable $* setup/Setup haddock
Ian Lynagh's avatar
Ian Lynagh committed
191

192
.PHONY: install install-docs install.library.%
Ian Lynagh's avatar
Ian Lynagh committed
193 194 195 196

INSTALL_DIR=$(prefix)/share/ghc/doc/html/

install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
197
ifneq "$(NO_HADDOCK_DOCS)" "YES"
Ian Lynagh's avatar
Ian Lynagh committed
198 199 200 201 202 203
	$(INSTALL_DATA)   index.html doc-index.html 			  $(INSTALL_DIR)
	$(INSTALL_SCRIPT) gen_contents_index 					  $(INSTALL_DIR)
	# Hacks:
	$(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.css $(INSTALL_DIR)
	$(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.js  $(INSTALL_DIR)
	$(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.gif $(INSTALL_DIR)
204
endif
Ian Lynagh's avatar
Ian Lynagh committed
205

206 207 208 209
# Cabal doesn't let us ask to install docs only, so do nothing here
install-docs:
	@:

Ian Lynagh's avatar
Ian Lynagh committed
210 211 212 213
# 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.
$(foreach SUBDIR,$(SUBDIRS),stamp/configure.library.install.$(SUBDIR)): \
214
stamp/configure.library.install.%: %/setup/Setup ifBuildable/ifBuildable
Ian Lynagh's avatar
Ian Lynagh committed
215
	-$(RM) -f stamp/configure.library.*.$*
216
	ifBuildable/ifBuildable $* setup/Setup configure \
Ian Lynagh's avatar
Ian Lynagh committed
217 218 219 220
	                                    $(CONFIGURE_OPTS) \
	                                    --prefix=$(prefix) \
	                                    --with-compiler=$(bindir)/ghc \
	                                    --datasubdir=ghc
Ian Lynagh's avatar
Ian Lynagh committed
221 222 223 224
	touch $@

# We need to reconfigure as we now need to register with the normal ghc-pkg
$(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
225 226
install.library.%: stamp/configure.library.install.% \
                   %/setup/Setup ifBuildable/ifBuildable
227
	ifBuildable/ifBuildable $* setup/Setup install
Ian Lynagh's avatar
Ian Lynagh committed
228

229 230 231
.PHONY: distclean clean clean.library.%

distclean: clean
Ian Lynagh's avatar
Ian Lynagh committed
232 233 234 235

clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
	$(RM) -f stamp/$(BOOTSTRAPPING_CABAL)
	$(RM) -rf $(BOOTSTRAPPING_CABAL)
Ian Lynagh's avatar
Ian Lynagh committed
236
	$(RM) -rf ifBuildable
Ian Lynagh's avatar
Ian Lynagh committed
237 238 239 240
	$(RM) -f libraries.txt index.html doc-index.html

$(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
clean.library.%:
241
	$(RM) -f stamp/configure.library.*.$* $*/unbuildable
Ian Lynagh's avatar
Ian Lynagh committed
242 243
	-cd $* && setup/Setup clean
	$(RM) -rf $*/setup
244