blob: 9cdce69b7852181802d52fb71779de8cecfc1daf [file] [log] [blame]
bellard7d132992003-03-06 23:23:54 +00001#!/bin/sh
2#
bellard3ef693a2003-03-23 20:17:16 +00003# qemu configure script (c) 2003 Fabrice Bellard
bellard7d132992003-03-06 23:23:54 +00004#
Peter Maydell8cd05ab2014-05-23 17:07:24 +01005
Cornelia Huck99519e62014-05-28 12:39:17 +02006# Unset some variables known to interfere with behavior of common tools,
Paolo Bonzini5b507232023-05-25 17:46:07 +02007# just as autoconf does. Unlike autoconf, we assume that unset exists.
8unset CLICOLOR_FORCE GREP_OPTIONS BASH_ENV ENV MAIL MAILPATH CDPATH
Cornelia Huck99519e62014-05-28 12:39:17 +02009
John Snow5e4dfd32015-10-28 13:56:40 -040010# Don't allow CCACHE, if present, to use cached results of compile tests!
11export CCACHE_RECACHE=yes
12
Daniel P. Berrangédedad022020-08-21 12:22:04 +020013# make source path absolute
14source_path=$(cd "$(dirname -- "$0")"; pwd)
15
16if test "$PWD" = "$source_path"
17then
18 echo "Using './build' as the directory for build output"
19
20 MARKER=build/auto-created-by-configure
21
22 if test -e build
23 then
24 if test -f $MARKER
25 then
26 rm -rf build
27 else
28 echo "ERROR: ./build dir already exists and was not previously created by configure"
29 exit 1
30 fi
31 fi
32
Dinah Baumf160a5b2023-02-21 06:06:30 -050033 if ! mkdir build || ! touch $MARKER
34 then
35 echo "ERROR: Could not create ./build directory. Check the permissions on"
36 echo "your source directory, or try doing an out-of-tree build."
37 exit 1
38 fi
Daniel P. Berrangédedad022020-08-21 12:22:04 +020039
40 cat > GNUmakefile <<'EOF'
41# This file is auto-generated by configure to support in-source tree
42# 'make' command invocation
43
44ifeq ($(MAKECMDGOALS),)
45recurse: all
46endif
47
48.NOTPARALLEL: %
49%: force
50 @echo 'changing dir to build for $(MAKE) "$(MAKECMDGOALS)"...'
51 @$(MAKE) -C build -f Makefile $(MAKECMDGOALS)
52 @if test "$(MAKECMDGOALS)" = "distclean" && \
53 test -e build/auto-created-by-configure ; \
54 then \
55 rm -rf build GNUmakefile ; \
56 fi
57force: ;
58.PHONY: force
59GNUmakefile: ;
60
61EOF
62 cd build
Peter Maydell64708612022-08-25 16:06:59 +010063 exec "$source_path/configure" "$@"
Daniel P. Berrangédedad022020-08-21 12:22:04 +020064fi
65
Peter Maydell8cd05ab2014-05-23 17:07:24 +010066# Temporary directory used for files created while
67# configure runs. Since it is in the build directory
68# we can safely blow away any previous version of it
69# (and we need not jump through hoops to try to delete
70# it when configure exits.)
71TMPDIR1="config-temp"
72rm -rf "${TMPDIR1}"
Peter Maydell563661c2022-08-25 16:07:02 +010073if ! mkdir -p "${TMPDIR1}"; then
Peter Maydell8cd05ab2014-05-23 17:07:24 +010074 echo "ERROR: failed to create temporary directory"
75 exit 1
bellard7d132992003-03-06 23:23:54 +000076fi
77
Peter Maydell8cd05ab2014-05-23 17:07:24 +010078TMPB="qemu-conf"
79TMPC="${TMPDIR1}/${TMPB}.c"
Don Slutz66518bf2014-01-02 21:12:46 -050080TMPO="${TMPDIR1}/${TMPB}.o"
Peter Maydell8cd05ab2014-05-23 17:07:24 +010081TMPE="${TMPDIR1}/${TMPB}.exe"
bellard7d132992003-03-06 23:23:54 +000082
Gerd Hoffmannda1d85e2010-04-23 13:44:10 +020083rm -f config.log
malc9ac81bb2008-11-29 20:09:56 +000084
Peter Maydellb48e3612011-11-23 17:26:44 +000085# Print a helpful header at the top of config.log
86echo "# QEMU configure log $(date)" >> config.log
Peter Maydell979ae162012-03-07 12:16:29 +000087printf "# Configured with:" >> config.log
Alex Bennée7f788772022-12-21 09:04:08 +000088# repeat the invocation to log and stdout for CI
89invoke=$(printf " '%s'" "$0" "$@")
90test -n "$GITLAB_CI" && echo "configuring with: $invoke"
91{ echo "$invoke"; echo; echo "#"; } >> config.log
Peter Maydellb48e3612011-11-23 17:26:44 +000092
Paolo Bonzini835af892020-09-08 13:20:45 +020093quote_sh() {
94 printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
95}
96
Paolo Bonzinid880a3b2017-07-03 16:58:28 +020097print_error() {
98 (echo
Peter Maydell76ad07a2013-04-08 12:11:26 +010099 echo "ERROR: $1"
100 while test -n "$2"; do
101 echo " $2"
102 shift
103 done
Paolo Bonzinid880a3b2017-07-03 16:58:28 +0200104 echo) >&2
105}
106
107error_exit() {
108 print_error "$@"
Peter Maydell76ad07a2013-04-08 12:11:26 +0100109 exit 1
110}
111
Peter Maydell9c83ffd2014-02-25 18:27:49 +0000112do_compiler() {
Paolo Bonzinicd362de2022-05-27 16:35:48 +0100113 # Run the compiler, capturing its output to the log. First argument
114 # is compiler binary to execute.
Peter Maydellb3b54722022-08-25 16:07:03 +0100115 compiler="$1"
Paolo Bonzinicd362de2022-05-27 16:35:48 +0100116 shift
117 if test -n "$BASH_VERSION"; then eval '
118 echo >>config.log "
119funcs: ${FUNCNAME[*]}
120lines: ${BASH_LINENO[*]}"
121 '; fi
122 echo $compiler "$@" >> config.log
123 $compiler "$@" >> config.log 2>&1 || return $?
124}
125
Peter Maydell9c83ffd2014-02-25 18:27:49 +0000126do_cc() {
Paolo Bonzinid0016b82022-10-18 09:38:44 +0200127 do_compiler "$cc" $CPU_CFLAGS "$@"
Peter Maydell9c83ffd2014-02-25 18:27:49 +0000128}
129
Juan Quintela52166aa2009-08-03 14:46:03 +0200130compile_object() {
John Snowfd0e6052015-03-25 18:57:39 -0400131 local_cflags="$1"
Paolo Bonzinia988b4c2022-10-20 14:20:30 +0200132 do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -c -o $TMPO $TMPC
Juan Quintela52166aa2009-08-03 14:46:03 +0200133}
134
135compile_prog() {
136 local_cflags="$1"
137 local_ldflags="$2"
Paolo Bonzinia988b4c2022-10-20 14:20:30 +0200138 do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -o $TMPE $TMPC \
139 $LDFLAGS $EXTRA_LDFLAGS $local_ldflags
Juan Quintela52166aa2009-08-03 14:46:03 +0200140}
141
Paolo Bonzini11568d62010-12-23 11:43:58 +0100142# symbolically link $1 to $2. Portable version of "ln -sf".
143symlink() {
Stefan Weil72b8b5a2012-03-19 13:20:47 +0100144 rm -rf "$2"
Anthony Liguoriec5b06d2012-06-06 16:57:00 +0800145 mkdir -p "$(dirname "$2")"
Stefan Weil72b8b5a2012-03-19 13:20:47 +0100146 ln -s "$1" "$2"
Paolo Bonzini11568d62010-12-23 11:43:58 +0100147}
148
Loïc Minier0dba6192010-01-28 21:26:51 +0000149# check whether a command is available to this shell (may be either an
150# executable or a builtin)
151has() {
152 type "$1" >/dev/null 2>&1
153}
154
Marc-André Lureau0a01d762019-08-21 11:21:16 +0400155version_ge () {
Alex Bennée2df52b92021-02-02 13:39:52 +0000156 local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
157 local_ver2=$(echo "$2" | tr . ' ')
Marc-André Lureau0a01d762019-08-21 11:21:16 +0400158 while true; do
159 set x $local_ver1
160 local_first=${2-0}
Stefano Garzarellac44a33e2020-08-21 22:35:58 +0200161 # 'shift 2' if $2 is set, or 'shift' if $2 is not set
162 shift ${2:+2}
Marc-André Lureau0a01d762019-08-21 11:21:16 +0400163 local_ver1=$*
164 set x $local_ver2
165 # the second argument finished, the first must be greater or equal
166 test $# = 1 && return 0
167 test $local_first -lt $2 && return 1
168 test $local_first -gt $2 && return 0
Stefano Garzarellac44a33e2020-08-21 22:35:58 +0200169 shift ${2:+2}
Marc-André Lureau0a01d762019-08-21 11:21:16 +0400170 local_ver2=$*
171 done
172}
173
Antonio Ospite4ace32e2019-05-26 16:47:47 +0200174if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
175then
176 error_exit "main directory cannot contain spaces nor colons"
177fi
178
Paolo Bonzini13cf3762023-05-11 09:34:13 +0200179# parse CC options first; some compiler tests are used to establish
180# some defaults, based on the host environment
181
Antonio Ospite14211822019-05-26 16:47:46 +0200182# default parameters
Juan Quintela2ff6b912009-08-03 14:45:55 +0200183cpu=""
Joelle van Dyne3812c0c2021-01-25 17:24:48 -0800184cross_compile="no"
bellard7d132992003-03-06 23:23:54 +0000185cross_prefix=""
Peter Maydelle49d0212012-12-07 15:39:13 +0000186host_cc="cc"
Paolo Bonzini13cf3762023-05-11 09:34:13 +0200187EXTRA_CFLAGS=""
188EXTRA_CXXFLAGS=""
189EXTRA_OBJCFLAGS=""
190EXTRA_LDFLAGS=""
Paolo Bonzini377529c2010-12-23 11:43:50 +0100191
192# Default value for a variable defining feature "foo".
193# * foo="no" feature will only be used if --enable-foo arg is given
194# * foo="" feature will be searched for, and if found, will be used
195# unless --disable-foo is given
196# * foo="yes" this value will only be set by --enable-foo flag.
197# feature will searched for,
198# if not found, configure exits with error
199#
200# Always add --enable-foo and --disable-foo command line args.
201# Distributions want to ensure that several features are compiled in, and it
202# is impossible without a --enable-foo that exits if a feature is not found.
Alex Bennéec87ea112020-12-10 19:04:13 +0000203default_feature=""
Alex Bennéec87ea112020-12-10 19:04:13 +0000204
aliguoriac0df512008-12-29 17:14:15 +0000205for opt do
Stefan Weil89138852016-05-16 15:10:20 +0200206 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
aliguoriac0df512008-12-29 17:14:15 +0000207 case "$opt" in
208 --cross-prefix=*) cross_prefix="$optarg"
Joelle van Dyne3812c0c2021-01-25 17:24:48 -0800209 cross_compile="yes"
aliguoriac0df512008-12-29 17:14:15 +0000210 ;;
Paolo Bonzini3d8df642010-12-23 11:43:48 +0100211 --cc=*) CC="$optarg"
aliguoriac0df512008-12-29 17:14:15 +0000212 ;;
Tomoki Sekiyama83f73fc2013-08-07 11:39:36 -0400213 --cxx=*) CXX="$optarg"
214 ;;
Peter Maydellc0c34c92023-04-18 17:15:54 +0100215 --objcc=*) objcc="$optarg"
216 ;;
Juan Quintela2ff6b912009-08-03 14:45:55 +0200217 --cpu=*) cpu="$optarg"
218 ;;
Paolo Bonzinia2866662021-11-05 10:09:26 +0100219 --extra-cflags=*)
220 EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
221 EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
Philippe Mathieu-Daudée910c7d2022-01-08 22:38:55 +0100222 EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
Paolo Bonzinia2866662021-11-05 10:09:26 +0100223 ;;
224 --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
Juan Quintelae2a2ed02009-08-03 14:46:02 +0200225 ;;
Philippe Mathieu-Daudée910c7d2022-01-08 22:38:55 +0100226 --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
227 ;;
Paolo Bonzinia2866662021-11-05 10:09:26 +0100228 --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
Juan Quintelae2a2ed02009-08-03 14:46:02 +0200229 ;;
Alex Bennéed75402b2018-04-04 20:27:05 +0100230 --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
231 ;;
Matheus Ferst479ca4c2022-01-20 14:31:41 -0300232 --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
Alex Bennéed422b2b2018-04-13 11:07:58 +0100233 eval "cross_cc_cflags_${cc_arch}=\$optarg"
234 ;;
Alex Bennéed75402b2018-04-04 20:27:05 +0100235 --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
236 eval "cross_cc_${cc_arch}=\$optarg"
237 ;;
Paolo Bonzini5adb43b2022-05-27 16:35:51 +0100238 --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-prefix-FOO option"
239 ;;
240 --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
241 eval "cross_prefix_${cc_arch}=\$optarg"
242 ;;
Paolo Bonzini13cf3762023-05-11 09:34:13 +0200243 --without-default-features) default_feature="no"
244 ;;
aliguoriac0df512008-12-29 17:14:15 +0000245 esac
246done
aliguoriac0df512008-12-29 17:14:15 +0000247
Paolo Bonzini13cf3762023-05-11 09:34:13 +0200248
249if test -e "$source_path/.git"
250then
251 git_submodules_action="update"
252else
253 git_submodules_action="ignore"
254fi
255
256git_submodules="ui/keycodemapdb"
257git="git"
258debug_tcg="no"
259docs="auto"
260EXESUF=""
261prefix="/usr/local"
262qemu_suffix="qemu"
263softmmu="yes"
264linux_user=""
265bsd_user=""
266plugins="$default_feature"
267ninja=""
268python=
269pypi="enabled"
270bindir="bin"
271skip_meson=no
272vfio_user_server="disabled"
273use_containers="yes"
274gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
275gdb_arches=""
276werror=""
277
278# Don't accept a target_list environment variable.
279unset target_list
280unset target_list_exclude
281
282# The following Meson options are handled manually (still they
283# are included in the automatically generated help message)
284
285# 1. Track which submodules are needed
286fdt="auto"
287
288# 2. Automatically enable/disable other options
289tcg="auto"
290cfi="false"
291
292# 3. Need to check for -static-pie before Meson runs. Also,
293# Meson has PIE as a boolean rather than enabled/disabled/auto.
294pie=""
295static="no"
296
Peter Maydelle49d0212012-12-07 15:39:13 +0000297# Preferred compiler:
298# ${CC} (if set)
299# ${cross_prefix}gcc (if cross-prefix specified)
300# system compiler
301if test -z "${CC}${cross_prefix}"; then
302 cc="$host_cc"
303else
304 cc="${CC-${cross_prefix}gcc}"
305fi
306
Tomoki Sekiyama83f73fc2013-08-07 11:39:36 -0400307if test -z "${CXX}${cross_prefix}"; then
308 cxx="c++"
309else
310 cxx="${CXX-${cross_prefix}g++}"
311fi
312
Peter Maydellc0c34c92023-04-18 17:15:54 +0100313# Preferred ObjC compiler:
314# $objcc (if set, i.e. via --objcc option)
315# ${cross_prefix}clang (if cross-prefix specified)
316# clang (if available)
317# $cc
318if test -z "${objcc}${cross_prefix}"; then
319 if has clang; then
320 objcc=clang
321 else
322 objcc="$cc"
323 fi
324else
325 objcc="${objcc-${cross_prefix}clang}"
326fi
327
Stuart Yoderb3198cc2011-08-04 17:10:08 -0500328ar="${AR-${cross_prefix}ar}"
Richard Hendersoncdbd7272016-07-07 21:49:36 -0700329as="${AS-${cross_prefix}as}"
Richard Henderson5f6f0e22016-06-23 10:39:18 -0700330ccas="${CCAS-$cc}"
Stuart Yoderb3198cc2011-08-04 17:10:08 -0500331objcopy="${OBJCOPY-${cross_prefix}objcopy}"
332ld="${LD-${cross_prefix}ld}"
Alistair Francis9f81aeb2017-11-07 17:10:46 -0800333ranlib="${RANLIB-${cross_prefix}ranlib}"
Stefan Weil4852ee92014-09-18 21:55:08 +0200334nm="${NM-${cross_prefix}nm}"
Paolo Bonzini35acbb32021-10-13 13:43:36 +0200335smbd="$SMBD"
Stuart Yoderb3198cc2011-08-04 17:10:08 -0500336strip="${STRIP-${cross_prefix}strip}"
Konstantin Kostiuk158bb222022-04-28 21:15:25 +0300337widl="${WIDL-${cross_prefix}widl}"
Stuart Yoderb3198cc2011-08-04 17:10:08 -0500338windres="${WINDRES-${cross_prefix}windres}"
Andrey Drobyshevf9f0e612022-11-29 19:38:08 +0200339windmc="${WINDMC-${cross_prefix}windmc}"
Paolo Bonzini877c5562022-10-12 13:03:18 +0200340pkg_config="${PKG_CONFIG-${cross_prefix}pkg-config}"
Dave Airlie47c03742013-12-10 14:05:51 +1000341sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
aliguoriac0df512008-12-29 17:14:15 +0000342
aliguoriac0df512008-12-29 17:14:15 +0000343check_define() {
344cat > $TMPC <<EOF
345#if !defined($1)
Peter Maydellfd786e12011-11-23 17:26:43 +0000346#error $1 not defined
aliguoriac0df512008-12-29 17:14:15 +0000347#endif
348int main(void) { return 0; }
349EOF
Juan Quintela52166aa2009-08-03 14:46:03 +0200350 compile_object
aliguoriac0df512008-12-29 17:14:15 +0000351}
352
John Snow93b25862015-03-25 18:57:37 -0400353write_c_skeleton() {
354 cat > $TMPC <<EOF
355int main(void) { return 0; }
356EOF
357}
358
Peter Maydellbbea4052012-08-14 15:35:34 +0100359if check_define __linux__ ; then
Paolo Bonziniba7c60c2021-11-08 14:47:54 +0100360 targetos=linux
Peter Maydellbbea4052012-08-14 15:35:34 +0100361elif check_define _WIN32 ; then
Paolo Bonziniba7c60c2021-11-08 14:47:54 +0100362 targetos=windows
Peter Maydellbbea4052012-08-14 15:35:34 +0100363elif check_define __OpenBSD__ ; then
Paolo Bonziniba7c60c2021-11-08 14:47:54 +0100364 targetos=openbsd
Peter Maydellbbea4052012-08-14 15:35:34 +0100365elif check_define __sun__ ; then
Paolo Bonziniba7c60c2021-11-08 14:47:54 +0100366 targetos=sunos
Peter Maydellbbea4052012-08-14 15:35:34 +0100367elif check_define __HAIKU__ ; then
Paolo Bonziniba7c60c2021-11-08 14:47:54 +0100368 targetos=haiku
Peter Maydell951fedf2017-07-13 16:15:32 +0100369elif check_define __FreeBSD__ ; then
Paolo Bonziniba7c60c2021-11-08 14:47:54 +0100370 targetos=freebsd
Peter Maydell951fedf2017-07-13 16:15:32 +0100371elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
Paolo Bonziniba7c60c2021-11-08 14:47:54 +0100372 targetos=gnu/kfreebsd
Peter Maydell951fedf2017-07-13 16:15:32 +0100373elif check_define __DragonFly__ ; then
Paolo Bonziniba7c60c2021-11-08 14:47:54 +0100374 targetos=dragonfly
Peter Maydell951fedf2017-07-13 16:15:32 +0100375elif check_define __NetBSD__; then
Paolo Bonziniba7c60c2021-11-08 14:47:54 +0100376 targetos=netbsd
Peter Maydell951fedf2017-07-13 16:15:32 +0100377elif check_define __APPLE__; then
Paolo Bonziniba7c60c2021-11-08 14:47:54 +0100378 targetos=darwin
Peter Maydellbbea4052012-08-14 15:35:34 +0100379else
Peter Maydell951fedf2017-07-13 16:15:32 +0100380 # This is a fatal error, but don't report it yet, because we
381 # might be going to just print the --help text, or it might
382 # be the result of a missing compiler.
Paolo Bonziniba7c60c2021-11-08 14:47:54 +0100383 targetos=bogus
Peter Maydellbbea4052012-08-14 15:35:34 +0100384fi
385
Paolo Bonzini65eff012021-11-08 22:52:35 +0100386# OS specific
387
Paolo Bonzini3b0d8642021-10-13 14:14:53 +0200388mingw32="no"
389bsd="no"
390linux="no"
391solaris="no"
Peter Maydellbbea4052012-08-14 15:35:34 +0100392case $targetos in
Paolo Bonzini65eff012021-11-08 22:52:35 +0100393windows)
394 mingw32="yes"
395 plugins="no"
396 pie="no"
397;;
398gnu/kfreebsd)
399 bsd="yes"
400;;
401freebsd)
402 bsd="yes"
Paolo Bonzini65eff012021-11-08 22:52:35 +0100403 make="${MAKE-gmake}"
404 # needed for kinfo_getvmmap(3) in libutil.h
405;;
406dragonfly)
407 bsd="yes"
408 make="${MAKE-gmake}"
409;;
410netbsd)
411 bsd="yes"
412 make="${MAKE-gmake}"
413;;
414openbsd)
415 bsd="yes"
416 make="${MAKE-gmake}"
417;;
418darwin)
419 bsd="yes"
420 darwin="yes"
Paolo Bonzini65eff012021-11-08 22:52:35 +0100421;;
Paolo Bonziniba7c60c2021-11-08 14:47:54 +0100422sunos)
Paolo Bonzini65eff012021-11-08 22:52:35 +0100423 solaris="yes"
424 make="${MAKE-gmake}"
Paolo Bonzini65eff012021-11-08 22:52:35 +0100425;;
426haiku)
427 pie="no"
Paolo Bonzini65eff012021-11-08 22:52:35 +0100428;;
429linux)
430 linux="yes"
Paolo Bonzini65eff012021-11-08 22:52:35 +0100431;;
Peter Maydellbbea4052012-08-14 15:35:34 +0100432esac
433
Juan Quintela2ff6b912009-08-03 14:45:55 +0200434if test ! -z "$cpu" ; then
435 # command line argument
436 :
437elif check_define __i386__ ; then
aliguoriac0df512008-12-29 17:14:15 +0000438 cpu="i386"
439elif check_define __x86_64__ ; then
Richard Hendersonc72b26e2013-08-20 12:20:05 -0700440 if check_define __ILP32__ ; then
441 cpu="x32"
442 else
443 cpu="x86_64"
444 fi
blueswir13aa9bd62008-12-31 16:55:26 +0000445elif check_define __sparc__ ; then
blueswir13aa9bd62008-12-31 16:55:26 +0000446 if check_define __arch64__ ; then
447 cpu="sparc64"
448 else
449 cpu="sparc"
450 fi
malcfdf7ed92009-01-14 18:39:52 +0000451elif check_define _ARCH_PPC ; then
452 if check_define _ARCH_PPC64 ; then
Richard Hendersonf8378ac2019-05-01 15:38:18 -0700453 if check_define _LITTLE_ENDIAN ; then
454 cpu="ppc64le"
455 else
456 cpu="ppc64"
457 fi
malcfdf7ed92009-01-14 18:39:52 +0000458 else
459 cpu="ppc"
460 fi
Aurelien Jarnoafa05232009-10-17 14:17:47 +0200461elif check_define __mips__ ; then
462 cpu="mips"
Aurelien Jarnod66ed0e2010-06-13 12:28:21 +0200463elif check_define __s390__ ; then
464 if check_define __s390x__ ; then
465 cpu="s390x"
466 else
467 cpu="s390"
468 fi
Alistair Francisc4f80542018-12-19 19:20:19 +0000469elif check_define __riscv ; then
Richard Hendersonba0e7332021-09-17 11:08:09 -0700470 cpu="riscv"
Peter Maydell21d89f82011-11-30 10:57:48 +0100471elif check_define __arm__ ; then
472 cpu="arm"
Claudio Fontana1f080312013-06-12 16:20:23 +0100473elif check_define __aarch64__ ; then
474 cpu="aarch64"
WANG Xueruidfcf9002021-12-21 13:41:04 +0800475elif check_define __loongarch64 ; then
476 cpu="loongarch64"
aliguoriac0df512008-12-29 17:14:15 +0000477else
Paolo Bonzinif9c77802022-10-12 15:27:03 +0200478 # Using uname is really broken, but it is just a fallback for architectures
479 # that are going to use TCI anyway
Stefan Weil89138852016-05-16 15:10:20 +0200480 cpu=$(uname -m)
Paolo Bonzinif9c77802022-10-12 15:27:03 +0200481 echo "WARNING: unrecognized host CPU, proceeding with 'uname -m' output '$cpu'"
aliguoriac0df512008-12-29 17:14:15 +0000482fi
483
Paolo Bonzinif9c77802022-10-12 15:27:03 +0200484# Normalise host CPU name and set multilib cflags. The canonicalization
485# isn't really necessary, because the architectures that we check for
486# should not hit the 'uname -m' case, but better safe than sorry.
Peter Maydell359bc952011-12-24 13:07:25 +0000487# Note that this case should only have supported host CPUs, not guests.
bellard7d132992003-03-06 23:23:54 +0000488case "$cpu" in
Paolo Bonzinie4da0e32021-11-09 09:23:56 +0100489 armv*b|armv*l|arm)
490 cpu="arm" ;;
491
Paolo Bonzinif9c77802022-10-12 15:27:03 +0200492 i386|i486|i586|i686)
bellard97a847b2003-08-10 21:36:04 +0000493 cpu="i386"
Paolo Bonzinie4da0e32021-11-09 09:23:56 +0100494 CPU_CFLAGS="-m32" ;;
495 x32)
Paolo Bonzini4da270b2021-11-09 09:36:10 +0100496 cpu="x86_64"
Paolo Bonzinie4da0e32021-11-09 09:23:56 +0100497 CPU_CFLAGS="-mx32" ;;
aurel32aaa5fa12008-04-11 22:04:22 +0000498 x86_64|amd64)
499 cpu="x86_64"
Paolo Bonzinie4da0e32021-11-09 09:23:56 +0100500 # ??? Only extremely old AMD cpus do not have cmpxchg16b.
501 # If we truly care, we should simply detect this case at
502 # runtime and generate the fallback to serial emulation.
503 CPU_CFLAGS="-m64 -mcx16" ;;
504
Aurelien Jarnoafa05232009-10-17 14:17:47 +0200505 mips*)
Paolo Bonzinie4da0e32021-11-09 09:23:56 +0100506 cpu="mips" ;;
507
508 ppc)
509 CPU_CFLAGS="-m32" ;;
510 ppc64)
Miroslav Rezaninaced5cff2022-03-05 07:16:46 +0100511 CPU_CFLAGS="-m64 -mbig-endian" ;;
Paolo Bonzinie4da0e32021-11-09 09:23:56 +0100512 ppc64le)
Paolo Bonzinid8ff8922021-11-09 09:18:20 +0100513 cpu="ppc64"
Miroslav Rezaninaced5cff2022-03-05 07:16:46 +0100514 CPU_CFLAGS="-m64 -mlittle-endian" ;;
Paolo Bonzinie4da0e32021-11-09 09:23:56 +0100515
516 s390)
Paolo Bonzini823eb012021-11-08 14:18:17 +0100517 CPU_CFLAGS="-m31" ;;
Paolo Bonzinie4da0e32021-11-09 09:23:56 +0100518 s390x)
519 CPU_CFLAGS="-m64" ;;
520
blueswir131422552007-04-16 18:27:06 +0000521 sparc|sun4[cdmuv])
bellardae228532003-05-13 18:59:59 +0000522 cpu="sparc"
Paolo Bonzinie4da0e32021-11-09 09:23:56 +0100523 CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
524 sparc64)
525 CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
bellard7d132992003-03-06 23:23:54 +0000526esac
Juan Quintelae2d52ad2009-08-12 18:20:24 +0200527
Paolo Bonzini0db4a062010-12-23 11:43:49 +0100528: ${make=${MAKE-make}}
Paolo Bonzinib6daf4d2020-09-01 06:38:04 -0400529
Markus Armbruster903458c2020-02-14 18:18:41 +0100530
John Snowfee6d412023-02-10 01:31:43 +0100531check_py_version() {
Paolo Bonzini5591b742023-05-10 23:54:31 -0400532 # We require python >= 3.7.
John Snowfee6d412023-02-10 01:31:43 +0100533 # NB: a True python conditional creates a non-zero return code (Failure)
Paolo Bonzini5591b742023-05-10 23:54:31 -0400534 "$1" -c 'import sys; sys.exit(sys.version_info < (3,7))'
John Snowfee6d412023-02-10 01:31:43 +0100535}
536
John Snowfee6d412023-02-10 01:31:43 +0100537first_python=
538if test -z "${PYTHON}"; then
John Snowfee6d412023-02-10 01:31:43 +0100539 # A bare 'python' is traditionally python 2.x, but some distros
540 # have it as python 3.x, so check in both places.
Paolo Bonzini5591b742023-05-10 23:54:31 -0400541 for binary in python3 python python3.11 python3.10 python3.9 python3.8 python3.7; do
John Snowfee6d412023-02-10 01:31:43 +0100542 if has "$binary"; then
543 python=$(command -v "$binary")
544 if check_py_version "$python"; then
545 # This one is good.
546 first_python=
547 break
548 else
549 first_python=$python
550 fi
551 fi
552 done
553else
554 # Same as above, but only check the environment variable.
555 has "${PYTHON}" || error_exit "The PYTHON environment variable does not point to an executable"
556 python=$(command -v "$PYTHON")
John Snowfee6d412023-02-10 01:31:43 +0100557 if check_py_version "$python"; then
558 # This one is good.
559 first_python=
560 else
561 first_python=$first_python
562 fi
563fi
Markus Armbruster903458c2020-02-14 18:18:41 +0100564
Alex Bennée39d87c82020-03-03 15:06:20 +0000565# Check for ancillary tools used in testing
566genisoimage=
Alex Bennée3df437c2020-05-19 09:22:48 -0400567for binary in genisoimage mkisofs
Alex Bennée39d87c82020-03-03 15:06:20 +0000568do
569 if has $binary
570 then
571 genisoimage=$(command -v "$binary")
572 break
573 fi
574done
575
Juan Quintela3457a3f2009-08-03 14:46:07 +0200576if test "$mingw32" = "yes" ; then
Juan Quintela3457a3f2009-08-03 14:46:07 +0200577 EXESUF=".exe"
Paolo Bonzinid17f3052020-08-18 12:17:01 +0200578 prefix="/qemu"
Paolo Bonzinic09c1ce2022-04-20 17:33:57 +0200579 bindir=""
Marc-André Lureau77433a52020-08-26 15:04:12 +0400580 qemu_suffix=""
Juan Quintela3457a3f2009-08-03 14:46:07 +0200581fi
582
Akihiko Odaki8154f5e2022-06-25 00:40:42 +0900583meson_option_build_array() {
584 printf '['
Peter Maydellc5cfdab2022-07-20 16:26:31 +0100585 (if test "$targetos" = windows; then
Akihiko Odaki8154f5e2022-06-25 00:40:42 +0900586 IFS=\;
587 else
588 IFS=:
589 fi
590 for e in $1; do
Peter Maydell65842b02022-07-20 16:26:29 +0100591 printf '"""'
592 # backslash escape any '\' and '"' characters
593 printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g'
594 printf '""",'
Akihiko Odaki8154f5e2022-06-25 00:40:42 +0900595 done)
596 printf ']\n'
597}
598
Peter Maydell64708612022-08-25 16:06:59 +0100599. "$source_path/scripts/meson-buildoptions.sh"
Paolo Bonzini61d63092021-10-07 15:08:28 +0200600
601meson_options=
Paolo Bonzinic54b59e2022-04-20 17:33:58 +0200602meson_option_add() {
603 meson_options="$meson_options $(quote_sh "$1")"
604}
Paolo Bonzini61d63092021-10-07 15:08:28 +0200605meson_option_parse() {
606 meson_options="$meson_options $(_meson_option_parse "$@")"
607 if test $? -eq 1; then
608 echo "ERROR: unknown option $1"
609 echo "Try '$0 --help' for more information"
610 exit 1
611 fi
612}
613
bellard7d132992003-03-06 23:23:54 +0000614for opt do
Stefan Weil89138852016-05-16 15:10:20 +0200615 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
bellard7d132992003-03-06 23:23:54 +0000616 case "$opt" in
bellard2efc3262005-12-18 19:14:49 +0000617 --help|-h) show_help=yes
618 ;;
Peter Maydell64708612022-08-25 16:06:59 +0100619 --version|-V) exec cat "$source_path/VERSION"
Mike Frysinger99123e12011-04-07 01:12:28 -0400620 ;;
pbrookb1a550a2006-04-16 13:28:56 +0000621 --prefix=*) prefix="$optarg"
bellard7d132992003-03-06 23:23:54 +0000622 ;;
aliguoriac0df512008-12-29 17:14:15 +0000623 --cross-prefix=*)
bellard7d132992003-03-06 23:23:54 +0000624 ;;
aliguoriac0df512008-12-29 17:14:15 +0000625 --cc=*)
bellard7d132992003-03-06 23:23:54 +0000626 ;;
pbrookb1a550a2006-04-16 13:28:56 +0000627 --host-cc=*) host_cc="$optarg"
bellard83469012005-07-23 14:27:54 +0000628 ;;
Tomoki Sekiyama83f73fc2013-08-07 11:39:36 -0400629 --cxx=*)
630 ;;
Peter Maydellc0c34c92023-04-18 17:15:54 +0100631 --objcc=*)
Peter Maydell3c4a4d02012-08-11 22:34:40 +0100632 ;;
pbrookb1a550a2006-04-16 13:28:56 +0000633 --make=*) make="$optarg"
bellard7d132992003-03-06 23:23:54 +0000634 ;;
Paolo Bonzinib6daf4d2020-09-01 06:38:04 -0400635 --install=*)
pbrook6a882642006-04-17 13:57:12 +0000636 ;;
John Snow81e2b192023-05-10 23:54:23 -0400637 --python=*) python="$optarg"
Blue Swirlc886edf2011-07-22 21:08:09 +0000638 ;;
Paolo Bonzinia5665052019-06-10 12:05:14 +0200639 --skip-meson) skip_meson=yes
640 ;;
Paolo Bonzini48328882020-08-26 08:04:15 +0200641 --ninja=*) ninja="$optarg"
642 ;;
Brade2d88302011-09-02 16:53:28 -0400643 --smbd=*) smbd="$optarg"
644 ;;
Juan Quintelae2a2ed02009-08-03 14:46:02 +0200645 --extra-cflags=*)
bellard7d132992003-03-06 23:23:54 +0000646 ;;
Bruno Dominguez11cde1c2017-06-06 14:07:47 +0100647 --extra-cxxflags=*)
648 ;;
Philippe Mathieu-Daudée910c7d2022-01-08 22:38:55 +0100649 --extra-objcflags=*)
650 ;;
Juan Quintelae2a2ed02009-08-03 14:46:02 +0200651 --extra-ldflags=*)
bellard7d132992003-03-06 23:23:54 +0000652 ;;
Alex Bennéed75402b2018-04-04 20:27:05 +0100653 --cross-cc-*)
654 ;;
Paolo Bonzini5adb43b2022-05-27 16:35:51 +0100655 --cross-prefix-*)
656 ;;
John Snow6b0cedc2023-05-10 23:54:28 -0400657 --enable-docs) docs=enabled
658 ;;
659 --disable-docs) docs=disabled
660 ;;
Juan Quintela2ff6b912009-08-03 14:45:55 +0200661 --cpu=*)
bellard7d132992003-03-06 23:23:54 +0000662 ;;
pbrookb1a550a2006-04-16 13:28:56 +0000663 --target-list=*) target_list="$optarg"
Alex Bennée447e1332019-03-19 11:59:12 +0000664 if test "$target_list_exclude"; then
665 error_exit "Can't mix --target-list with --target-list-exclude"
666 fi
667 ;;
668 --target-list-exclude=*) target_list_exclude="$optarg"
669 if test "$target_list"; then
670 error_exit "Can't mix --target-list-exclude with --target-list"
671 fi
bellardde83cd02003-06-15 20:25:43 +0000672 ;;
Paolo Bonzinic54b59e2022-04-20 17:33:58 +0200673 --with-default-devices) meson_option_add -Ddefault_devices=true
Paolo Bonzinif3494742019-01-23 14:56:17 +0800674 ;;
Paolo Bonzinic54b59e2022-04-20 17:33:58 +0200675 --without-default-devices) meson_option_add -Ddefault_devices=false
Paolo Bonzinif3494742019-01-23 14:56:17 +0800676 ;;
Alex Bennéed1d5e9e2021-07-07 14:17:44 +0100677 --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
678 ;;
679 --with-devices-*) device_arch=${opt#--with-devices-};
680 device_arch=${device_arch%%=*}
681 cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
682 if test -f "$cf"; then
683 device_archs="$device_archs $device_arch"
684 eval "devices_${device_arch}=\$optarg"
685 else
686 error_exit "File $cf does not exist"
687 fi
688 ;;
Alex Bennéec87ea112020-12-10 19:04:13 +0000689 --without-default-features) # processed above
690 ;;
Paolo Bonzini877c5562022-10-12 13:03:18 +0200691 --static) static="yes"
bellard43ce4df2003-06-09 19:53:12 +0000692 ;;
Paolo Bonzini0b24e752010-05-26 16:08:26 +0200693 --bindir=*) bindir="$optarg"
694 ;;
Marc-André Lureau77433a52020-08-26 15:04:12 +0400695 --with-suffix=*) qemu_suffix="$optarg"
Eduardo Habkost023d3d62012-04-18 16:55:50 -0300696 ;;
Olaf Hering181ce1d2018-04-18 09:50:44 +0200697 --host=*|--build=*|\
698 --disable-dependency-tracking|\
Luiz Capitulino785c23a2012-10-03 18:35:57 -0300699 --sbindir=*|--sharedstatedir=*|\
Paolo Bonzinife0038b2020-10-16 04:35:10 -0400700 --oldincludedir=*|--datarootdir=*|--infodir=*|\
Max Filippov023ddd72011-11-24 16:11:31 +0400701 --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
702 # These switches are silently ignored, for compatibility with
703 # autoconf-generated configure scripts. This allows QEMU's
704 # configure to be used by RPM and similar macros that set
705 # lots of directory switches by default.
706 ;;
aurel32f8393942009-04-13 18:45:38 +0000707 --enable-debug-tcg) debug_tcg="yes"
708 ;;
709 --disable-debug-tcg) debug_tcg="no"
710 ;;
Paul Brookf3d08ee2009-06-04 11:39:04 +0100711 --enable-debug)
712 # Enable debugging options that aren't excessively noisy
713 debug_tcg="yes"
Stefan Hajnoczi58a2e3f2023-05-01 13:34:43 -0400714 meson_option_parse --enable-debug-graph-lock ""
Paolo Bonzinic55cf6a2021-10-13 11:46:09 +0200715 meson_option_parse --enable-debug-mutex ""
Paolo Bonzinic54b59e2022-04-20 17:33:58 +0200716 meson_option_add -Doptimization=0
Lingfeng Yang0aebab02020-06-12 20:02:23 +0100717 ;;
Paolo Bonzini1badb702020-09-18 04:57:25 -0400718 --disable-tcg) tcg="disabled"
Alex Bennéed1a14252021-07-09 15:29:54 +0100719 plugins="no"
Paolo Bonzinib3f6ea72017-07-03 16:59:07 +0200720 ;;
Paolo Bonzini1badb702020-09-18 04:57:25 -0400721 --enable-tcg) tcg="enabled"
Paolo Bonzinib3f6ea72017-07-03 16:59:07 +0200722 ;;
pbrookcad25d62006-03-19 16:31:11 +0000723 --disable-system) softmmu="no"
pbrook0a8e90f2006-03-19 14:54:16 +0000724 ;;
pbrookcad25d62006-03-19 16:31:11 +0000725 --enable-system) softmmu="yes"
pbrook0a8e90f2006-03-19 14:54:16 +0000726 ;;
Zachary Amsden0953a802009-07-30 00:14:59 -1000727 --disable-user)
728 linux_user="no" ;
729 bsd_user="no" ;
Zachary Amsden0953a802009-07-30 00:14:59 -1000730 ;;
731 --enable-user) ;;
ths831b7822007-01-18 20:06:33 +0000732 --disable-linux-user) linux_user="no"
pbrook0a8e90f2006-03-19 14:54:16 +0000733 ;;
ths831b7822007-01-18 20:06:33 +0000734 --enable-linux-user) linux_user="yes"
735 ;;
blueswir184778502008-10-26 20:33:16 +0000736 --disable-bsd-user) bsd_user="no"
737 ;;
738 --enable-bsd-user) bsd_user="yes"
739 ;;
Avi Kivity40d64442011-11-15 20:12:17 +0200740 --enable-pie) pie="yes"
Kirill A. Shutemov34005a02009-09-12 02:17:55 +0300741 ;;
Avi Kivity40d64442011-11-15 20:12:17 +0200742 --disable-pie) pie="no"
Kirill A. Shutemov34005a02009-09-12 02:17:55 +0300743 ;;
bellard85aa5182007-11-11 20:17:03 +0000744 --enable-werror) werror="yes"
745 ;;
746 --disable-werror) werror="no"
747 ;;
Daniele Buono9e62ba42020-12-04 18:06:14 -0500748 --enable-cfi)
749 cfi="true";
Paolo Bonzinic54b59e2022-04-20 17:33:58 +0200750 meson_option_add -Db_lto=true
Daniele Buono9e62ba42020-12-04 18:06:14 -0500751 ;;
752 --disable-cfi) cfi="false"
753 ;;
Paolo Bonzinifbb41212020-10-05 11:31:15 +0200754 --disable-fdt) fdt="disabled"
Juan Quintela2df87df2009-08-12 18:29:54 +0200755 ;;
Paolo Bonzinifbb41212020-10-05 11:31:15 +0200756 --enable-fdt) fdt="enabled"
757 ;;
758 --enable-fdt=git) fdt="internal"
759 ;;
Paolo Bonzini03a3c0b2021-10-07 15:08:27 +0200760 --enable-fdt=*) fdt="$optarg"
Juan Quintela2df87df2009-08-12 18:29:54 +0200761 ;;
Daniel P. Berrangecc84d632017-10-20 15:02:43 +0100762 --with-git=*) git="$optarg"
763 ;;
Dan Streetman7d7dbf92021-01-19 12:20:46 -0500764 --with-git-submodules=*)
765 git_submodules_action="$optarg"
Daniel P. Berrangef62bbee2017-10-26 13:52:26 +0100766 ;;
John Snow0c5f3dc2023-05-10 23:54:30 -0400767 --disable-pypi) pypi="disabled"
768 ;;
769 --enable-pypi) pypi="enabled"
770 ;;
Alex Bennée9b8e4292021-07-09 15:29:56 +0100771 --enable-plugins) if test "$mingw32" = "yes"; then
772 error_exit "TCG plugins not currently supported on Windows platforms"
773 else
774 plugins="yes"
775 fi
Alex Bennée40e8c6f2019-06-13 14:52:25 +0100776 ;;
777 --disable-plugins) plugins="no"
778 ;;
Alex Bennéeafc3a8f2019-11-28 16:35:24 +0100779 --enable-containers) use_containers="yes"
780 ;;
781 --disable-containers) use_containers="no"
782 ;;
Alex Bennéef48e5902020-03-16 17:21:48 +0000783 --gdb=*) gdb_bin="$optarg"
784 ;;
Jagannathan Raman55116962022-06-13 16:26:24 -0400785 --enable-vfio-user-server) vfio_user_server="enabled"
786 ;;
787 --disable-vfio-user-server) vfio_user_server="disabled"
788 ;;
Paolo Bonzini3b4da132021-10-07 15:08:29 +0200789 # everything else has the same name in configure and meson
Paolo Bonzini4fda6012022-04-20 17:33:51 +0200790 --*) meson_option_parse "$opt" "$optarg"
balrog7f1559c2007-11-17 10:24:32 +0000791 ;;
bellard7d132992003-03-06 23:23:54 +0000792 esac
793done
794
Alex Bennéed1a14252021-07-09 15:29:54 +0100795# test for any invalid configuration combinations
796if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
797 error_exit "Can't enable plugins on non-TCG builds"
798fi
799
Dan Streetman7d7dbf92021-01-19 12:20:46 -0500800case $git_submodules_action in
801 update|validate)
802 if test ! -e "$source_path/.git"; then
803 echo "ERROR: cannot $git_submodules_action git submodules without .git"
804 exit 1
805 fi
806 ;;
807 ignore)
Paolo Bonzinib80fd282021-05-12 09:18:55 +0200808 if ! test -f "$source_path/ui/keycodemapdb/README"
809 then
810 echo
811 echo "ERROR: missing GIT submodules"
812 echo
813 if test -e "$source_path/.git"; then
814 echo "--with-git-submodules=ignore specified but submodules were not"
815 echo "checked out. Please initialize and update submodules."
816 else
817 echo "This is not a GIT checkout but module content appears to"
818 echo "be missing. Do not use 'git archive' or GitHub download links"
819 echo "to acquire QEMU source archives. Non-GIT builds are only"
820 echo "supported with source archives linked from:"
821 echo
822 echo " https://www.qemu.org/download/#source"
823 echo
824 echo "Developers working with GIT can use scripts/archive-source.sh"
825 echo "if they need to create valid source archives."
826 fi
827 echo
828 exit 1
829 fi
Dan Streetman7d7dbf92021-01-19 12:20:46 -0500830 ;;
831 *)
832 echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
833 exit 1
834 ;;
835esac
836
Peter Maydell60e0df22011-05-03 14:50:13 +0100837default_target_list=""
Peter Maydell6e92f822013-05-20 16:16:15 +0100838mak_wilds=""
839
Paolo Bonzinib915a2f2021-11-09 10:10:41 +0100840if [ "$linux_user" != no ]; then
Peter Maydell64708612022-08-25 16:06:59 +0100841 if [ "$targetos" = linux ] && [ -d "$source_path/linux-user/include/host/$cpu" ]; then
Paolo Bonzinib915a2f2021-11-09 10:10:41 +0100842 linux_user=yes
843 elif [ "$linux_user" = yes ]; then
844 error_exit "linux-user not supported on this architecture"
845 fi
846fi
847if [ "$bsd_user" != no ]; then
848 if [ "$bsd_user" = "" ]; then
849 test $targetos = freebsd && bsd_user=yes
850 fi
Peter Maydell64708612022-08-25 16:06:59 +0100851 if [ "$bsd_user" = yes ] && ! [ -d "$source_path/bsd-user/$targetos" ]; then
Paolo Bonzinib915a2f2021-11-09 10:10:41 +0100852 error_exit "bsd-user not supported on this host OS"
853 fi
854fi
Peter Maydell6e92f822013-05-20 16:16:15 +0100855if [ "$softmmu" = "yes" ]; then
Alex Bennée812b31d2021-07-07 14:17:43 +0100856 mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
Peter Maydell60e0df22011-05-03 14:50:13 +0100857fi
Peter Maydell6e92f822013-05-20 16:16:15 +0100858if [ "$linux_user" = "yes" ]; then
Alex Bennée812b31d2021-07-07 14:17:43 +0100859 mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
Peter Maydell60e0df22011-05-03 14:50:13 +0100860fi
Peter Maydell6e92f822013-05-20 16:16:15 +0100861if [ "$bsd_user" = "yes" ]; then
Alex Bennée812b31d2021-07-07 14:17:43 +0100862 mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
Peter Maydell60e0df22011-05-03 14:50:13 +0100863fi
864
Alex Bennée2d838d92020-09-09 12:27:37 +0100865for config in $mak_wilds; do
866 target="$(basename "$config" .mak)"
Alex Bennée98db9a02020-09-15 14:43:14 +0100867 if echo "$target_list_exclude" | grep -vq "$target"; then
Alex Bennée2d838d92020-09-09 12:27:37 +0100868 default_target_list="${default_target_list} $target"
869 fi
870done
Peter Maydell6e92f822013-05-20 16:16:15 +0100871
pbrookaf5db582006-04-08 14:26:41 +0000872if test x"$show_help" = x"yes" ; then
873cat << EOF
874
875Usage: configure [options]
876Options: [defaults in brackets after descriptions]
877
Stefan Weil08fb77e2013-12-18 22:09:39 +0100878Standard options:
879 --help print this message
880 --prefix=PREFIX install in PREFIX [$prefix]
Thomas Huth74154d72022-01-12 11:27:22 +0000881 --target-list=LIST set target list (default: build all)
Stefan Weil08fb77e2013-12-18 22:09:39 +0100882$(echo Available targets: $default_target_list | \
883 fold -s -w 53 | sed -e 's/^/ /')
Alex Bennée447e1332019-03-19 11:59:12 +0000884 --target-list-exclude=LIST exclude a set of targets from the default target-list
Stefan Weil08fb77e2013-12-18 22:09:39 +0100885
886Advanced options (experts only):
Joelle van Dyne3812c0c2021-01-25 17:24:48 -0800887 --cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
Stefan Weil08fb77e2013-12-18 22:09:39 +0100888 --cc=CC use C compiler CC [$cc]
Stefan Weil08fb77e2013-12-18 22:09:39 +0100889 --host-cc=CC use C compiler CC [$host_cc] for code run at
890 build time
891 --cxx=CXX use C++ compiler CXX [$cxx]
892 --objcc=OBJCC use Objective-C compiler OBJCC [$objcc]
Paolo Bonzinia2866662021-11-05 10:09:26 +0100893 --extra-cflags=CFLAGS append extra C compiler flags CFLAGS
894 --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
Philippe Mathieu-Daudée910c7d2022-01-08 22:38:55 +0100895 --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
Stefan Weil08fb77e2013-12-18 22:09:39 +0100896 --extra-ldflags=LDFLAGS append extra linker flags LDFLAGS
Alex Bennéed75402b2018-04-04 20:27:05 +0100897 --cross-cc-ARCH=CC use compiler when building ARCH guest test cases
Matheus Ferst479ca4c2022-01-20 14:31:41 -0300898 --cross-cc-cflags-ARCH= use compiler flags when building ARCH guest tests
Paolo Bonzini5adb43b2022-05-27 16:35:51 +0100899 --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
Stefan Weil08fb77e2013-12-18 22:09:39 +0100900 --make=MAKE use specified make [$make]
Stefan Weil08fb77e2013-12-18 22:09:39 +0100901 --python=PYTHON use specified python [$python]
Paolo Bonzini48328882020-08-26 08:04:15 +0200902 --ninja=NINJA use specified ninja [$ninja]
Stefan Weil08fb77e2013-12-18 22:09:39 +0100903 --smbd=SMBD use specified smbd [$smbd]
Thomas Huthdb1b5f12018-03-27 17:09:30 +0200904 --with-git=GIT use specified git [$git]
Dan Streetman7d7dbf92021-01-19 12:20:46 -0500905 --with-git-submodules=update update git submodules (default if .git dir exists)
906 --with-git-submodules=validate fail if git submodules are not up to date
907 --with-git-submodules=ignore do not update or check git submodules (default if no .git dir)
Stefan Weil08fb77e2013-12-18 22:09:39 +0100908 --static enable static build [$static]
Stefan Weil08fb77e2013-12-18 22:09:39 +0100909 --bindir=PATH install binaries in PATH
Marc-André Lureauca8c0902020-08-26 15:04:14 +0400910 --with-suffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
Paolo Bonzinic035c8d2020-12-14 11:34:47 +0100911 --without-default-features default all --enable-* options to "disabled"
912 --without-default-devices do not include any device that is not needed to
913 start the emulator (only use if you are including
Alex Bennéed1d5e9e2021-07-07 14:17:44 +0100914 desired devices in configs/devices/)
915 --with-devices-ARCH=NAME override default configs/devices
Stefan Weil08fb77e2013-12-18 22:09:39 +0100916 --enable-debug enable common debug build options
Stefan Weil08fb77e2013-12-18 22:09:39 +0100917 --disable-werror disable compilation abort on warning
Michael Tokarevc23f23b2015-06-17 22:19:26 +0300918 --cpu=CPU Build for host CPU [$cpu]
Alex Bennée40e8c6f2019-06-13 14:52:25 +0100919 --enable-plugins
920 enable plugins via shared library loading
Alex Bennéeafc3a8f2019-11-28 16:35:24 +0100921 --disable-containers don't use containers for cross-building
Alex Bennéef48e5902020-03-16 17:21:48 +0000922 --gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
Paolo Bonzini61d63092021-10-07 15:08:28 +0200923EOF
924 meson_options_help
925cat << EOF
Michael Tokarevc23f23b2015-06-17 22:19:26 +0300926 system all system emulation targets
927 user supported user emulation targets
928 linux-user all linux usermode emulation targets
929 bsd-user all BSD usermode emulation targets
Michael Tokarevc23f23b2015-06-17 22:19:26 +0300930 pie Position Independent Executables
Michael Tokarevc23f23b2015-06-17 22:19:26 +0300931 debug-tcg TCG debugging (default is disabled)
Stefan Weil08fb77e2013-12-18 22:09:39 +0100932
933NOTE: The object files are built at the place where configure is launched
pbrookaf5db582006-04-08 14:26:41 +0000934EOF
Fam Zheng2d2ad6d2014-04-18 14:55:36 +0800935exit 0
pbrookaf5db582006-04-08 14:26:41 +0000936fi
937
Thomas Huth9c790242019-03-11 11:20:34 +0100938# Remove old dependency files to make sure that they get properly regenerated
Peter Maydell002d8c12022-08-25 16:07:00 +0100939rm -f ./*/config-devices.mak.d
Thomas Huth9c790242019-03-11 11:20:34 +0100940
Daniel P. Berrangéfaf44142019-03-27 17:07:01 +0000941if test -z "$python"
942then
John Snowfee6d412023-02-10 01:31:43 +0100943 # If first_python is set, there was a binary somewhere even though
944 # it was not suitable. Use it for the error message.
945 if test -n "$first_python"; then
Paolo Bonzini5591b742023-05-10 23:54:31 -0400946 error_exit "Cannot use '$first_python', Python >= 3.7 is required." \
John Snowfee6d412023-02-10 01:31:43 +0100947 "Use --python=/path/to/python to specify a supported Python."
948 else
949 error_exit "Python not found. Use --python=/path/to/python"
950 fi
Stefan Hajnoczic53eeaf2017-03-28 14:44:18 +0100951fi
John Snowfee6d412023-02-10 01:31:43 +0100952
Roman Bolshakov8e2c76b2020-08-25 23:27:55 +0300953if ! has "$make"
954then
955 error_exit "GNU make ($make) not found"
956fi
Stefan Hajnoczic53eeaf2017-03-28 14:44:18 +0100957
John Snowfee6d412023-02-10 01:31:43 +0100958if ! check_py_version "$python"; then
Paolo Bonzini5591b742023-05-10 23:54:31 -0400959 error_exit "Cannot use '$python', Python >= 3.7 is required." \
John Snowe46b82a2023-05-10 23:54:32 -0400960 "Use --python=/path/to/python to specify a supported Python." \
961 "Maybe try:" \
962 " openSUSE Leap 15.3+: zypper install python39" \
963 " CentOS 8: dnf install python38"
Stefan Hajnoczic53eeaf2017-03-28 14:44:18 +0100964fi
965
John Snow81e2b192023-05-10 23:54:23 -0400966# Resolve PATH
967python="$(command -v "$python")"
John Snow81e2b192023-05-10 23:54:23 -0400968
969# Create a Python virtual environment using our configured python.
970# The stdout of this script will be the location of a symlink that
971# points to the configured Python.
972# Entry point scripts for pip, meson, and sphinx are generated if those
973# packages are present.
974
975# Defaults assumed for now:
976# - venv is cleared if it exists already;
977# - venv is allowed to use system packages;
John Snow0c5f3dc2023-05-10 23:54:30 -0400978# - all setup can be performed offline;
979# - missing packages may be fetched from PyPI,
980# unless --disable-pypi is passed.
John Snow81e2b192023-05-10 23:54:23 -0400981# - pip is not installed into the venv when possible,
982# but ensurepip is called as a fallback when necessary.
983
984echo "python determined to be '$python'"
985echo "python version: $($python --version)"
986
987python="$($python -B "${source_path}/python/scripts/mkvenv.py" create pyvenv)"
988if test "$?" -ne 0 ; then
989 error_exit "python venv creation failed"
990fi
991
992# Suppress writing compiled files
993python="$python -B"
John Snow6f6652e2023-05-10 23:54:29 -0400994mkvenv="$python ${source_path}/python/scripts/mkvenv.py"
Paolo Bonzini462a6562023-02-10 17:18:54 +0100995
John Snow0c5f3dc2023-05-10 23:54:30 -0400996mkvenv_flags=""
997if test "$pypi" = "enabled" ; then
998 mkvenv_flags="--online"
999fi
1000
John Snow6f6652e2023-05-10 23:54:29 -04001001if ! $mkvenv ensure \
John Snow0c5f3dc2023-05-10 23:54:30 -04001002 $mkvenv_flags \
John Snow66e2c6c2023-05-10 23:54:25 -04001003 --dir "${source_path}/python/wheels" \
1004 --diagnose "meson" \
Paolo Bonzini3b087f72021-12-23 15:29:56 +01001005 "meson>=0.63.0" ;
John Snow66e2c6c2023-05-10 23:54:25 -04001006then
1007 exit 1
Paolo Bonzinia5665052019-06-10 12:05:14 +02001008fi
Paolo Bonzinia5665052019-06-10 12:05:14 +02001009
John Snow66e2c6c2023-05-10 23:54:25 -04001010# At this point, we expect Meson to be installed and available.
1011# We expect mkvenv or pip to have created pyvenv/bin/meson for us.
1012# We ignore PATH completely here: we want to use the venv's Meson
1013# *exclusively*.
Marc-André Lureau0a01d762019-08-21 11:21:16 +04001014
John Snow66e2c6c2023-05-10 23:54:25 -04001015meson="$(cd pyvenv/bin; pwd)/meson"
Marc-André Lureau0a01d762019-08-21 11:21:16 +04001016
John Snow6f6652e2023-05-10 23:54:29 -04001017# Conditionally ensure Sphinx is installed.
1018
John Snow0c5f3dc2023-05-10 23:54:30 -04001019mkvenv_flags=""
1020if test "$pypi" = "enabled" -a "$docs" = "enabled" ; then
1021 mkvenv_flags="--online"
1022fi
1023
John Snow6f6652e2023-05-10 23:54:29 -04001024if test "$docs" != "disabled" ; then
1025 if ! $mkvenv ensure \
John Snow0c5f3dc2023-05-10 23:54:30 -04001026 $mkvenv_flags \
John Snow6f6652e2023-05-10 23:54:29 -04001027 --diagnose "sphinx-build" \
1028 "sphinx>=1.6.0" "sphinx-rtd-theme>=0.5.0";
1029 then
1030 if test "$docs" = "enabled" ; then
1031 exit 1
1032 fi
1033 echo "Sphinx not found/usable, disabling docs."
1034 docs=disabled
1035 else
1036 docs=enabled
1037 fi
1038fi
1039
Paolo Bonzini09e93322020-08-13 09:28:11 -04001040# Probe for ninja
Paolo Bonzini48328882020-08-26 08:04:15 +02001041
1042if test -z "$ninja"; then
1043 for c in ninja ninja-build samu; do
1044 if has $c; then
1045 ninja=$(command -v "$c")
1046 break
1047 fi
1048 done
Paolo Bonzini09e93322020-08-13 09:28:11 -04001049 if test -z "$ninja"; then
1050 error_exit "Cannot find Ninja"
1051 fi
Paolo Bonzini48328882020-08-26 08:04:15 +02001052fi
Paolo Bonzinia5665052019-06-10 12:05:14 +02001053
Peter Maydell9c83ffd2014-02-25 18:27:49 +00001054# Consult white-list to determine whether to enable werror
1055# by default. Only enable by default for git builds
Peter Maydell9c83ffd2014-02-25 18:27:49 +00001056if test -z "$werror" ; then
Dan Streetman7d7dbf92021-01-19 12:20:46 -05001057 if test "$git_submodules_action" != "ignore" && \
Eric Blakee633a5c2019-02-04 20:39:37 -06001058 { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
Peter Maydell9c83ffd2014-02-25 18:27:49 +00001059 werror="yes"
1060 else
1061 werror="no"
1062 fi
1063fi
1064
Paolo Bonzini975ff032020-11-20 10:34:10 +01001065if test "$targetos" = "bogus"; then
Peter Maydellfb59dab2017-03-28 14:01:52 +01001066 # Now that we know that we're not printing the help and that
1067 # the compiler works (so the results of the check_defines we used
1068 # to identify the OS are reliable), if we didn't recognize the
1069 # host OS we should stop now.
Peter Maydell951fedf2017-07-13 16:15:32 +01001070 error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
Peter Maydellfb59dab2017-03-28 14:01:52 +01001071fi
1072
Avi Kivity40d64442011-11-15 20:12:17 +02001073if test "$static" = "yes" ; then
Alex Bennée5f2453a2021-07-09 15:29:55 +01001074 if test "$plugins" = "yes"; then
1075 error_exit "static and plugins are mutually incompatible"
Alex Bennéeba4dd2a2021-07-09 15:29:57 +01001076 else
1077 plugins="no"
Alex Bennée5f2453a2021-07-09 15:29:55 +01001078 fi
Avi Kivity40d64442011-11-15 20:12:17 +02001079fi
Paolo Bonzini37650682021-12-10 09:55:15 +01001080test "$plugins" = "" && plugins=yes
Avi Kivity40d64442011-11-15 20:12:17 +02001081
Richard Hendersonb2634122019-12-17 13:54:56 -10001082cat > $TMPC << EOF
Avi Kivity21d4a792011-11-23 11:24:25 +02001083
1084#ifdef __linux__
1085# define THREAD __thread
1086#else
1087# define THREAD
1088#endif
Avi Kivity21d4a792011-11-23 11:24:25 +02001089static THREAD int tls_var;
Avi Kivity21d4a792011-11-23 11:24:25 +02001090int main(void) { return tls_var; }
Avi Kivity40d64442011-11-15 20:12:17 +02001091EOF
Alex Bennée412aeac2019-08-15 19:41:51 +00001092
Richard Henderson12781462019-12-17 15:30:14 -10001093if test "$static" = "yes"; then
Richard Hendersoneca7a8e2020-04-03 20:11:50 +01001094 if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
Richard Henderson12781462019-12-17 15:30:14 -10001095 pie="yes"
1096 elif test "$pie" = "yes"; then
1097 error_exit "-static-pie not available due to missing toolchain support"
1098 else
Richard Henderson12781462019-12-17 15:30:14 -10001099 pie="no"
1100 fi
Paolo Bonzinia988b4c2022-10-20 14:20:30 +02001101elif test "$pie" != "no"; then
1102 if compile_prog "-Werror -fPIE -DPIE" "-pie"; then
1103 pie="yes"
1104 elif test "$pie" = "yes"; then
1105 error_exit "PIE not available due to missing toolchain support"
1106 else
1107 echo "Disabling PIE due to missing toolchain support"
1108 pie="no"
Paolo Bonzinib9eae9e2022-03-29 13:07:25 +02001109 fi
Avi Kivity40d64442011-11-15 20:12:17 +02001110fi
1111
Paolo Bonzini09dada42013-04-17 16:26:47 +02001112##########################################
Paolo Bonzini09dada42013-04-17 16:26:47 +02001113
Stefan Weilafb63eb2012-09-26 22:04:38 +02001114if test -z "${target_list+xxx}" ; then
Paolo Bonzinifdb75ae2020-09-21 04:37:49 -04001115 default_targets=yes
Paolo Bonzinid880a3b2017-07-03 16:58:28 +02001116 for target in $default_target_list; do
Paolo Bonzinifdb75ae2020-09-21 04:37:49 -04001117 target_list="$target_list $target"
Paolo Bonzinid880a3b2017-07-03 16:58:28 +02001118 done
1119 target_list="${target_list# }"
Anthony Liguori121afa92012-09-14 08:17:03 -05001120else
Paolo Bonzinifdb75ae2020-09-21 04:37:49 -04001121 default_targets=no
Stefan Weil89138852016-05-16 15:10:20 +02001122 target_list=$(echo "$target_list" | sed -e 's/,/ /g')
Paolo Bonzinid880a3b2017-07-03 16:58:28 +02001123 for target in $target_list; do
1124 # Check that we recognised the target name; this allows a more
1125 # friendly error message than if we let it fall through.
1126 case " $default_target_list " in
1127 *" $target "*)
1128 ;;
1129 *)
1130 error_exit "Unknown target name '$target'"
1131 ;;
1132 esac
Paolo Bonzinid880a3b2017-07-03 16:58:28 +02001133 done
bellard5327cf42005-01-10 23:18:50 +00001134fi
Peter Maydell25b48332013-05-20 16:16:16 +01001135
Paolo Bonzinif55fe272010-05-26 16:08:17 +02001136# see if system emulation was really requested
1137case " $target_list " in
1138 *"-softmmu "*) softmmu=yes
1139 ;;
1140 *) softmmu=no
1141 ;;
1142esac
bellard5327cf42005-01-10 23:18:50 +00001143
Philippe Mathieu-Daudé76301562022-02-04 15:54:47 +01001144if test "$tcg" = "auto"; then
1145 if test -z "$target_list"; then
1146 tcg="disabled"
1147 else
1148 tcg="enabled"
1149 fi
1150fi
1151
1152if test "$tcg" = "enabled"; then
1153 git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
1154 git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
1155fi
1156
Michal Privoznik33ab5f22022-10-14 09:30:15 +02001157##########################################
bellard7d132992003-03-06 23:23:54 +00001158# big/little endian test
1159cat > $TMPC << EOF
Michal Privoznik33ab5f22022-10-14 09:30:15 +02001160#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1161# error LITTLE
1162#endif
1163int main(void) { return 0; }
bellard7d132992003-03-06 23:23:54 +00001164EOF
1165
Michal Privoznik33ab5f22022-10-14 09:30:15 +02001166if ! compile_prog ; then
1167 bigendian="no"
Mike Frysinger61cc9192013-06-30 23:30:18 -04001168else
Michal Privoznik33ab5f22022-10-14 09:30:15 +02001169 cat > $TMPC << EOF
1170#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
1171# error BIG
1172#endif
1173int main(void) { return 0; }
1174EOF
1175
1176 if ! compile_prog ; then
1177 bigendian="yes"
1178 else
Mike Frysinger61cc9192013-06-30 23:30:18 -04001179 echo big/little test failed
Thomas Huth659eb152021-07-15 10:39:28 +02001180 exit 1
Michal Privoznik33ab5f22022-10-14 09:30:15 +02001181 fi
bellard7d132992003-03-06 23:23:54 +00001182fi
1183
Gonglei015a33b2014-07-01 20:58:08 +08001184##########################################
aurel32f652e6a2008-12-16 10:43:48 +00001185# fdt probe
Paolo Bonzinifbb41212020-10-05 11:31:15 +02001186
1187case "$fdt" in
1188 auto | enabled | internal)
1189 # Simpler to always update submodule, even if not needed.
Paolo Bonzini2d652f22021-05-12 09:21:56 +02001190 git_submodules="${git_submodules} dtc"
Peter Maydelle169e1e2013-05-24 16:26:54 +01001191 ;;
Paolo Bonzinifbb41212020-10-05 11:31:15 +02001192esac
aurel32f652e6a2008-12-16 10:43:48 +00001193
Richard Henderson76a347e2012-12-28 14:17:02 -08001194########################################
John Snowfd0e6052015-03-25 18:57:39 -04001195# check if ccache is interfering with
1196# semantic analysis of macros
1197
John Snow5e4dfd32015-10-28 13:56:40 -04001198unset CCACHE_CPP2
John Snowfd0e6052015-03-25 18:57:39 -04001199ccache_cpp2=no
1200cat > $TMPC << EOF
1201static const int Z = 1;
1202#define fn() ({ Z; })
1203#define TAUT(X) ((X) == Z)
1204#define PAREN(X, Y) (X == Y)
1205#define ID(X) (X)
Stefan Weil8a0afbb2022-11-02 21:22:58 +01001206int main(void)
John Snowfd0e6052015-03-25 18:57:39 -04001207{
1208 int x = 0, y = 0;
1209 x = ID(x);
1210 x = fn();
1211 fn();
1212 if (PAREN(x, y)) return 0;
1213 if (TAUT(Z)) return 0;
1214 return 0;
1215}
1216EOF
1217
1218if ! compile_object "-Werror"; then
1219 ccache_cpp2=yes
1220fi
1221
Alexander Bulekovadc28022020-02-19 23:11:14 -05001222##########################################
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001223# functions to probe cross compilers
1224
1225container="no"
Alex Bennée60f999b2023-02-28 19:06:46 +00001226runc=""
Stefan Weil47fdc8f2022-11-17 17:25:20 +00001227if test $use_containers = "yes" && (has "docker" || has "podman"); then
Paolo Bonzinic4575b52022-09-29 12:41:58 +01001228 case $($python "$source_path"/tests/docker/docker.py probe) in
1229 *docker) container=docker ;;
1230 podman) container=podman ;;
1231 no) container=no ;;
1232 esac
Paolo Bonzinia3e28f82022-09-29 12:41:59 +01001233 if test "$container" != "no"; then
1234 docker_py="$python $source_path/tests/docker/docker.py --engine $container"
Alex Bennée60f999b2023-02-28 19:06:46 +00001235 runc=$($python "$source_path"/tests/docker/docker.py probe)
Paolo Bonzinia3e28f82022-09-29 12:41:59 +01001236 fi
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001237fi
1238
1239# cross compilers defaults, can be overridden with --cross-cc-ARCH
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001240: ${cross_prefix_aarch64="aarch64-linux-gnu-"}
1241: ${cross_prefix_aarch64_be="$cross_prefix_aarch64"}
1242: ${cross_prefix_alpha="alpha-linux-gnu-"}
1243: ${cross_prefix_arm="arm-linux-gnueabihf-"}
1244: ${cross_prefix_armeb="$cross_prefix_arm"}
1245: ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
Song Gao34bb43b2022-06-06 20:43:33 +08001246: ${cross_prefix_loongarch64="loongarch64-unknown-linux-gnu-"}
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001247: ${cross_prefix_hppa="hppa-linux-gnu-"}
1248: ${cross_prefix_i386="i686-linux-gnu-"}
1249: ${cross_prefix_m68k="m68k-linux-gnu-"}
1250: ${cross_prefix_microblaze="microblaze-linux-musl-"}
1251: ${cross_prefix_mips64el="mips64el-linux-gnuabi64-"}
1252: ${cross_prefix_mips64="mips64-linux-gnuabi64-"}
1253: ${cross_prefix_mipsel="mipsel-linux-gnu-"}
1254: ${cross_prefix_mips="mips-linux-gnu-"}
1255: ${cross_prefix_nios2="nios2-linux-gnu-"}
1256: ${cross_prefix_ppc="powerpc-linux-gnu-"}
1257: ${cross_prefix_ppc64="powerpc64-linux-gnu-"}
1258: ${cross_prefix_ppc64le="$cross_prefix_ppc64"}
1259: ${cross_prefix_riscv64="riscv64-linux-gnu-"}
1260: ${cross_prefix_s390x="s390x-linux-gnu-"}
1261: ${cross_prefix_sh4="sh4-linux-gnu-"}
1262: ${cross_prefix_sparc64="sparc64-linux-gnu-"}
1263: ${cross_prefix_sparc="$cross_prefix_sparc64"}
1264: ${cross_prefix_x86_64="x86_64-linux-gnu-"}
1265
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001266: ${cross_cc_aarch64_be="$cross_cc_aarch64"}
1267: ${cross_cc_cflags_aarch64_be="-mbig-endian"}
Paolo Bonzini46af66e2022-05-27 16:35:49 +01001268: ${cross_cc_armeb="$cross_cc_arm"}
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001269: ${cross_cc_cflags_armeb="-mbig-endian"}
1270: ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
Taylor Simpsonfc2622f2023-04-27 15:40:49 -07001271: ${cross_cc_cflags_hexagon="-mv73 -O2 -static"}
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001272: ${cross_cc_cflags_i386="-m32"}
Paolo Bonzinid44f2f92022-06-15 11:42:01 +02001273: ${cross_cc_cflags_ppc="-m32 -mbig-endian"}
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001274: ${cross_cc_cflags_ppc64="-m64 -mbig-endian"}
1275: ${cross_cc_ppc64le="$cross_cc_ppc64"}
1276: ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"}
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001277: ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
Paolo Bonzini46af66e2022-05-27 16:35:49 +01001278: ${cross_cc_sparc="$cross_cc_sparc64"}
1279: ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001280: ${cross_cc_cflags_x86_64="-m64"}
1281
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001282compute_target_variable() {
Paolo Bonzini92e288f2022-06-22 10:42:58 +02001283 eval "$2="
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001284 if eval test -n "\"\${cross_prefix_$1}\""; then
1285 if eval has "\"\${cross_prefix_$1}\$3\""; then
1286 eval "$2=\"\${cross_prefix_$1}\$3\""
1287 fi
1288 fi
1289}
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001290
Paolo Bonzini35fd22b2022-10-12 16:33:03 +02001291have_target() {
1292 for i; do
1293 case " $target_list " in
1294 *" $i "*) return 0;;
1295 *) ;;
1296 esac
1297 done
1298 return 1
1299}
1300
Paolo Bonzini52f08de2022-07-02 15:59:02 +02001301# probe_target_compiler TARGET
1302#
1303# Look for a compiler for the given target, either native or cross.
1304# Set variables target_* if a compiler is found, and container_cross_*
1305# if a Docker-based cross-compiler image is known for the target.
1306# Set got_cross_cc to yes/no depending on whether a non-container-based
1307# compiler was found.
1308#
1309# If TARGET is a user-mode emulation target, also set build_static to
1310# "y" if static linking is possible.
1311#
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001312probe_target_compiler() {
1313 # reset all output variables
Paolo Bonzini92e288f2022-06-22 10:42:58 +02001314 got_cross_cc=no
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001315 container_image=
1316 container_hosts=
1317 container_cross_cc=
Paolo Bonzini87eb0142022-05-27 16:35:52 +01001318 container_cross_ar=
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001319 container_cross_as=
1320 container_cross_ld=
Paolo Bonzini87eb0142022-05-27 16:35:52 +01001321 container_cross_nm=
1322 container_cross_objcopy=
1323 container_cross_ranlib=
1324 container_cross_strip=
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001325
Paolo Bonzini52f08de2022-07-02 15:59:02 +02001326 target_arch=${1%%-*}
1327 case $target_arch in
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001328 aarch64) container_hosts="x86_64 aarch64" ;;
1329 alpha) container_hosts=x86_64 ;;
1330 arm) container_hosts="x86_64 aarch64" ;;
1331 cris) container_hosts=x86_64 ;;
1332 hexagon) container_hosts=x86_64 ;;
1333 hppa) container_hosts=x86_64 ;;
1334 i386) container_hosts=x86_64 ;;
Richard Hendersonb70ec502022-07-04 12:36:29 +05301335 loongarch64) container_hosts=x86_64 ;;
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001336 m68k) container_hosts=x86_64 ;;
1337 microblaze) container_hosts=x86_64 ;;
1338 mips64el) container_hosts=x86_64 ;;
1339 mips64) container_hosts=x86_64 ;;
1340 mipsel) container_hosts=x86_64 ;;
1341 mips) container_hosts=x86_64 ;;
1342 nios2) container_hosts=x86_64 ;;
1343 ppc) container_hosts=x86_64 ;;
1344 ppc64|ppc64le) container_hosts=x86_64 ;;
1345 riscv64) container_hosts=x86_64 ;;
1346 s390x) container_hosts=x86_64 ;;
1347 sh4) container_hosts=x86_64 ;;
1348 sparc64) container_hosts=x86_64 ;;
1349 tricore) container_hosts=x86_64 ;;
1350 x86_64) container_hosts="aarch64 ppc64el x86_64" ;;
1351 xtensa*) container_hosts=x86_64 ;;
1352 esac
1353
1354 for host in $container_hosts; do
1355 test "$container" != no || continue
1356 test "$host" = "$cpu" || continue
Paolo Bonzini52f08de2022-07-02 15:59:02 +02001357 case $target_arch in
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001358 aarch64)
1359 # We don't have any bigendian build tools so we only use this for AArch64
1360 container_image=debian-arm64-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001361 container_cross_prefix=aarch64-linux-gnu-
1362 container_cross_cc=${container_cross_prefix}gcc-10
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001363 ;;
1364 alpha)
1365 container_image=debian-alpha-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001366 container_cross_prefix=alpha-linux-gnu-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001367 ;;
1368 arm)
1369 # We don't have any bigendian build tools so we only use this for ARM
1370 container_image=debian-armhf-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001371 container_cross_prefix=arm-linux-gnueabihf-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001372 ;;
1373 cris)
1374 container_image=fedora-cris-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001375 container_cross_prefix=cris-linux-gnu-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001376 ;;
1377 hexagon)
1378 container_image=debian-hexagon-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001379 container_cross_prefix=hexagon-unknown-linux-musl-
1380 container_cross_cc=${container_cross_prefix}clang
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001381 ;;
1382 hppa)
1383 container_image=debian-hppa-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001384 container_cross_prefix=hppa-linux-gnu-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001385 ;;
1386 i386)
1387 container_image=fedora-i386-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001388 container_cross_prefix=
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001389 ;;
Richard Hendersonb70ec502022-07-04 12:36:29 +05301390 loongarch64)
1391 container_image=debian-loongarch-cross
1392 container_cross_prefix=loongarch64-unknown-linux-gnu-
1393 ;;
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001394 m68k)
1395 container_image=debian-m68k-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001396 container_cross_prefix=m68k-linux-gnu-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001397 ;;
1398 microblaze)
1399 container_image=debian-microblaze-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001400 container_cross_prefix=microblaze-linux-musl-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001401 ;;
1402 mips64el)
1403 container_image=debian-mips64el-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001404 container_cross_prefix=mips64el-linux-gnuabi64-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001405 ;;
1406 mips64)
1407 container_image=debian-mips64-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001408 container_cross_prefix=mips64-linux-gnuabi64-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001409 ;;
1410 mipsel)
1411 container_image=debian-mipsel-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001412 container_cross_prefix=mipsel-linux-gnu-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001413 ;;
1414 mips)
1415 container_image=debian-mips-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001416 container_cross_prefix=mips-linux-gnu-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001417 ;;
1418 nios2)
1419 container_image=debian-nios2-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001420 container_cross_prefix=nios2-linux-gnu-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001421 ;;
1422 ppc)
1423 container_image=debian-powerpc-test-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001424 container_cross_prefix=powerpc-linux-gnu-
1425 container_cross_cc=${container_cross_prefix}gcc-10
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001426 ;;
1427 ppc64|ppc64le)
1428 container_image=debian-powerpc-test-cross
Richard Henderson705c8812022-07-28 11:39:01 -07001429 container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu-
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001430 container_cross_cc=${container_cross_prefix}gcc-10
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001431 ;;
1432 riscv64)
1433 container_image=debian-riscv64-test-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001434 container_cross_prefix=riscv64-linux-gnu-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001435 ;;
1436 s390x)
1437 container_image=debian-s390x-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001438 container_cross_prefix=s390x-linux-gnu-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001439 ;;
1440 sh4)
1441 container_image=debian-sh4-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001442 container_cross_prefix=sh4-linux-gnu-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001443 ;;
1444 sparc64)
1445 container_image=debian-sparc64-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001446 container_cross_prefix=sparc64-linux-gnu-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001447 ;;
1448 tricore)
1449 container_image=debian-tricore-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001450 container_cross_prefix=tricore-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001451 container_cross_as=tricore-as
1452 container_cross_ld=tricore-ld
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001453 break
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001454 ;;
1455 x86_64)
1456 container_image=debian-amd64-cross
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001457 container_cross_prefix=x86_64-linux-gnu-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001458 ;;
1459 xtensa*)
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001460 container_hosts=x86_64
1461 container_image=debian-xtensa-cross
1462
1463 # default to the dc232b cpu
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001464 container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001465 ;;
1466 esac
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001467 : ${container_cross_cc:=${container_cross_prefix}gcc}
Paolo Bonzini87eb0142022-05-27 16:35:52 +01001468 : ${container_cross_ar:=${container_cross_prefix}ar}
Paolo Bonzini5adb43b2022-05-27 16:35:51 +01001469 : ${container_cross_as:=${container_cross_prefix}as}
1470 : ${container_cross_ld:=${container_cross_prefix}ld}
Paolo Bonzini87eb0142022-05-27 16:35:52 +01001471 : ${container_cross_nm:=${container_cross_prefix}nm}
1472 : ${container_cross_objcopy:=${container_cross_prefix}objcopy}
1473 : ${container_cross_ranlib:=${container_cross_prefix}ranlib}
1474 : ${container_cross_strip:=${container_cross_prefix}strip}
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001475 done
1476
Paolo Bonzini92e288f2022-06-22 10:42:58 +02001477 try=cross
Paolo Bonzini52f08de2022-07-02 15:59:02 +02001478 case "$target_arch:$cpu" in
Paolo Bonzini26e72532022-06-06 10:47:45 +02001479 aarch64_be:aarch64 | \
1480 armeb:arm | \
Paolo Bonzini640aabc2022-06-15 11:42:01 +02001481 i386:x86_64 | \
Paolo Bonzini26e72532022-06-06 10:47:45 +02001482 mips*:mips64 | \
Paolo Bonzinid44f2f92022-06-15 11:42:01 +02001483 ppc*:ppc64 | \
Paolo Bonzini26e72532022-06-06 10:47:45 +02001484 sparc:sparc64 | \
Paolo Bonzini640aabc2022-06-15 11:42:01 +02001485 "$cpu:$cpu")
Paolo Bonzini92e288f2022-06-22 10:42:58 +02001486 try='native cross' ;;
Paolo Bonzini640aabc2022-06-15 11:42:01 +02001487 esac
Paolo Bonzini92e288f2022-06-22 10:42:58 +02001488 eval "target_cflags=\${cross_cc_cflags_$target_arch}"
Peter Maydellb3b54722022-08-25 16:07:03 +01001489 for thistry in $try; do
1490 case $thistry in
Paolo Bonzini92e288f2022-06-22 10:42:58 +02001491 native)
1492 target_cc=$cc
1493 target_ccas=$ccas
1494 target_ar=$ar
1495 target_as=$as
1496 target_ld=$ld
1497 target_nm=$nm
1498 target_objcopy=$objcopy
1499 target_ranlib=$ranlib
1500 target_strip=$strip
1501 ;;
1502 cross)
1503 target_cc=
1504 if eval test -n "\"\${cross_cc_$target_arch}\""; then
1505 if eval has "\"\${cross_cc_$target_arch}\""; then
1506 eval "target_cc=\"\${cross_cc_$target_arch}\""
1507 fi
1508 else
1509 compute_target_variable $target_arch target_cc gcc
1510 fi
1511 target_ccas=$target_cc
1512 compute_target_variable $target_arch target_ar ar
1513 compute_target_variable $target_arch target_as as
1514 compute_target_variable $target_arch target_ld ld
1515 compute_target_variable $target_arch target_nm nm
1516 compute_target_variable $target_arch target_objcopy objcopy
1517 compute_target_variable $target_arch target_ranlib ranlib
1518 compute_target_variable $target_arch target_strip strip
1519 ;;
1520 esac
1521
1522 if test -n "$target_cc"; then
1523 case $target_arch in
1524 i386|x86_64)
1525 if $target_cc --version | grep -qi "clang"; then
1526 continue
1527 fi
1528 ;;
1529 esac
1530 elif test -n "$target_as" && test -n "$target_ld"; then
1531 # Special handling for assembler only targets
1532 case $target in
1533 tricore-softmmu)
1534 build_static=
1535 got_cross_cc=yes
1536 break
1537 ;;
1538 *)
1539 continue
1540 ;;
1541 esac
1542 else
1543 continue
1544 fi
1545
1546 write_c_skeleton
1547 case $1 in
1548 *-softmmu)
1549 if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC &&
1550 do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then
1551 got_cross_cc=yes
1552 break
1553 fi
1554 ;;
1555 *)
1556 if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC -static ; then
1557 build_static=y
1558 got_cross_cc=yes
1559 break
1560 fi
1561 if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC ; then
1562 build_static=
1563 got_cross_cc=yes
1564 break
Paolo Bonzini2ad60f62022-05-27 16:35:50 +01001565 fi
1566 ;;
1567 esac
Paolo Bonzini92e288f2022-06-22 10:42:58 +02001568 done
1569 if test $got_cross_cc != yes; then
1570 build_static=
1571 target_cc=
1572 target_ccas=
Paolo Bonzini92e288f2022-06-22 10:42:58 +02001573 target_ar=
1574 target_as=
1575 target_ld=
1576 target_nm=
1577 target_objcopy=
1578 target_ranlib=
1579 target_strip=
Paolo Bonzini2ad60f62022-05-27 16:35:50 +01001580 fi
Alex Bennéefde10962022-10-11 12:34:16 +01001581 test -n "$target_cc"
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001582}
1583
1584write_target_makefile() {
Paolo Bonzinie81785a2022-06-15 11:45:55 +02001585 echo "EXTRA_CFLAGS=$target_cflags"
Paolo Bonzini0825cae2022-09-29 12:42:06 +01001586 if test -z "$target_cc" && test -z "$target_as"; then
1587 test -z "$container_image" && error_exit "Internal error: could not find cross compiler for $1?"
1588 echo "$1: docker-image-$container_image" >> Makefile.prereqs
1589 if test -n "$container_cross_cc"; then
1590 echo "CC=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
1591 echo "CCAS=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
1592 fi
1593 echo "AR=$docker_py cc --cc $container_cross_ar -i qemu/$container_image -s $source_path --"
1594 echo "AS=$docker_py cc --cc $container_cross_as -i qemu/$container_image -s $source_path --"
1595 echo "LD=$docker_py cc --cc $container_cross_ld -i qemu/$container_image -s $source_path --"
1596 echo "NM=$docker_py cc --cc $container_cross_nm -i qemu/$container_image -s $source_path --"
1597 echo "OBJCOPY=$docker_py cc --cc $container_cross_objcopy -i qemu/$container_image -s $source_path --"
1598 echo "RANLIB=$docker_py cc --cc $container_cross_ranlib -i qemu/$container_image -s $source_path --"
1599 echo "STRIP=$docker_py cc --cc $container_cross_strip -i qemu/$container_image -s $source_path --"
1600 else
1601 if test -n "$target_cc"; then
1602 echo "CC=$target_cc"
1603 echo "CCAS=$target_ccas"
1604 fi
1605 if test -n "$target_ar"; then
1606 echo "AR=$target_ar"
1607 fi
1608 if test -n "$target_as"; then
1609 echo "AS=$target_as"
1610 fi
1611 if test -n "$target_ld"; then
1612 echo "LD=$target_ld"
1613 fi
1614 if test -n "$target_nm"; then
1615 echo "NM=$target_nm"
1616 fi
1617 if test -n "$target_objcopy"; then
1618 echo "OBJCOPY=$target_objcopy"
1619 fi
1620 if test -n "$target_ranlib"; then
1621 echo "RANLIB=$target_ranlib"
1622 fi
1623 if test -n "$target_strip"; then
1624 echo "STRIP=$target_strip"
1625 fi
Paolo Bonzini87eb0142022-05-27 16:35:52 +01001626 fi
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001627}
1628
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001629##########################################
Jagannathan Raman55116962022-06-13 16:26:24 -04001630# check for vfio_user_server
1631
1632case "$vfio_user_server" in
1633 enabled )
1634 if test "$git_submodules_action" != "ignore"; then
1635 git_submodules="${git_submodules} subprojects/libvfio-user"
1636 fi
1637 ;;
1638esac
1639
Paolo Bonzini33ab4782022-05-27 16:35:55 +01001640#######################################
1641# cross-compiled firmware targets
1642
Paolo Bonziniad388842022-05-27 16:35:53 +01001643# Set up build tree symlinks that point back into the source tree
1644# (these can be both files and directories).
1645# Caution: avoid adding files or directories here using wildcards. This
1646# will result in problems later if a new file matching the wildcard is
1647# added to the source tree -- nothing will cause configure to be rerun
1648# so the build tree will be missing the link back to the new file, and
1649# tests might fail. Prefer to keep the relevant files in their own
1650# directory and symlink the directory instead.
1651LINKS="Makefile"
Thomas Huth201aa172023-02-28 22:15:29 +01001652LINKS="$LINKS docs/config"
Paolo Bonziniad388842022-05-27 16:35:53 +01001653LINKS="$LINKS pc-bios/optionrom/Makefile"
1654LINKS="$LINKS pc-bios/s390-ccw/Makefile"
Paolo Bonzinid6959182022-05-27 16:35:56 +01001655LINKS="$LINKS pc-bios/vof/Makefile"
Paolo Bonziniad388842022-05-27 16:35:53 +01001656LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
1657LINKS="$LINKS tests/avocado tests/data"
1658LINKS="$LINKS tests/qemu-iotests/check"
1659LINKS="$LINKS python"
1660LINKS="$LINKS contrib/plugins/Makefile "
1661for f in $LINKS ; do
1662 if [ -e "$source_path/$f" ]; then
Paolo Bonziniad388842022-05-27 16:35:53 +01001663 symlink "$source_path/$f" "$f"
1664 fi
1665done
1666
Paolo Bonzinib898bf22022-09-29 12:42:05 +01001667echo "# Automatically generated by configure - do not modify" > Makefile.prereqs
1668
Paolo Bonzinica35f782010-05-26 16:08:29 +02001669# Mac OS X ships with a broken assembler
1670roms=
Paolo Bonzini35fd22b2022-10-12 16:33:03 +02001671if have_target i386-softmmu x86_64-softmmu && \
1672 test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
1673 test "$targetos" != "haiku" && \
Paolo Bonzini61cbb352022-09-29 12:41:57 +01001674 probe_target_compiler i386-softmmu; then
Paolo Bonzini70899772022-06-06 11:35:41 +02001675 roms="pc-bios/optionrom"
1676 config_mak=pc-bios/optionrom/config.mak
1677 echo "# Automatically generated by configure - do not modify" > $config_mak
1678 echo "TOPSRC_DIR=$source_path" >> $config_mak
Alex Bennéefde10962022-10-11 12:34:16 +01001679 write_target_makefile >> $config_mak
Paolo Bonzinica35f782010-05-26 16:08:29 +02001680fi
Paolo Bonzinica35f782010-05-26 16:08:29 +02001681
Paolo Bonzini35fd22b2022-10-12 16:33:03 +02001682if have_target ppc-softmmu ppc64-softmmu && \
1683 probe_target_compiler ppc-softmmu; then
Paolo Bonzini76ca98b2022-04-13 15:22:01 +02001684 roms="$roms pc-bios/vof"
Paolo Bonzinid6959182022-05-27 16:35:56 +01001685 config_mak=pc-bios/vof/config.mak
1686 echo "# Automatically generated by configure - do not modify" > $config_mak
1687 echo "SRC_DIR=$source_path/pc-bios/vof" >> $config_mak
Alex Bennéefde10962022-10-11 12:34:16 +01001688 write_target_makefile >> $config_mak
Paolo Bonzinid6959182022-05-27 16:35:56 +01001689fi
1690
Paolo Bonzini9ffed422022-05-27 16:35:54 +01001691# Only build s390-ccw bios if the compiler has -march=z900 or -march=z10
1692# (which is the lowest architecture level that Clang supports)
Paolo Bonzini35fd22b2022-10-12 16:33:03 +02001693if have_target s390x-softmmu && probe_target_compiler s390x-softmmu; then
Alex Bennéefde10962022-10-11 12:34:16 +01001694 write_c_skeleton
1695 do_compiler "$target_cc" $target_cc_cflags -march=z900 -o $TMPO -c $TMPC
1696 has_z900=$?
1697 if [ $has_z900 = 0 ] || do_compiler "$target_cc" $target_cc_cflags -march=z10 -msoft-float -Werror -o $TMPO -c $TMPC; then
1698 if [ $has_z900 != 0 ]; then
1699 echo "WARNING: Your compiler does not support the z900!"
1700 echo " The s390-ccw bios will only work with guest CPUs >= z10."
Thomas Hutha5b2afd2021-05-02 13:22:21 +02001701 fi
Paolo Bonzini76ca98b2022-04-13 15:22:01 +02001702 roms="$roms pc-bios/s390-ccw"
Paolo Bonzini9ffed422022-05-27 16:35:54 +01001703 config_mak=pc-bios/s390-ccw/config-host.mak
1704 echo "# Automatically generated by configure - do not modify" > $config_mak
1705 echo "SRC_PATH=$source_path/pc-bios/s390-ccw" >> $config_mak
Alex Bennéefde10962022-10-11 12:34:16 +01001706 write_target_makefile >> $config_mak
Philippe Mathieu-Daudé1ef6bfc2020-06-15 09:49:19 +02001707 # SLOF is required for building the s390-ccw firmware on s390x,
1708 # since it is using the libnet code from SLOF for network booting.
Paolo Bonzini2d652f22021-05-12 09:21:56 +02001709 git_submodules="${git_submodules} roms/SLOF"
Thomas Huth2e33c3f2019-01-14 13:52:26 +01001710 fi
Christian Borntraeger9933c302013-04-23 01:23:03 +00001711fi
1712
Paolo Bonzini9ffed422022-05-27 16:35:54 +01001713#######################################
1714# generate config-host.mak
1715
Peter Maydell35a7a6f2022-07-20 16:26:27 +01001716if ! (GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
Dan Streetman7d7dbf92021-01-19 12:20:46 -05001717 exit 1
Yonggang Luo5d91a2e2020-09-03 01:00:49 +08001718fi
Yonggang Luo5d91a2e2020-09-03 01:00:49 +08001719
Juan Quintela98ec69a2009-07-16 18:34:18 +02001720config_host_mak="config-host.mak"
bellard97a847b2003-08-10 21:36:04 +00001721
Juan Quintela98ec69a2009-07-16 18:34:18 +02001722echo "# Automatically generated by configure - do not modify" > $config_host_mak
Juan Quintela98ec69a2009-07-16 18:34:18 +02001723echo >> $config_host_mak
Juan Quintela98ec69a2009-07-16 18:34:18 +02001724
Paolo Bonzinie6c3b0f2010-10-21 10:18:35 +02001725echo all: >> $config_host_mak
Daniel P. Berrangecc84d632017-10-20 15:02:43 +01001726echo "GIT=$git" >> $config_host_mak
Daniel P. Berrangeaef45d52017-09-29 11:11:56 +01001727echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
Dan Streetman7d7dbf92021-01-19 12:20:46 -05001728echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
Juan Quintela804edf22009-07-27 16:12:49 +02001729
aurel32f8393942009-04-13 18:45:38 +00001730if test "$debug_tcg" = "yes" ; then
Juan Quintela2358a492009-07-27 16:13:25 +02001731 echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
aurel32f8393942009-04-13 18:45:38 +00001732fi
bellard67b915a2004-03-31 23:37:16 +00001733if test "$mingw32" = "yes" ; then
Juan Quintela98ec69a2009-07-16 18:34:18 +02001734 echo "CONFIG_WIN32=y" >> $config_host_mak
Paolo Bonzini954ed682022-10-12 11:35:17 +02001735 echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER-QEMU}" >> $config_host_mak
1736 echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO-Linux}" >> $config_host_mak
1737 echo "QEMU_GA_VERSION=${QEMU_GA_VERSION-$(cat "$source_path"/VERSION)}" >> $config_host_mak
pbrook210fa552007-02-27 21:04:49 +00001738else
Juan Quintela35f4df22009-07-27 16:13:07 +02001739 echo "CONFIG_POSIX=y" >> $config_host_mak
bellard67b915a2004-03-31 23:37:16 +00001740fi
blueswir1128ab2f2008-08-15 18:33:42 +00001741
Mark McLoughlindffcb712009-10-22 17:49:11 +01001742if test "$linux" = "yes" ; then
1743 echo "CONFIG_LINUX=y" >> $config_host_mak
1744fi
1745
bellard83fb7ad2004-07-05 21:25:26 +00001746if test "$darwin" = "yes" ; then
Juan Quintela98ec69a2009-07-16 18:34:18 +02001747 echo "CONFIG_DARWIN=y" >> $config_host_mak
bellard83fb7ad2004-07-05 21:25:26 +00001748fi
malcb29fe3e2008-11-18 01:42:22 +00001749
bellardec530c82006-04-25 22:36:06 +00001750if test "$solaris" = "yes" ; then
Juan Quintela98ec69a2009-07-16 18:34:18 +02001751 echo "CONFIG_SOLARIS=y" >> $config_host_mak
bellardec530c82006-04-25 22:36:06 +00001752fi
Juan Quintela98ec69a2009-07-16 18:34:18 +02001753echo "SRC_PATH=$source_path" >> $config_host_mak
Alex Bennée2b1f35b2018-07-04 07:30:11 +01001754echo "TARGET_DIRS=$target_list" >> $config_host_mak
Jan Vesely277abf12016-04-29 13:15:23 -04001755
bellard83fb7ad2004-07-05 21:25:26 +00001756# XXX: suppress that
bellard7d3505c2004-05-12 19:32:15 +00001757if [ "$bsd" = "yes" ] ; then
Juan Quintela2358a492009-07-27 16:13:25 +02001758 echo "CONFIG_BSD=y" >> $config_host_mak
bellard7d3505c2004-05-12 19:32:15 +00001759fi
1760
Alex Bennée40e8c6f2019-06-13 14:52:25 +01001761if test "$plugins" = "yes" ; then
1762 echo "CONFIG_PLUGIN=y" >> $config_host_mak
Alex Bennée40e8c6f2019-06-13 14:52:25 +01001763fi
1764
Alex Bennéeb1863cc2021-01-08 22:42:39 +00001765if test -n "$gdb_bin"; then
1766 gdb_version=$($gdb_bin --version | head -n 1)
Alex Bennéed6a66c82021-02-02 13:39:53 +00001767 if version_ge ${gdb_version##* } 9.1; then
Alex Bennéeb1863cc2021-01-08 22:42:39 +00001768 echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
Paolo Bonzini4b424c72023-05-18 11:27:39 +02001769 gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
Alex Bennée48543dd2022-09-29 12:41:45 +01001770 else
1771 gdb_bin=""
Alex Bennéeb1863cc2021-01-08 22:42:39 +00001772 fi
Alex Bennéef48e5902020-03-16 17:21:48 +00001773fi
1774
Paolo Bonzinic4575b52022-09-29 12:41:58 +01001775if test "$container" != no; then
1776 echo "ENGINE=$container" >> $config_host_mak
Alex Bennée60f999b2023-02-28 19:06:46 +00001777 echo "RUNC=$runc" >> $config_host_mak
Paolo Bonzinic4575b52022-09-29 12:41:58 +01001778fi
Juan Quintela98ec69a2009-07-16 18:34:18 +02001779echo "ROMS=$roms" >> $config_host_mak
Juan Quintela804edf22009-07-27 16:12:49 +02001780echo "MAKE=$make" >> $config_host_mak
Blue Swirlc886edf2011-07-22 21:08:09 +00001781echo "PYTHON=$python" >> $config_host_mak
Alex Bennée39d87c82020-03-03 15:06:20 +00001782echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
Paolo Bonzinia5665052019-06-10 12:05:14 +02001783echo "MESON=$meson" >> $config_host_mak
Paolo Bonzini09e93322020-08-13 09:28:11 -04001784echo "NINJA=$ninja" >> $config_host_mak
Paolo Bonzini877c5562022-10-12 13:03:18 +02001785echo "PKG_CONFIG=${pkg_config}" >> $config_host_mak
Juan Quintela804edf22009-07-27 16:12:49 +02001786echo "CC=$cc" >> $config_host_mak
Juan Quintela804edf22009-07-27 16:12:49 +02001787echo "EXESUF=$EXESUF" >> $config_host_mak
Juan Quintela804edf22009-07-27 16:12:49 +02001788
Peter Maydell6efd7512011-11-30 11:59:04 +00001789# use included Linux headers
1790if test "$linux" = "yes" ; then
Andreas Färbera307beb2012-06-14 15:14:33 +00001791 mkdir -p linux-headers
Peter Maydell6efd7512011-11-30 11:59:04 +00001792 case "$cpu" in
Paolo Bonzini4da270b2021-11-09 09:36:10 +01001793 i386|x86_64)
Peter Maydell08312a62012-08-03 13:51:25 +01001794 linux_arch=x86
Peter Maydell6efd7512011-11-30 11:59:04 +00001795 ;;
Paolo Bonzinid8ff8922021-11-09 09:18:20 +01001796 ppc|ppc64)
Peter Maydell08312a62012-08-03 13:51:25 +01001797 linux_arch=powerpc
Peter Maydell6efd7512011-11-30 11:59:04 +00001798 ;;
1799 s390x)
Peter Maydell08312a62012-08-03 13:51:25 +01001800 linux_arch=s390
1801 ;;
Claudio Fontana1f080312013-06-12 16:20:23 +01001802 aarch64)
1803 linux_arch=arm64
1804 ;;
WANG Xueruidfcf9002021-12-21 13:41:04 +08001805 loongarch*)
1806 linux_arch=loongarch
1807 ;;
Sanjay Lal222e7d12014-06-17 23:10:36 +01001808 mips64)
1809 linux_arch=mips
1810 ;;
Peter Maydell08312a62012-08-03 13:51:25 +01001811 *)
1812 # For most CPUs the kernel architecture name and QEMU CPU name match.
1813 linux_arch="$cpu"
Peter Maydell6efd7512011-11-30 11:59:04 +00001814 ;;
1815 esac
Peter Maydell08312a62012-08-03 13:51:25 +01001816 # For non-KVM architectures we will not have asm headers
1817 if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
1818 symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
1819 fi
Peter Maydell6efd7512011-11-30 11:59:04 +00001820fi
1821
bellard1d14ffa2005-10-30 18:58:22 +00001822for target in $target_list; do
Paolo Bonzinifdb75ae2020-09-21 04:37:49 -04001823 target_dir="$target"
Philippe Mathieu-Daudé57a93f12021-11-09 15:45:04 +01001824 target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
Peter Maydell64708612022-08-25 16:06:59 +01001825 mkdir -p "$target_dir"
Paolo Bonzinifdb75ae2020-09-21 04:37:49 -04001826 case $target in
1827 *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
1828 *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
1829 esac
1830done
bellard7d132992003-03-06 23:23:54 +00001831
Paolo Bonzinifdb75ae2020-09-21 04:37:49 -04001832if test "$default_targets" = "yes"; then
1833 echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
1834fi
Peter Crosthwaitea540f152013-04-18 14:47:31 +10001835
John Snowfd0e6052015-03-25 18:57:39 -04001836if test "$ccache_cpp2" = "yes"; then
1837 echo "export CCACHE_CPP2=y" >> $config_host_mak
1838fi
1839
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001840# tests/tcg configuration
Paolo Bonzinib898bf22022-09-29 12:42:05 +01001841(config_host_mak=tests/tcg/config-host.mak
Paolo Bonzinid6743422022-09-29 12:42:00 +01001842mkdir -p tests/tcg
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001843echo "# Automatically generated by configure - do not modify" > $config_host_mak
1844echo "SRC_PATH=$source_path" >> $config_host_mak
1845echo "HOST_CC=$host_cc" >> $config_host_mak
1846
Alex Bennée48543dd2022-09-29 12:41:45 +01001847# versioned checked in the main config_host.mak above
1848if test -n "$gdb_bin"; then
1849 echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
1850fi
Paolo Bonzinid1d94d92022-10-27 19:36:32 +01001851if test "$plugins" = "yes" ; then
1852 echo "CONFIG_PLUGIN=y" >> $config_host_mak
1853fi
Alex Bennée48543dd2022-09-29 12:41:45 +01001854
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001855tcg_tests_targets=
1856for target in $target_list; do
1857 arch=${target%%-*}
1858
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001859 case $target in
Paolo Bonzinic48a5c42022-06-13 18:12:56 +01001860 xtensa*-linux-user)
1861 # the toolchain is not complete with headers, only build softmmu tests
1862 continue
1863 ;;
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001864 *-softmmu)
Peter Maydell64708612022-08-25 16:06:59 +01001865 test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || continue
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001866 qemu="qemu-system-$arch"
1867 ;;
1868 *-linux-user|*-bsd-user)
1869 qemu="qemu-$arch"
1870 ;;
1871 esac
1872
Alex Bennéefde10962022-10-11 12:34:16 +01001873 if probe_target_compiler $target || test -n "$container_image"; then
Paolo Bonzini0825cae2022-09-29 12:42:06 +01001874 test -n "$container_image" && build_static=y
Paolo Bonzinid6743422022-09-29 12:42:00 +01001875 mkdir -p "tests/tcg/$target"
Paolo Bonzinic7022a72022-09-29 12:42:07 +01001876 config_target_mak=tests/tcg/$target/config-target.mak
Paolo Bonzinid6743422022-09-29 12:42:00 +01001877 ln -sf "$source_path/tests/tcg/Makefile.target" "tests/tcg/$target/Makefile"
Paolo Bonzinic7022a72022-09-29 12:42:07 +01001878 echo "# Automatically generated by configure - do not modify" > "$config_target_mak"
1879 echo "TARGET_NAME=$arch" >> "$config_target_mak"
Paolo Bonzinia3e28f82022-09-29 12:41:59 +01001880 echo "TARGET=$target" >> "$config_target_mak"
Paolo Bonzinic7022a72022-09-29 12:42:07 +01001881 write_target_makefile "build-tcg-tests-$target" >> "$config_target_mak"
Paolo Bonzini15b273f2022-09-29 12:42:04 +01001882 echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
Paolo Bonzinic7022a72022-09-29 12:42:07 +01001883 echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
Alex Bennéebcbc36a2023-03-02 18:57:59 -08001884
1885 # will GDB work with these binaries?
1886 if test "${gdb_arches#*$arch}" != "$gdb_arches"; then
1887 echo "HOST_GDB_SUPPORTS_ARCH=y" >> "$config_target_mak"
1888 fi
1889
Paolo Bonzinib898bf22022-09-29 12:42:05 +01001890 echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs
Paolo Bonzinicd362de2022-05-27 16:35:48 +01001891 tcg_tests_targets="$tcg_tests_targets $target"
1892 fi
Paolo Bonzini2038f8c2019-08-07 16:35:23 +02001893done
Fabiano Rosasc0031d32023-01-20 15:48:22 -03001894
1895if test "$tcg" = "enabled"; then
1896 echo "TCG_TESTS_TARGETS=$tcg_tests_targets" >> config-host.mak
1897fi
1898)
Paolo Bonzini2038f8c2019-08-07 16:35:23 +02001899
Paolo Bonzinia5665052019-06-10 12:05:14 +02001900if test "$skip_meson" = no; then
Paolo Bonzinid77e90f2021-03-16 08:19:34 +01001901 cross="config-meson.cross.new"
1902 meson_quote() {
Paolo Bonziniac7ebcc2021-11-05 10:07:37 +01001903 test $# = 0 && return
Paolo Bonzini47b30832020-09-23 05:26:17 -04001904 echo "'$(echo $* | sed "s/ /','/g")'"
Paolo Bonzinid77e90f2021-03-16 08:19:34 +01001905 }
Marc-André Lureaufc929892019-07-13 01:47:54 +04001906
Paolo Bonzinid77e90f2021-03-16 08:19:34 +01001907 echo "# Automatically generated by configure - do not modify" > $cross
1908 echo "[properties]" >> $cross
Alex Bennéed1d5e9e2021-07-07 14:17:44 +01001909
1910 # unroll any custom device configs
Alex Bennée11bdcfc2021-07-21 00:26:38 +01001911 for a in $device_archs; do
1912 eval "c=\$devices_${a}"
1913 echo "${a}-softmmu = '$c'" >> $cross
1914 done
Alex Bennéed1d5e9e2021-07-07 14:17:44 +01001915
Paolo Bonzinid77e90f2021-03-16 08:19:34 +01001916 echo "[built-in options]" >> $cross
Paolo Bonzinia2866662021-11-05 10:09:26 +01001917 echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
1918 echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
Philippe Mathieu-Daudée910c7d2022-01-08 22:38:55 +01001919 test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
Paolo Bonzinia2866662021-11-05 10:09:26 +01001920 echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
1921 echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
Paolo Bonzinid77e90f2021-03-16 08:19:34 +01001922 echo "[binaries]" >> $cross
Paolo Bonzini4dba2782021-09-29 17:14:43 +02001923 echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
1924 test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
1925 test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
Paolo Bonzinid77e90f2021-03-16 08:19:34 +01001926 echo "ar = [$(meson_quote $ar)]" >> $cross
1927 echo "nm = [$(meson_quote $nm)]" >> $cross
Paolo Bonzini877c5562022-10-12 13:03:18 +02001928 echo "pkgconfig = [$(meson_quote $pkg_config)]" >> $cross
Paolo Bonzinid77e90f2021-03-16 08:19:34 +01001929 echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
1930 if has $sdl2_config; then
1931 echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
1932 fi
1933 echo "strip = [$(meson_quote $strip)]" >> $cross
Konstantin Kostiuk158bb222022-04-28 21:15:25 +03001934 echo "widl = [$(meson_quote $widl)]" >> $cross
Paolo Bonzinid77e90f2021-03-16 08:19:34 +01001935 echo "windres = [$(meson_quote $windres)]" >> $cross
Andrey Drobyshevf9f0e612022-11-29 19:38:08 +02001936 echo "windmc = [$(meson_quote $windmc)]" >> $cross
Paolo Bonzinid77e90f2021-03-16 08:19:34 +01001937 if test "$cross_compile" = "yes"; then
Marc-André Lureaufc929892019-07-13 01:47:54 +04001938 cross_arg="--cross-file config-meson.cross"
Marc-André Lureaufc929892019-07-13 01:47:54 +04001939 echo "[host_machine]" >> $cross
Paolo Bonziniba7c60c2021-11-08 14:47:54 +01001940 echo "system = '$targetos'" >> $cross
Paolo Bonzini823eb012021-11-08 14:18:17 +01001941 case "$cpu" in
Joelle van Dynef6bca9d2021-01-25 17:24:54 -08001942 i386)
Marc-André Lureaufc929892019-07-13 01:47:54 +04001943 echo "cpu_family = 'x86'" >> $cross
1944 ;;
Marc-André Lureaufc929892019-07-13 01:47:54 +04001945 *)
Paolo Bonzini823eb012021-11-08 14:18:17 +01001946 echo "cpu_family = '$cpu'" >> $cross
Marc-André Lureaufc929892019-07-13 01:47:54 +04001947 ;;
1948 esac
1949 echo "cpu = '$cpu'" >> $cross
1950 if test "$bigendian" = "yes" ; then
1951 echo "endian = 'big'" >> $cross
1952 else
1953 echo "endian = 'little'" >> $cross
1954 fi
Paolo Bonzinid77e90f2021-03-16 08:19:34 +01001955 else
Marc-André Lureaufc929892019-07-13 01:47:54 +04001956 cross_arg="--native-file config-meson.cross"
Paolo Bonzinid77e90f2021-03-16 08:19:34 +01001957 fi
1958 mv $cross config-meson.cross
Marc-André Lureaufc929892019-07-13 01:47:54 +04001959
Paolo Bonzinid77e90f2021-03-16 08:19:34 +01001960 rm -rf meson-private meson-info meson-logs
Paolo Bonzini0a31e3a2022-04-20 17:33:59 +02001961
Marc-André Lureau5a347a72023-03-02 17:18:46 +04001962 # Prevent meson from automatically downloading wrapped subprojects when missing.
1963 # You can use 'meson subprojects download' before running configure.
1964 meson_option_add "--wrap-mode=nodownload"
1965
Paolo Bonzini0a31e3a2022-04-20 17:33:59 +02001966 # Built-in options
1967 test "$bindir" != "bin" && meson_option_add "-Dbindir=$bindir"
1968 test "$default_feature" = no && meson_option_add -Dauto_features=disabled
Paolo Bonzinia0cbd2e2022-07-14 14:33:49 +02001969 test "$static" = yes && meson_option_add -Dprefer_static=true
Paolo Bonzini0a31e3a2022-04-20 17:33:59 +02001970 test "$pie" = no && meson_option_add -Db_pie=false
1971 test "$werror" = yes && meson_option_add -Dwerror=true
1972
1973 # QEMU options
Paolo Bonzini0a31e3a2022-04-20 17:33:59 +02001974 test "$cfi" != false && meson_option_add "-Dcfi=$cfi"
John Snow6b0cedc2023-05-10 23:54:28 -04001975 test "$docs" != auto && meson_option_add "-Ddocs=$docs"
Paolo Bonzini0a31e3a2022-04-20 17:33:59 +02001976 test "$fdt" != auto && meson_option_add "-Dfdt=$fdt"
1977 test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
1978 test "$qemu_suffix" != qemu && meson_option_add "-Dqemu_suffix=$qemu_suffix"
Paolo Bonzini0a31e3a2022-04-20 17:33:59 +02001979 test "$smbd" != '' && meson_option_add "-Dsmbd=$smbd"
1980 test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
Jagannathan Raman55116962022-06-13 16:26:24 -04001981 test "$vfio_user_server" != auto && meson_option_add "-Dvfio_user_server=$vfio_user_server"
Paolo Bonzini61d63092021-10-07 15:08:28 +02001982 run_meson() {
Paolo Bonzini0a31e3a2022-04-20 17:33:59 +02001983 NINJA=$ninja $meson setup --prefix "$prefix" "$@" $cross_arg "$PWD" "$source_path"
Paolo Bonzini61d63092021-10-07 15:08:28 +02001984 }
1985 eval run_meson $meson_options
Paolo Bonzinid77e90f2021-03-16 08:19:34 +01001986 if test "$?" -ne 0 ; then
1987 error_exit "meson setup failed"
1988 fi
Paolo Bonzini973038d2023-05-19 20:04:07 +02001989else
1990 if test -f meson-private/cmd_line.txt; then
1991 # Adjust old command line options that were removed
1992 # sed -i is not portable
1993 perl -i -ne '
1994 /^sphinx_build/ && next;
1995 print;' meson-private/cmd_line.txt
1996 fi
Paolo Bonzinia5665052019-06-10 12:05:14 +02001997fi
1998
Michael S. Tsirkindc655402014-03-09 17:37:49 +02001999# Save the configure command line for later reuse.
2000cat <<EOD >config.status
2001#!/bin/sh
2002# Generated by configure.
2003# Run this file to recreate the current configuration.
2004# Compiler output produced by configure, useful for debugging
2005# configure, is in config.log if it exists.
2006EOD
Daniel P. Berrangée811da72018-09-04 13:36:03 +01002007
2008preserve_env() {
2009 envname=$1
2010
2011 eval envval=\$$envname
2012
2013 if test -n "$envval"
2014 then
2015 echo "$envname='$envval'" >> config.status
2016 echo "export $envname" >> config.status
2017 else
2018 echo "unset $envname" >> config.status
2019 fi
2020}
2021
2022# Preserve various env variables that influence what
2023# features/build target configure will detect
2024preserve_env AR
2025preserve_env AS
2026preserve_env CC
Paolo Bonzini8009da02021-11-05 10:08:43 +01002027preserve_env CFLAGS
Daniel P. Berrangée811da72018-09-04 13:36:03 +01002028preserve_env CXX
Paolo Bonzini8009da02021-11-05 10:08:43 +01002029preserve_env CXXFLAGS
Daniel P. Berrangée811da72018-09-04 13:36:03 +01002030preserve_env LD
Paolo Bonzini8009da02021-11-05 10:08:43 +01002031preserve_env LDFLAGS
Daniel P. Berrangée811da72018-09-04 13:36:03 +01002032preserve_env LD_LIBRARY_PATH
Daniel P. Berrangée811da72018-09-04 13:36:03 +01002033preserve_env MAKE
2034preserve_env NM
Paolo Bonzinib5569e52022-06-07 12:14:47 +02002035preserve_env OBJCFLAGS
Daniel P. Berrangée811da72018-09-04 13:36:03 +01002036preserve_env OBJCOPY
2037preserve_env PATH
2038preserve_env PKG_CONFIG
2039preserve_env PKG_CONFIG_LIBDIR
2040preserve_env PKG_CONFIG_PATH
2041preserve_env PYTHON
Paolo Bonzini954ed682022-10-12 11:35:17 +02002042preserve_env QEMU_GA_MANUFACTURER
2043preserve_env QEMU_GA_DISTRO
2044preserve_env QEMU_GA_VERSION
Daniel P. Berrangée811da72018-09-04 13:36:03 +01002045preserve_env SDL2_CONFIG
2046preserve_env SMBD
2047preserve_env STRIP
Konstantin Kostiuk158bb222022-04-28 21:15:25 +03002048preserve_env WIDL
Daniel P. Berrangée811da72018-09-04 13:36:03 +01002049preserve_env WINDRES
Andrey Drobyshevf9f0e612022-11-29 19:38:08 +02002050preserve_env WINDMC
Daniel P. Berrangée811da72018-09-04 13:36:03 +01002051
Michael S. Tsirkindc655402014-03-09 17:37:49 +02002052printf "exec" >>config.status
Paolo Bonzinia5665052019-06-10 12:05:14 +02002053for i in "$0" "$@"; do
Paolo Bonzini835af892020-09-08 13:20:45 +02002054 test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
Paolo Bonzinia5665052019-06-10 12:05:14 +02002055done
Dr. David Alan Gilbertcf7cc922016-01-12 11:58:48 +00002056echo ' "$@"' >>config.status
Michael S. Tsirkindc655402014-03-09 17:37:49 +02002057chmod +x config.status
2058
Peter Maydell8cd05ab2014-05-23 17:07:24 +01002059rm -r "$TMPDIR1"