boilerplate.mk 5.89 KB
Newer Older
thomie's avatar
thomie committed
1 2 3 4 5 6 7
# Eliminate use of the built-in implicit rules, and clear out the default list
# of suffixes for suffix rules. Speeds up make quite a bit. Both are needed
# for the shortest `make -d` output.
# Don't set --no-builtin-variables; some rules might stop working if you do
# (e.g. 'make clean' in testsuite/ currently relies on an implicit $RM).
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:
8

9 10
default: all

Ian Lynagh's avatar
Ian Lynagh committed
11 12 13 14
HAVE_EVAL := NO
$(eval HAVE_EVAL := YES)

ifeq "$(HAVE_EVAL)" "NO"
15 16 17 18 19
$(error Your make does not support eval. You need GNU make >= 3.81)
endif

ifeq "$(abspath /)" ""
$(error Your make does not support abspath. You need GNU make >= 3.81)
Ian Lynagh's avatar
Ian Lynagh committed
20 21
endif

Ian Lynagh's avatar
Ian Lynagh committed
22 23 24
show:
	@echo '$(VALUE)="$($(VALUE))"'

25
define canonicalise
26
# $1 = path variable
Ian Lynagh's avatar
Ian Lynagh committed
27
$1_CYGPATH := $$(shell $(SHELL) -c "cygpath -m '$$($1)'" 2> /dev/null)
28
ifneq "$$($1_CYGPATH)" ""
Ian Lynagh's avatar
Ian Lynagh committed
29 30 31
# We use 'override' in case we are trying to update a value given on
# the commandline (e.g. TEST_HC)
override $1 := $$($1_CYGPATH)
32 33 34
endif
endef

35 36
define canonicaliseExecutable
# $1 = program path variable
37
ifneq "$$(shell test -x '$$($1).exe' && echo exists)" ""
Ian Lynagh's avatar
Ian Lynagh committed
38 39 40
# We use 'override' in case we are trying to update a value given on
# the commandline (e.g. TEST_HC)
override $1 := $$($1).exe
41 42 43 44
endif
$(call canonicalise,$1)
endef

45 46
ifeq "$(TEST_HC)" ""

47 48 49
STAGE1_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage1)
STAGE2_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage2)
STAGE3_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage3)
50

51
ifneq "$(wildcard $(STAGE1_GHC) $(STAGE1_GHC).exe)" ""
52

53
IMPLICIT_COMPILER = NO
54
IN_TREE_COMPILER = YES
55
ifeq "$(BINDIST)" "YES"
56
TEST_HC := $(abspath $(TOP)/../)/bindisttest/install   dir/bin/ghc
57 58 59
else ifeq "$(stage)" "1"
TEST_HC := $(STAGE1_GHC)
else ifeq "$(stage)" "3"
60
TEST_HC := $(STAGE3_GHC)
61 62
else
# use stage2 by default
63
TEST_HC := $(STAGE2_GHC)
64 65
endif

66
else
67
IMPLICIT_COMPILER = YES
68
IN_TREE_COMPILER = NO
69 70 71
TEST_HC := $(shell which ghc)
endif

72
else
73 74 75 76 77
ifeq "$(TEST_HC)" "ghc"
IMPLICIT_COMPILER = YES
else
IMPLICIT_COMPILER = NO
endif
78
IN_TREE_COMPILER = NO
Ian Lynagh's avatar
Ian Lynagh committed
79 80 81 82
# We want to support both "ghc" and "/usr/bin/ghc" as values of TEST_HC
# passed in by the user, but
#     which ghc          == /usr/bin/ghc
#     which /usr/bin/ghc == /usr/bin/ghc
Ian Lynagh's avatar
Ian Lynagh committed
83 84 85 86 87 88 89 90 91 92 93
# so on unix-like platforms we can just always 'which' it.
# However, on cygwin, we can't just use which:
#     $ which c:/ghc/ghc-7.4.1/bin/ghc.exe
#     which: no ghc.exe in (./c:/ghc/ghc-7.4.1/bin)
# so we start off by using realpath, and if that succeeds then we use
# that value. Otherwise we fall back on 'which'.
#
# Note also that we need to use 'override' in order to override a
# value given on the commandline.
TEST_HC_REALPATH := $(realpath $(TEST_HC))
ifeq "$(TEST_HC_REALPATH)" ""
Ian Lynagh's avatar
Ian Lynagh committed
94
override TEST_HC := $(shell which '$(TEST_HC)')
Ian Lynagh's avatar
Ian Lynagh committed
95 96 97
else
override TEST_HC := $(TEST_HC_REALPATH)
endif
98
endif
99

100 101 102
# We can't use $(dir ...) here as TEST_HC might be in a path
# containing spaces
BIN_ROOT = $(shell dirname '$(TEST_HC)')
Ian Lynagh's avatar
Ian Lynagh committed
103

104 105 106 107 108 109
ifeq "$(IMPLICIT_COMPILER)" "YES"
find_tool = $(shell which $(1))
else
find_tool = $(BIN_ROOT)/$(1)
endif

110
ifeq "$(GHC_PKG)" ""
111
GHC_PKG := $(call find_tool,ghc-pkg)
112
endif
113

ian@well-typed.com's avatar
ian@well-typed.com committed
114
ifeq "$(RUNGHC)" ""
115
RUNGHC := $(call find_tool,runghc)
ian@well-typed.com's avatar
ian@well-typed.com committed
116 117
endif

118 119 120 121
ifeq "$(HADDOCK)" ""
HADDOCK := $(call find_tool,haddock)
endif

122
ifeq "$(HSC2HS)" ""
123
HSC2HS := $(call find_tool,hsc2hs)
124 125
endif

126
ifeq "$(HP2PS_ABS)" ""
127
HP2PS_ABS := $(call find_tool,hp2ps)
128 129
endif

130
ifeq "$(HPC)" ""
131
HPC := $(call find_tool,hpc)
132 133
endif

Ian Lynagh's avatar
Ian Lynagh committed
134
$(eval $(call canonicaliseExecutable,TEST_HC))
135
ifeq "$(shell test -x '$(TEST_HC)' && echo exists)" ""
Ian Lynagh's avatar
Ian Lynagh committed
136
$(error Cannot find ghc: $(TEST_HC))
137
endif
138

139
$(eval $(call canonicaliseExecutable,GHC_PKG))
140
ifeq "$(shell test -x '$(GHC_PKG)' && echo exists)" ""
Ian Lynagh's avatar
Ian Lynagh committed
141
$(error Cannot find ghc-pkg: $(GHC_PKG))
142
endif
143

144 145
$(eval $(call canonicaliseExecutable,HADDOCK))
ifeq "$(shell test -x '$(HADDOCK)' && echo exists)" ""
146 147
# haddock is optional. Use 'override' to override canonicalise's override...
override HADDOCK :=
148 149
endif

150
$(eval $(call canonicaliseExecutable,HSC2HS))
151
ifeq "$(shell test -x '$(HSC2HS)' && echo exists)" ""
Ian Lynagh's avatar
Ian Lynagh committed
152
$(error Cannot find hsc2hs: $(HSC2HS))
153 154
endif

155
$(eval $(call canonicaliseExecutable,HP2PS_ABS))
156
ifeq "$(shell test -x '$(HP2PS_ABS)' && echo exists)" ""
Ian Lynagh's avatar
Ian Lynagh committed
157
$(error Cannot find hp2ps: $(HP2PS_ABS))
158 159
endif

160
$(eval $(call canonicaliseExecutable,HPC))
161
ifeq "$(shell test -x '$(HPC)' && echo exists)" ""
162 163 164
$(error Cannot find hpc: $(HPC))
endif

165 166 167
# Be careful when using this. On Windows it ends up looking like
# c:/foo/bar which confuses make, as make thinks that the : is Makefile
# syntax
168 169 170
TOP_ABS := $(abspath $(TOP))
$(eval $(call canonicalise,TOP_ABS))

171 172 173
GS = gs
CP = cp
RM = rm -f
174
PYTHON = python
175 176 177
ifeq "$(shell $(SHELL) -c 'python2 -c 0' 2> /dev/null && echo exists)" "exists"
PYTHON = python2
endif
178

179 180
CHECK_API_ANNOTATIONS := $(abspath $(TOP)/../inplace/bin/check-api-annotations)

181 182 183 184 185 186 187
# -----------------------------------------------------------------------------
# configuration of TEST_HC

# ghc-config.hs is a short Haskell program that runs ghc --info, parses
# the results, and emits a little .mk file with make bindings for the values.
# This way we cache the results for different values of $(TEST_HC)

188
$(TOP)/mk/ghc-config : $(TOP)/mk/ghc-config.hs
189 190
	"$(TEST_HC)" --make -o $@ $<

Simon Marlow's avatar
Simon Marlow committed
191 192
empty=
space=$(empty) $(empty)
193
ghc-config-mk = $(TOP)/mk/ghcconfig$(subst $(space),_,$(subst :,_,$(subst /,_,$(subst \,_,$(TEST_HC))))).mk
194

195 196 197
$(ghc-config-mk) : $(TOP)/mk/ghc-config
	$(TOP)/mk/ghc-config "$(TEST_HC)" >"$@"; if [ $$? != 0 ]; then $(RM) "$@"; exit 1; fi
# If the ghc-config fails, remove $@, and fail
198

199
# Note: $(CLEANING) is not defined in the testsuite.
200
ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
201
include $(ghc-config-mk)
202
endif
203

ian@well-typed.com's avatar
ian@well-typed.com committed
204 205 206 207 208 209 210 211 212 213
ifeq "$(GhcDynamic)" "YES"
ghcThWayFlags     = -dynamic
ghciWayFlags      = -dynamic
ghcPluginWayFlags = -dynamic
else
ghcThWayFlags     = -static
ghciWayFlags      = -static
ghcPluginWayFlags = -static
endif

214 215
# -----------------------------------------------------------------------------

216 217 218 219 220
ifeq "$(HostOS)" "mingw32"
WINDOWS = YES
else
WINDOWS = NO
endif
Ian Lynagh's avatar
Ian Lynagh committed
221 222 223 224 225
ifeq "$(HostOS)" "darwin"
DARWIN = YES
else
DARWIN = NO
endif
226