Fold testsuite.git into ghc.git (re #8545)
[ghc.git] / testsuite / mk / boilerplate.mk
1
2 default: all
3
4 HAVE_EVAL := NO
5 $(eval HAVE_EVAL := YES)
6
7 ifeq "$(HAVE_EVAL)" "NO"
8 $(error Your make does not support eval. You need GNU make >= 3.81)
9 endif
10
11 ifeq "$(abspath /)" ""
12 $(error Your make does not support abspath. You need GNU make >= 3.81)
13 endif
14
15 show:
16 @echo '$(VALUE)="$($(VALUE))"'
17
18 define canonicalise
19 # $1 = path variable
20 $1_CYGPATH := $$(shell $(SHELL) -c "cygpath -m '$$($1)'" 2> /dev/null)
21 ifneq "$$($1_CYGPATH)" ""
22 # We use 'override' in case we are trying to update a value given on
23 # the commandline (e.g. TEST_HC)
24 override $1 := $$($1_CYGPATH)
25 endif
26 endef
27
28 define canonicaliseExecutable
29 # $1 = program path variable
30 ifneq "$$(shell test -x '$$($1).exe' && echo exists)" ""
31 # We use 'override' in case we are trying to update a value given on
32 # the commandline (e.g. TEST_HC)
33 override $1 := $$($1).exe
34 endif
35 $(call canonicalise,$1)
36 endef
37
38 ifeq "$(TEST_HC)" ""
39
40 STAGE1_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage1)
41 STAGE2_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage2)
42 STAGE3_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage3)
43
44 ifneq "$(wildcard $(STAGE1_GHC) $(STAGE1_GHC).exe)" ""
45
46 IN_TREE_COMPILER = YES
47 ifeq "$(BINDIST)" "YES"
48 TEST_HC := $(abspath $(TOP)/../)/bindisttest/install dir/bin/ghc
49 else ifeq "$(stage)" "1"
50 TEST_HC := $(STAGE1_GHC)
51 else ifeq "$(stage)" "3"
52 TEST_HC := $(STAGE3_GHC)
53 else
54 # use stage2 by default
55 TEST_HC := $(STAGE2_GHC)
56 endif
57
58 else
59 IN_TREE_COMPILER = NO
60 TEST_HC := $(shell which ghc)
61 endif
62
63 else
64 IN_TREE_COMPILER = NO
65 # We want to support both "ghc" and "/usr/bin/ghc" as values of TEST_HC
66 # passed in by the user, but
67 # which ghc == /usr/bin/ghc
68 # which /usr/bin/ghc == /usr/bin/ghc
69 # so on unix-like platforms we can just always 'which' it.
70 # However, on cygwin, we can't just use which:
71 # $ which c:/ghc/ghc-7.4.1/bin/ghc.exe
72 # which: no ghc.exe in (./c:/ghc/ghc-7.4.1/bin)
73 # so we start off by using realpath, and if that succeeds then we use
74 # that value. Otherwise we fall back on 'which'.
75 #
76 # Note also that we need to use 'override' in order to override a
77 # value given on the commandline.
78 TEST_HC_REALPATH := $(realpath $(TEST_HC))
79 ifeq "$(TEST_HC_REALPATH)" ""
80 override TEST_HC := $(shell which '$(TEST_HC)')
81 else
82 override TEST_HC := $(TEST_HC_REALPATH)
83 endif
84 endif
85
86 # We can't use $(dir ...) here as TEST_HC might be in a path
87 # containing spaces
88 BIN_ROOT = $(shell dirname '$(TEST_HC)')
89
90 ifeq "$(GHC_PKG)" ""
91 GHC_PKG := $(BIN_ROOT)/ghc-pkg
92 endif
93
94 ifeq "$(RUNGHC)" ""
95 RUNGHC := $(BIN_ROOT)/runghc
96 endif
97
98 ifeq "$(HSC2HS)" ""
99 HSC2HS := $(BIN_ROOT)/hsc2hs
100 endif
101
102 ifeq "$(HP2PS_ABS)" ""
103 HP2PS_ABS := $(BIN_ROOT)/hp2ps
104 endif
105
106 ifeq "$(HPC)" ""
107 HPC := $(BIN_ROOT)/hpc
108 endif
109
110 $(eval $(call canonicaliseExecutable,TEST_HC))
111 ifeq "$(shell test -x '$(TEST_HC)' && echo exists)" ""
112 $(error Cannot find ghc: $(TEST_HC))
113 endif
114
115 $(eval $(call canonicaliseExecutable,GHC_PKG))
116 ifeq "$(shell test -x '$(GHC_PKG)' && echo exists)" ""
117 $(error Cannot find ghc-pkg: $(GHC_PKG))
118 endif
119
120 $(eval $(call canonicaliseExecutable,HSC2HS))
121 ifeq "$(shell test -x '$(HSC2HS)' && echo exists)" ""
122 $(error Cannot find hsc2hs: $(HSC2HS))
123 endif
124
125 $(eval $(call canonicaliseExecutable,HP2PS_ABS))
126 ifeq "$(shell test -x '$(HP2PS_ABS)' && echo exists)" ""
127 $(error Cannot find hp2ps: $(HP2PS_ABS))
128 endif
129
130 $(eval $(call canonicaliseExecutable,HPC))
131 ifeq "$(shell test -x '$(HPC)' && echo exists)" ""
132 $(error Cannot find hpc: $(HPC))
133 endif
134
135 # Be careful when using this. On Windows it ends up looking like
136 # c:/foo/bar which confuses make, as make thinks that the : is Makefile
137 # syntax
138 TOP_ABS := $(abspath $(TOP))
139 $(eval $(call canonicalise,TOP_ABS))
140
141 GS = gs
142 CP = cp
143 RM = rm -f
144 PYTHON = python
145 ifeq "$(shell $(SHELL) -c 'python2 -c 0' 2> /dev/null && echo exists)" "exists"
146 PYTHON = python2
147 endif
148
149 # -----------------------------------------------------------------------------
150 # configuration of TEST_HC
151
152 # ghc-config.hs is a short Haskell program that runs ghc --info, parses
153 # the results, and emits a little .mk file with make bindings for the values.
154 # This way we cache the results for different values of $(TEST_HC)
155
156 $(TOP)/mk/ghc-config : $(TOP)/mk/ghc-config.hs
157 "$(TEST_HC)" --make -o $@ $<
158
159 empty=
160 space=$(empty) $(empty)
161 ghc-config-mk = $(TOP)/mk/ghcconfig$(subst $(space),_,$(subst :,_,$(subst /,_,$(subst \,_,$(TEST_HC))))).mk
162
163 $(ghc-config-mk) : $(TOP)/mk/ghc-config
164 $(TOP)/mk/ghc-config "$(TEST_HC)" >"$@"; if [ $$? != 0 ]; then $(RM) "$@"; exit 1; fi
165 # If the ghc-config fails, remove $@, and fail
166
167 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
168 include $(ghc-config-mk)
169 endif
170
171 ifeq "$(GhcDynamic)" "YES"
172 ghcThWayFlags = -dynamic
173 ghciWayFlags = -dynamic
174 ghcPluginWayFlags = -dynamic
175 else
176 ghcThWayFlags = -static
177 ghciWayFlags = -static
178 ghcPluginWayFlags = -static
179 endif
180
181 # -----------------------------------------------------------------------------
182
183 ifeq "$(HostOS)" "mingw32"
184 WINDOWS = YES
185 else
186 WINDOWS = NO
187 endif
188 ifeq "$(HostOS)" "darwin"
189 DARWIN = YES
190 else
191 DARWIN = NO
192 endif
193