Merge remote-tracking branch 'remotes/alistair23/tags/pull-riscv-to-apply-20210921...
[qemu.git] / tests / tcg / configure.sh
1 #! /bin/sh
2
3 if test -z "$source_path"; then
4 echo Do not invoke this script directly. It is called
5 echo automatically by configure.
6 exit 1
7 fi
8
9 write_c_skeleton() {
10 cat > $TMPC <<EOF
11 int main(void) { return 0; }
12 EOF
13 }
14
15 has() {
16 command -v "$1" >/dev/null 2>&1
17 }
18
19 do_compiler() {
20 # Run the compiler, capturing its output to the log. First argument
21 # is compiler binary to execute.
22 local compiler="$1"
23 shift
24 if test -n "$BASH_VERSION"; then eval '
25 echo >>config.log "
26 funcs: ${FUNCNAME[*]}
27 lines: ${BASH_LINENO[*]}"
28 '; fi
29 echo $compiler "$@" >> config.log
30 $compiler "$@" >> config.log 2>&1 || return $?
31 }
32
33
34 TMPDIR1="config-temp"
35 TMPC="${TMPDIR1}/qemu-conf.c"
36 TMPE="${TMPDIR1}/qemu-conf.exe"
37
38 container="no"
39 if test $use_containers = "yes"; then
40 if has "docker" || has "podman"; then
41 container=$($python $source_path/tests/docker/docker.py probe)
42 fi
43 fi
44
45 # cross compilers defaults, can be overridden with --cross-cc-ARCH
46 : ${cross_cc_aarch64="aarch64-linux-gnu-gcc"}
47 : ${cross_cc_aarch64_be="$cross_cc_aarch64"}
48 : ${cross_cc_cflags_aarch64_be="-mbig-endian"}
49 : $(cross_cc_alpha="alpha-linux-gnu-gcc")
50 : ${cross_cc_arm="arm-linux-gnueabihf-gcc"}
51 : ${cross_cc_cflags_armeb="-mbig-endian"}
52 : ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
53 : ${cross_cc_cflags_hexagon="-mv67 -O2 -static"}
54 : ${cross_cc_hppa="hppa-linux-gnu-gcc"}
55 : ${cross_cc_i386="i686-linux-gnu-gcc"}
56 : ${cross_cc_cflags_i386="-m32"}
57 : ${cross_cc_m68k="m68k-linux-gnu-gcc"}
58 : $(cross_cc_mips64el="mips64el-linux-gnuabi64-gcc")
59 : $(cross_cc_mips64="mips64-linux-gnuabi64-gcc")
60 : $(cross_cc_mipsel="mipsel-linux-gnu-gcc")
61 : $(cross_cc_mips="mips-linux-gnu-gcc")
62 : ${cross_cc_ppc="powerpc-linux-gnu-gcc"}
63 : ${cross_cc_cflags_ppc="-m32"}
64 : ${cross_cc_ppc64="powerpc64-linux-gnu-gcc"}
65 : ${cross_cc_ppc64le="powerpc64le-linux-gnu-gcc"}
66 : $(cross_cc_riscv64="riscv64-linux-gnu-gcc")
67 : ${cross_cc_s390x="s390x-linux-gnu-gcc"}
68 : $(cross_cc_sh4="sh4-linux-gnu-gcc")
69 : ${cross_cc_cflags_sparc="-m32 -mv8plus -mcpu=ultrasparc"}
70 : ${cross_cc_sparc64="sparc64-linux-gnu-gcc"}
71 : ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
72 : ${cross_cc_x86_64="x86_64-linux-gnu-gcc"}
73 : ${cross_cc_cflags_x86_64="-m64"}
74
75 # tricore is special as it doesn't have a compiler
76 : ${cross_as_tricore="tricore-as"}
77 : ${cross_ld_tricore="tricore-ld"}
78
79 for target in $target_list; do
80 arch=${target%%-*}
81
82 # reset all container fields
83 container_image=
84 container_hosts=
85 container_cross_cc=
86 container_cross_as=
87 container_cross_ld=
88
89 # suppress clang
90 supress_clang=
91
92 case $target in
93 aarch64-*)
94 # We don't have any bigendian build tools so we only use this for AArch64
95 container_hosts="x86_64 aarch64"
96 container_image=debian-arm64-test-cross
97 container_cross_cc=aarch64-linux-gnu-gcc-10
98 ;;
99 alpha-*)
100 container_hosts=x86_64
101 container_image=debian-alpha-cross
102 container_cross_cc=alpha-linux-gnu-gcc
103 ;;
104 arm-*)
105 # We don't have any bigendian build tools so we only use this for ARM
106 container_hosts="x86_64 aarch64"
107 container_image=debian-armhf-cross
108 container_cross_cc=arm-linux-gnueabihf-gcc
109 ;;
110 cris-*)
111 container_hosts=x86_64
112 container_image=fedora-cris-cross
113 container_cross_cc=cris-linux-gnu-gcc
114 ;;
115 hexagon-*)
116 container_hosts=x86_64
117 container_image=debian-hexagon-cross
118 container_cross_cc=hexagon-unknown-linux-musl-clang
119 ;;
120 hppa-*)
121 container_hosts=x86_64
122 container_image=debian-hppa-cross
123 container_cross_cc=hppa-linux-gnu-gcc
124 ;;
125 i386-*)
126 container_hosts=x86_64
127 container_image=fedora-i386-cross
128 container_cross_cc=gcc
129 supress_clang=yes
130 ;;
131 m68k-*)
132 container_hosts=x86_64
133 container_image=debian-m68k-cross
134 container_cross_cc=m68k-linux-gnu-gcc
135 ;;
136 mips64el-*)
137 container_hosts=x86_64
138 container_image=debian-mips64el-cross
139 container_cross_cc=mips64el-linux-gnuabi64-gcc
140 ;;
141 mips64-*)
142 container_hosts=x86_64
143 container_image=debian-mips64-cross
144 container_cross_cc=mips64-linux-gnuabi64-gcc
145 ;;
146 mipsel-*)
147 container_hosts=x86_64
148 container_image=debian-mipsel-cross
149 container_cross_cc=mipsel-linux-gnu-gcc
150 ;;
151 mips-*)
152 container_hosts=x86_64
153 container_image=debian-mips-cross
154 container_cross_cc=mips-linux-gnu-gcc
155 ;;
156 ppc-*|ppc64abi32-*)
157 container_hosts=x86_64
158 container_image=debian-powerpc-test-cross
159 container_cross_cc=powerpc-linux-gnu-gcc-10
160 ;;
161 ppc64-*|ppc64le-*)
162 container_hosts=x86_64
163 container_image=debian-powerpc-test-cross
164 container_cross_cc=${target%%-*}-linux-gnu-gcc-10
165 container_cross_cc=powerpc${container_cross_cc#ppc}
166 ;;
167 riscv64-*)
168 container_hosts=x86_64
169 container_image=debian-riscv64-cross
170 container_cross_cc=riscv64-linux-gnu-gcc
171 ;;
172 s390x-*)
173 container_hosts=x86_64
174 container_image=debian-s390x-cross
175 container_cross_cc=s390x-linux-gnu-gcc
176 ;;
177 sh4-*)
178 container_hosts=x86_64
179 container_image=debian-sh4-cross
180 container_cross_cc=sh4-linux-gnu-gcc
181 ;;
182 sparc64-*)
183 container_hosts=x86_64
184 container_image=debian-sparc64-cross
185 container_cross_cc=sparc64-linux-gnu-gcc
186 ;;
187 tricore-softmmu)
188 container_hosts=x86_64
189 container_image=debian-tricore-cross
190 container_cross_as=tricore-as
191 container_cross_ld=tricore-ld
192 ;;
193 x86_64-*)
194 container_hosts="aarch64 ppc64el x86_64"
195 container_image=debian-amd64-cross
196 container_cross_cc=x86_64-linux-gnu-gcc
197 supress_clang=yes
198 ;;
199 xtensa*-softmmu)
200 container_hosts=x86_64
201 container_image=debian-xtensa-cross
202
203 # default to the dc232b cpu
204 container_cross_cc=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-gcc
205 ;;
206 esac
207
208 config_target_mak=tests/tcg/config-$target.mak
209
210 echo "# Automatically generated by configure - do not modify" > $config_target_mak
211 echo "TARGET_NAME=$arch" >> $config_target_mak
212 echo "target=$target" >> $config_target_mak
213 case $target in
214 *-linux-user | *-bsd-user)
215 echo "CONFIG_USER_ONLY=y" >> $config_target_mak
216 echo "QEMU=$PWD/qemu-$arch" >> $config_target_mak
217 ;;
218 *-softmmu)
219 echo "CONFIG_SOFTMMU=y" >> $config_target_mak
220 echo "QEMU=$PWD/qemu-system-$arch" >> $config_target_mak
221 ;;
222 esac
223
224 eval "target_compiler_cflags=\${cross_cc_cflags_$arch}"
225 echo "CROSS_CC_GUEST_CFLAGS=$target_compiler_cflags" >> $config_target_mak
226
227 got_cross_cc=no
228
229 if eval test "x\"\${cross_cc_$arch}\"" != xyes; then
230 eval "target_compiler=\"\${cross_cc_$arch}\""
231
232 if has $target_compiler; then
233 if test "$supress_clang" = yes &&
234 $target_compiler --version | grep -qi "clang"; then
235 got_cross_cc=no
236 else
237 write_c_skeleton
238 if ! do_compiler "$target_compiler" $target_compiler_cflags \
239 -o $TMPE $TMPC -static ; then
240 # For host systems we might get away with building without -static
241 if do_compiler "$target_compiler" $target_compiler_cflags \
242 -o $TMPE $TMPC ; then
243 got_cross_cc=yes
244 echo "CROSS_CC_GUEST_STATIC=y" >> $config_target_mak
245 echo "CROSS_CC_GUEST=$target_compiler" >> $config_target_mak
246 fi
247 else
248 got_cross_cc=yes
249 echo "CROSS_CC_GUEST_STATIC=y" >> $config_target_mak
250 echo "CROSS_CC_GUEST=$target_compiler" >> $config_target_mak
251 fi
252 fi
253 fi
254
255 # Special handling for assembler only tests
256 eval "target_as=\"\${cross_as_$arch}\""
257 eval "target_ld=\"\${cross_ld_$arch}\""
258 if has $target_as && has $target_ld; then
259 case $target in
260 tricore-softmmu)
261 echo "CROSS_CC_GUEST=$target_as" >> $config_target_mak
262 echo "CROSS_AS_GUEST=$target_as" >> $config_target_mak
263 echo "CROSS_LD_GUEST=$target_ld" >> $config_target_mak
264 got_cross_cc=yes
265 ;;
266 esac
267 fi
268 fi
269
270 if test $got_cross_cc = yes; then
271 # Test for compiler features for optional tests. We only do this
272 # for cross compilers because ensuring the docker containers based
273 # compilers is a requirememt for adding a new test that needs a
274 # compiler feature.
275
276 case $target in
277 aarch64-*)
278 if do_compiler "$target_compiler" $target_compiler_cflags \
279 -march=armv8.1-a+sve -o $TMPE $TMPC; then
280 echo "CROSS_CC_HAS_SVE=y" >> $config_target_mak
281 fi
282 if do_compiler "$target_compiler" $target_compiler_cflags \
283 -march=armv8.3-a -o $TMPE $TMPC; then
284 echo "CROSS_CC_HAS_ARMV8_3=y" >> $config_target_mak
285 fi
286 if do_compiler "$target_compiler" $target_compiler_cflags \
287 -mbranch-protection=standard -o $TMPE $TMPC; then
288 echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak
289 fi
290 if do_compiler "$target_compiler" $target_compiler_cflags \
291 -march=armv8.5-a+memtag -o $TMPE $TMPC; then
292 echo "CROSS_CC_HAS_ARMV8_MTE=y" >> $config_target_mak
293 fi
294 ;;
295 ppc*)
296 if do_compiler "$target_compiler" $target_compiler_cflags \
297 -mpower8-vector -o $TMPE $TMPC; then
298 echo "CROSS_CC_HAS_POWER8_VECTOR=y" >> $config_target_mak
299 fi
300 if do_compiler "$target_compiler" $target_compiler_cflags \
301 -mpower10 -o $TMPE $TMPC; then
302 echo "CROSS_CC_HAS_POWER10=y" >> $config_target_mak
303 fi
304 ;;
305 i386-linux-user)
306 if do_compiler "$target_compiler" $target_compiler_cflags \
307 -Werror -fno-pie -o $TMPE $TMPC; then
308 echo "CROSS_CC_HAS_I386_NOPIE=y" >> $config_target_mak
309 fi
310 ;;
311 esac
312 elif test $got_cross_cc = no && test "$container" != no && \
313 test -n "$container_image"; then
314 for host in $container_hosts; do
315 if test "$host" = "$ARCH"; then
316 echo "DOCKER_IMAGE=$container_image" >> $config_target_mak
317 echo "DOCKER_CROSS_CC_GUEST=$container_cross_cc" >> \
318 $config_target_mak
319 if test -n "$container_cross_as"; then
320 echo "DOCKER_CROSS_AS_GUEST=$container_cross_as" >> \
321 $config_target_mak
322 fi
323 if test -n "$container_cross_ld"; then
324 echo "DOCKER_CROSS_LD_GUEST=$container_cross_ld" >> \
325 $config_target_mak
326 fi
327 fi
328 done
329 fi
330 done