configure 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042
  1. #!/bin/sh
  2. #
  3. # qemu configure script (c) 2003 Fabrice Bellard
  4. #
  5. # Unset some variables known to interfere with behavior of common tools,
  6. # just as autoconf does. Unlike autoconf, we assume that unset exists.
  7. unset CLICOLOR_FORCE GREP_OPTIONS BASH_ENV ENV MAIL MAILPATH CDPATH
  8. # Don't allow CCACHE, if present, to use cached results of compile tests!
  9. export CCACHE_RECACHE=yes
  10. # make source path absolute
  11. source_path=$(cd "$(dirname -- "$0")"; pwd)
  12. if test "$PWD" -ef "$source_path"
  13. then
  14. echo "Using './build' as the directory for build output"
  15. MARKER=build/auto-created-by-configure
  16. if test -e build
  17. then
  18. if test -f $MARKER
  19. then
  20. rm -rf build
  21. else
  22. echo "ERROR: ./build dir already exists and was not previously created by configure"
  23. exit 1
  24. fi
  25. fi
  26. if ! mkdir build || ! touch $MARKER
  27. then
  28. echo "ERROR: Could not create ./build directory. Check the permissions on"
  29. echo "your source directory, or try doing an out-of-tree build."
  30. exit 1
  31. fi
  32. cat > GNUmakefile <<'EOF'
  33. # This file is auto-generated by configure to support in-source tree
  34. # 'make' command invocation
  35. build:
  36. @echo 'changing dir to build for $(MAKE) "$(MAKECMDGOALS)"...'
  37. @$(MAKE) -C build -f Makefile $(MAKECMDGOALS)
  38. @if test "$(MAKECMDGOALS)" = "distclean" && \
  39. test -e build/auto-created-by-configure ; \
  40. then \
  41. rm -rf build GNUmakefile ; \
  42. fi
  43. %: build
  44. @
  45. .PHONY: build
  46. GNUmakefile: ;
  47. EOF
  48. cd build
  49. exec "$source_path/configure" "$@"
  50. fi
  51. # Temporary directory used for files created while
  52. # configure runs. Since it is in the build directory
  53. # we can safely blow away any previous version of it
  54. # (and we need not jump through hoops to try to delete
  55. # it when configure exits.)
  56. TMPDIR1="config-temp"
  57. rm -rf "${TMPDIR1}"
  58. if ! mkdir -p "${TMPDIR1}"; then
  59. echo "ERROR: failed to create temporary directory"
  60. exit 1
  61. fi
  62. TMPB="qemu-conf"
  63. TMPC="${TMPDIR1}/${TMPB}.c"
  64. TMPO="${TMPDIR1}/${TMPB}.o"
  65. TMPE="${TMPDIR1}/${TMPB}.exe"
  66. rm -f config.log
  67. # Print a helpful header at the top of config.log
  68. echo "# QEMU configure log $(date)" >> config.log
  69. printf "# Configured with:" >> config.log
  70. # repeat the invocation to log and stdout for CI
  71. invoke=$(printf " '%s'" "$0" "$@")
  72. test -n "$GITLAB_CI" && echo "configuring with: $invoke"
  73. { echo "$invoke"; echo; echo "#"; } >> config.log
  74. quote_sh() {
  75. printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
  76. }
  77. error_exit() {
  78. (echo
  79. echo "ERROR: $1"
  80. while test -n "$2"; do
  81. echo " $2"
  82. shift
  83. done
  84. echo) >&2
  85. exit 1
  86. }
  87. do_compiler() {
  88. # Run the compiler, capturing its output to the log. First argument
  89. # is compiler binary to execute.
  90. compiler="$1"
  91. shift
  92. if test -n "$BASH_VERSION"; then eval '
  93. echo >>config.log "
  94. funcs: ${FUNCNAME[*]}
  95. lines: ${BASH_LINENO[*]}"
  96. '; fi
  97. echo $compiler "$@" >> config.log
  98. $compiler "$@" >> config.log 2>&1 || return $?
  99. }
  100. do_cc() {
  101. do_compiler "$cc" $CPU_CFLAGS "$@"
  102. }
  103. compile_object() {
  104. local_cflags="$1"
  105. do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -c -o $TMPO $TMPC
  106. }
  107. compile_prog() {
  108. local_cflags="$1"
  109. local_ldflags="$2"
  110. do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -o $TMPE $TMPC \
  111. $LDFLAGS $EXTRA_LDFLAGS $local_ldflags
  112. }
  113. # symbolically link $1 to $2. Portable version of "ln -sf".
  114. symlink() {
  115. rm -rf "$2"
  116. mkdir -p "$(dirname "$2")"
  117. ln -s "$1" "$2"
  118. }
  119. # check whether a command is available to this shell (may be either an
  120. # executable or a builtin)
  121. has() {
  122. type "$1" >/dev/null 2>&1
  123. }
  124. version_ge () {
  125. local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
  126. local_ver2=$(echo "$2" | tr . ' ')
  127. while true; do
  128. set x $local_ver1
  129. local_first=${2-0}
  130. # 'shift 2' if $2 is set, or 'shift' if $2 is not set
  131. shift ${2:+2}
  132. local_ver1=$*
  133. set x $local_ver2
  134. # the second argument finished, the first must be greater or equal
  135. test $# = 1 && return 0
  136. test $local_first -lt $2 && return 1
  137. test $local_first -gt $2 && return 0
  138. shift ${2:+2}
  139. local_ver2=$*
  140. done
  141. }
  142. if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
  143. then
  144. error_exit "main directory cannot contain spaces nor colons"
  145. fi
  146. # parse CC options first; some compiler tests are used to establish
  147. # some defaults, based on the host environment
  148. # default parameters
  149. container_engine="auto"
  150. cpu=""
  151. cross_compile="no"
  152. cross_prefix=""
  153. host_cc="cc"
  154. EXTRA_CFLAGS=""
  155. EXTRA_CXXFLAGS=""
  156. EXTRA_OBJCFLAGS=""
  157. EXTRA_LDFLAGS=""
  158. # Default value for a variable defining feature "foo".
  159. # * foo="no" feature will only be used if --enable-foo arg is given
  160. # * foo="" feature will be searched for, and if found, will be used
  161. # unless --disable-foo is given
  162. # * foo="yes" this value will only be set by --enable-foo flag.
  163. # feature will searched for,
  164. # if not found, configure exits with error
  165. #
  166. # Always add --enable-foo and --disable-foo command line args.
  167. # Distributions want to ensure that several features are compiled in, and it
  168. # is impossible without a --enable-foo that exits if a feature is not found.
  169. default_feature=""
  170. for opt do
  171. optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
  172. case "$opt" in
  173. --cross-prefix=*) cross_prefix="$optarg"
  174. cross_compile="yes"
  175. ;;
  176. --cc=*) CC="$optarg"
  177. ;;
  178. --cxx=*) CXX="$optarg"
  179. ;;
  180. --objcc=*) objcc="$optarg"
  181. ;;
  182. --rustc=*) RUSTC="$optarg"
  183. ;;
  184. --cpu=*) cpu="$optarg"
  185. ;;
  186. --extra-cflags=*)
  187. EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
  188. EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
  189. EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
  190. ;;
  191. --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
  192. ;;
  193. --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
  194. ;;
  195. --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
  196. ;;
  197. --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
  198. ;;
  199. --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
  200. eval "cross_cc_cflags_${cc_arch}=\$optarg"
  201. ;;
  202. --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
  203. eval "cross_cc_${cc_arch}=\$optarg"
  204. ;;
  205. --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-prefix-FOO option"
  206. ;;
  207. --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
  208. eval "cross_prefix_${cc_arch}=\$optarg"
  209. ;;
  210. --without-default-features) default_feature="no"
  211. ;;
  212. esac
  213. done
  214. default_cflags='-O2 -g'
  215. git_submodules_action="update"
  216. docs="auto"
  217. EXESUF=""
  218. system="yes"
  219. linux_user=""
  220. bsd_user=""
  221. plugins="$default_feature"
  222. subdirs=""
  223. ninja=""
  224. python=
  225. download="enabled"
  226. skip_meson=no
  227. use_containers="yes"
  228. rust="disabled"
  229. rust_target_triple=""
  230. gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
  231. gdb_arches=""
  232. # Don't accept a target_list environment variable.
  233. unset target_list
  234. unset target_list_exclude
  235. # The following Meson options are handled manually (still they
  236. # are included in the automatically generated help message)
  237. # because they automatically enable/disable other options
  238. tcg="auto"
  239. cfi="false"
  240. # Meson has PIE as a boolean rather than enabled/disabled/auto,
  241. # and we also need to check for -static-pie before Meson runs
  242. # which requires knowing whether --static is enabled.
  243. pie=""
  244. static="no"
  245. # Preferred compiler:
  246. # ${CC} (if set)
  247. # ${cross_prefix}gcc (if cross-prefix specified)
  248. # system compiler
  249. if test -z "${CC}${cross_prefix}"; then
  250. cc="cc"
  251. else
  252. cc="${CC-${cross_prefix}gcc}"
  253. fi
  254. if test -z "${CXX}${cross_prefix}"; then
  255. cxx="c++"
  256. else
  257. cxx="${CXX-${cross_prefix}g++}"
  258. fi
  259. # Preferred ObjC compiler:
  260. # $objcc (if set, i.e. via --objcc option)
  261. # ${cross_prefix}clang (if cross-prefix specified)
  262. # clang (if available)
  263. # $cc
  264. if test -z "${objcc}${cross_prefix}"; then
  265. if has clang; then
  266. objcc=clang
  267. else
  268. objcc="$cc"
  269. fi
  270. else
  271. objcc="${objcc-${cross_prefix}clang}"
  272. fi
  273. ar="${AR-${cross_prefix}ar}"
  274. as="${AS-${cross_prefix}as}"
  275. ccas="${CCAS-$cc}"
  276. dlltool="${DLLTOOL-${cross_prefix}dlltool}"
  277. objcopy="${OBJCOPY-${cross_prefix}objcopy}"
  278. ld="${LD-${cross_prefix}ld}"
  279. ranlib="${RANLIB-${cross_prefix}ranlib}"
  280. nm="${NM-${cross_prefix}nm}"
  281. readelf="${READELF-${cross_prefix}readelf}"
  282. strip="${STRIP-${cross_prefix}strip}"
  283. widl="${WIDL-${cross_prefix}widl}"
  284. windres="${WINDRES-${cross_prefix}windres}"
  285. windmc="${WINDMC-${cross_prefix}windmc}"
  286. pkg_config="${PKG_CONFIG-${cross_prefix}pkg-config}"
  287. sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
  288. rustc="${RUSTC-rustc}"
  289. check_define() {
  290. cat > $TMPC <<EOF
  291. #if !defined($1)
  292. #error $1 not defined
  293. #endif
  294. int main(void) { return 0; }
  295. EOF
  296. compile_object
  297. }
  298. write_c_skeleton() {
  299. cat > $TMPC <<EOF
  300. int main(void) { return 0; }
  301. EOF
  302. }
  303. if check_define __linux__ ; then
  304. host_os=linux
  305. elif check_define _WIN32 ; then
  306. host_os=windows
  307. elif check_define __OpenBSD__ ; then
  308. host_os=openbsd
  309. elif check_define __sun__ ; then
  310. host_os=sunos
  311. elif check_define __HAIKU__ ; then
  312. host_os=haiku
  313. elif check_define __FreeBSD__ ; then
  314. host_os=freebsd
  315. elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
  316. host_os=gnu/kfreebsd
  317. elif check_define __DragonFly__ ; then
  318. host_os=dragonfly
  319. elif check_define __NetBSD__; then
  320. host_os=netbsd
  321. elif check_define __APPLE__; then
  322. host_os=darwin
  323. else
  324. # This is a fatal error, but don't report it yet, because we
  325. # might be going to just print the --help text, or it might
  326. # be the result of a missing compiler.
  327. host_os=bogus
  328. fi
  329. if test ! -z "$cpu" ; then
  330. # command line argument
  331. :
  332. elif check_define __i386__ ; then
  333. cpu="i386"
  334. elif check_define __x86_64__ ; then
  335. if check_define __ILP32__ ; then
  336. cpu="x32"
  337. else
  338. cpu="x86_64"
  339. fi
  340. elif check_define __sparc__ ; then
  341. if check_define __arch64__ ; then
  342. cpu="sparc64"
  343. else
  344. cpu="sparc"
  345. fi
  346. elif check_define _ARCH_PPC ; then
  347. if check_define _ARCH_PPC64 ; then
  348. if check_define _LITTLE_ENDIAN ; then
  349. cpu="ppc64le"
  350. else
  351. cpu="ppc64"
  352. fi
  353. else
  354. cpu="ppc"
  355. fi
  356. elif check_define __mips__ ; then
  357. if check_define __mips64 ; then
  358. cpu="mips64"
  359. else
  360. cpu="mips"
  361. fi
  362. elif check_define __s390__ ; then
  363. if check_define __s390x__ ; then
  364. cpu="s390x"
  365. else
  366. cpu="s390"
  367. fi
  368. elif check_define __riscv ; then
  369. if check_define _LP64 ; then
  370. cpu="riscv64"
  371. else
  372. cpu="riscv32"
  373. fi
  374. elif check_define __arm__ ; then
  375. cpu="arm"
  376. elif check_define __aarch64__ ; then
  377. cpu="aarch64"
  378. elif check_define __loongarch64 ; then
  379. cpu="loongarch64"
  380. else
  381. # Using uname is really broken, but it is just a fallback for architectures
  382. # that are going to use TCI anyway
  383. cpu=$(uname -m)
  384. if test "$host_os" != "bogus"; then
  385. echo "WARNING: unrecognized host CPU, proceeding with 'uname -m' output '$cpu'"
  386. fi
  387. fi
  388. # Normalise host CPU name to the values used by Meson cross files and in source
  389. # directories, and set multilib cflags. The canonicalization isn't really
  390. # necessary, because the architectures that we check for should not hit the
  391. # 'uname -m' case, but better safe than sorry in case --cpu= is used.
  392. #
  393. # Note that this case should only have supported host CPUs, not guests.
  394. # Please keep it sorted and synchronized with meson.build's host_arch.
  395. host_arch=
  396. linux_arch=
  397. raw_cpu=$cpu
  398. case "$cpu" in
  399. aarch64)
  400. host_arch=aarch64
  401. linux_arch=arm64
  402. ;;
  403. armv*b|armv*l|arm)
  404. cpu=arm
  405. host_arch=arm
  406. linux_arch=arm
  407. ;;
  408. i386|i486|i586|i686)
  409. cpu="i386"
  410. host_arch=i386
  411. linux_arch=x86
  412. CPU_CFLAGS="-m32"
  413. ;;
  414. loongarch*)
  415. cpu=loongarch64
  416. host_arch=loongarch64
  417. linux_arch=loongarch
  418. ;;
  419. mips64*|mipsisa64*)
  420. cpu=mips64
  421. host_arch=mips
  422. linux_arch=mips
  423. ;;
  424. mips*)
  425. cpu=mips
  426. host_arch=mips
  427. linux_arch=mips
  428. ;;
  429. ppc)
  430. host_arch=ppc
  431. linux_arch=powerpc
  432. CPU_CFLAGS="-m32"
  433. ;;
  434. ppc64)
  435. host_arch=ppc64
  436. linux_arch=powerpc
  437. CPU_CFLAGS="-m64 -mbig-endian"
  438. ;;
  439. ppc64le)
  440. cpu=ppc64
  441. host_arch=ppc64
  442. linux_arch=powerpc
  443. CPU_CFLAGS="-m64 -mlittle-endian"
  444. ;;
  445. riscv32 | riscv64)
  446. host_arch=riscv
  447. linux_arch=riscv
  448. ;;
  449. s390)
  450. linux_arch=s390
  451. CPU_CFLAGS="-m31"
  452. ;;
  453. s390x)
  454. host_arch=s390x
  455. linux_arch=s390
  456. CPU_CFLAGS="-m64"
  457. ;;
  458. sparc|sun4[cdmuv])
  459. cpu=sparc
  460. CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc"
  461. ;;
  462. sparc64)
  463. host_arch=sparc64
  464. CPU_CFLAGS="-m64 -mcpu=ultrasparc"
  465. ;;
  466. x32)
  467. cpu="x86_64"
  468. host_arch=x86_64
  469. linux_arch=x86
  470. CPU_CFLAGS="-mx32"
  471. ;;
  472. x86_64|amd64)
  473. cpu="x86_64"
  474. host_arch=x86_64
  475. linux_arch=x86
  476. CPU_CFLAGS="-m64"
  477. ;;
  478. esac
  479. if test -n "$host_arch" && {
  480. ! test -d "$source_path/linux-user/include/host/$host_arch" ||
  481. ! test -d "$source_path/common-user/host/$host_arch"; }; then
  482. error_exit "linux-user/include/host/$host_arch does not exist." \
  483. "This is a bug in the configure script, please report it."
  484. fi
  485. if test -n "$linux_arch" && ! test -d "$source_path/linux-headers/asm-$linux_arch"; then
  486. error_exit "linux-headers/asm-$linux_arch does not exist." \
  487. "This is a bug in the configure script, please report it."
  488. fi
  489. check_py_version() {
  490. # We require python >= 3.8.
  491. # NB: a True python conditional creates a non-zero return code (Failure)
  492. "$1" -c 'import sys; sys.exit(sys.version_info < (3,8))'
  493. }
  494. first_python=
  495. if test -z "${PYTHON}"; then
  496. # A bare 'python' is traditionally python 2.x, but some distros
  497. # have it as python 3.x, so check in both places.
  498. for binary in python3 python python3.12 python3.11 \
  499. python3.10 python3.9 python3.8; do
  500. if has "$binary"; then
  501. python=$(command -v "$binary")
  502. if check_py_version "$python"; then
  503. # This one is good.
  504. first_python=
  505. break
  506. else
  507. first_python=$python
  508. fi
  509. fi
  510. done
  511. else
  512. # Same as above, but only check the environment variable.
  513. has "${PYTHON}" || error_exit "The PYTHON environment variable does not point to an executable"
  514. python=$(command -v "$PYTHON")
  515. if check_py_version "$python"; then
  516. # This one is good.
  517. first_python=
  518. else
  519. first_python=$first_python
  520. fi
  521. fi
  522. # Check for ancillary tools used in testing
  523. genisoimage=
  524. for binary in genisoimage mkisofs
  525. do
  526. if has $binary
  527. then
  528. genisoimage=$(command -v "$binary")
  529. break
  530. fi
  531. done
  532. if test "$host_os" = "windows" ; then
  533. EXESUF=".exe"
  534. fi
  535. meson_option_build_array() {
  536. printf '['
  537. (if test "$host_os" = windows; then
  538. IFS=\;
  539. else
  540. IFS=:
  541. fi
  542. for e in $1; do
  543. printf '"""'
  544. # backslash escape any '\' and '"' characters
  545. printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g'
  546. printf '""",'
  547. done)
  548. printf ']\n'
  549. }
  550. . "$source_path/scripts/meson-buildoptions.sh"
  551. meson_options=
  552. meson_option_add() {
  553. local arg
  554. for arg; do
  555. meson_options="$meson_options $(quote_sh "$arg")"
  556. done
  557. }
  558. meson_option_parse() {
  559. meson_options="$meson_options $(_meson_option_parse "$@")"
  560. if test $? -eq 1; then
  561. echo "ERROR: unknown option $1"
  562. echo "Try '$0 --help' for more information"
  563. exit 1
  564. fi
  565. }
  566. has_meson_option() {
  567. test "${meson_options#*"$1"}" != "$meson_options"
  568. }
  569. meson_add_machine_file() {
  570. if test "$cross_compile" = "yes"; then
  571. meson_option_add --cross-file "$1"
  572. else
  573. meson_option_add --native-file "$1"
  574. fi
  575. }
  576. for opt do
  577. optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
  578. case "$opt" in
  579. --help|-h) show_help=yes
  580. ;;
  581. --version|-V) exec cat "$source_path/VERSION"
  582. ;;
  583. --cross-prefix=*)
  584. ;;
  585. --cc=*)
  586. ;;
  587. --host-cc=*) host_cc="$optarg"
  588. ;;
  589. --cxx=*)
  590. ;;
  591. --objcc=*)
  592. ;;
  593. --rustc=*)
  594. ;;
  595. --make=*)
  596. ;;
  597. --install=*)
  598. ;;
  599. --python=*) python="$optarg"
  600. ;;
  601. --skip-meson) skip_meson=yes
  602. ;;
  603. --ninja=*) ninja="$optarg"
  604. ;;
  605. --extra-cflags=*)
  606. ;;
  607. --extra-cxxflags=*)
  608. ;;
  609. --extra-objcflags=*)
  610. ;;
  611. --extra-ldflags=*)
  612. ;;
  613. --cross-cc-*)
  614. ;;
  615. --cross-prefix-*)
  616. ;;
  617. --enable-docs) docs=enabled
  618. ;;
  619. --disable-docs) docs=disabled
  620. ;;
  621. --cpu=*)
  622. ;;
  623. --target-list=*) target_list="$optarg"
  624. if test "$target_list_exclude"; then
  625. error_exit "Can't mix --target-list with --target-list-exclude"
  626. fi
  627. ;;
  628. --target-list-exclude=*) target_list_exclude="$optarg"
  629. if test "$target_list"; then
  630. error_exit "Can't mix --target-list-exclude with --target-list"
  631. fi
  632. ;;
  633. --with-default-devices) meson_option_add -Ddefault_devices=true
  634. ;;
  635. --without-default-devices) meson_option_add -Ddefault_devices=false
  636. ;;
  637. --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
  638. ;;
  639. --with-devices-*) device_arch=${opt#--with-devices-};
  640. device_arch=${device_arch%%=*}
  641. cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
  642. if test -f "$cf"; then
  643. device_archs="$device_archs $device_arch"
  644. eval "devices_${device_arch}=\$optarg"
  645. else
  646. error_exit "File $cf does not exist"
  647. fi
  648. ;;
  649. --without-default-features) # processed above
  650. ;;
  651. --static) static="yes"
  652. ;;
  653. --host=*|--build=*|\
  654. --disable-dependency-tracking|\
  655. --sbindir=*|--sharedstatedir=*|\
  656. --oldincludedir=*|--datarootdir=*|--infodir=*|\
  657. --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
  658. # These switches are silently ignored, for compatibility with
  659. # autoconf-generated configure scripts. This allows QEMU's
  660. # configure to be used by RPM and similar macros that set
  661. # lots of directory switches by default.
  662. ;;
  663. --enable-debug)
  664. # Enable debugging options that aren't excessively noisy
  665. meson_option_parse --enable-debug-tcg ""
  666. meson_option_parse --enable-debug-graph-lock ""
  667. meson_option_parse --enable-debug-mutex ""
  668. meson_option_add -Doptimization=0
  669. default_cflags='-O0 -g'
  670. ;;
  671. --disable-tcg) tcg="disabled"
  672. ;;
  673. --enable-tcg) tcg="enabled"
  674. ;;
  675. --disable-system) system="no"
  676. ;;
  677. --enable-system) system="yes"
  678. ;;
  679. --disable-user)
  680. linux_user="no" ;
  681. bsd_user="no" ;
  682. ;;
  683. --enable-user) ;;
  684. --disable-linux-user) linux_user="no"
  685. ;;
  686. --enable-linux-user) linux_user="yes"
  687. ;;
  688. --disable-bsd-user) bsd_user="no"
  689. ;;
  690. --enable-bsd-user) bsd_user="yes"
  691. ;;
  692. --enable-pie) pie="yes"
  693. ;;
  694. --disable-pie) pie="no"
  695. ;;
  696. --enable-cfi) cfi=true
  697. ;;
  698. --disable-cfi) cfi=false
  699. ;;
  700. --disable-download) download="disabled"; git_submodules_action=validate;
  701. ;;
  702. --enable-download) download="enabled"; git_submodules_action=update;
  703. ;;
  704. --enable-plugins) plugins="yes"
  705. ;;
  706. --disable-plugins) plugins="no"
  707. ;;
  708. --enable-containers) use_containers="yes"
  709. ;;
  710. --disable-containers) use_containers="no"
  711. ;;
  712. --container-engine=*) container_engine="$optarg"
  713. ;;
  714. --rust-target-triple=*) rust_target_triple="$optarg"
  715. ;;
  716. --gdb=*) gdb_bin="$optarg"
  717. ;;
  718. --enable-rust) rust=enabled
  719. ;;
  720. --disable-rust) rust=disabled
  721. ;;
  722. # everything else has the same name in configure and meson
  723. --*) meson_option_parse "$opt" "$optarg"
  724. ;;
  725. # Pass through -Dxxxx options to meson
  726. -D*) meson_option_add "$opt"
  727. ;;
  728. esac
  729. done
  730. if ! test -e "$source_path/.git"
  731. then
  732. git_submodules_action="validate"
  733. fi
  734. if ! test -f "$source_path/subprojects/keycodemapdb/README" \
  735. && test "$download" = disabled
  736. then
  737. echo
  738. echo "ERROR: missing subprojects"
  739. echo
  740. if test -e "$source_path/.git"; then
  741. echo "--disable-download specified but subprojects were not"
  742. echo 'checked out. Please invoke "meson subprojects download"'
  743. echo "before configuring QEMU, or remove --disable-download"
  744. echo "from the command line."
  745. else
  746. echo "This is not a GIT checkout but subproject content appears to"
  747. echo "be missing. Do not use 'git archive' or GitHub download links"
  748. echo "to acquire QEMU source archives. Non-GIT builds are only"
  749. echo "supported with source archives linked from:"
  750. echo
  751. echo " https://www.qemu.org/download/#source"
  752. echo
  753. echo "Developers working with GIT can use scripts/archive-source.sh"
  754. echo "if they need to create valid source archives."
  755. fi
  756. echo
  757. exit 1
  758. fi
  759. default_target_list=""
  760. mak_wilds=""
  761. if [ -n "$host_arch" ] && [ -d "$source_path/common-user/host/$host_arch" ]; then
  762. if [ "$linux_user" != no ]; then
  763. if [ "$host_os" = linux ]; then
  764. linux_user=yes
  765. elif [ "$linux_user" = yes ]; then
  766. error_exit "linux-user not supported on this architecture"
  767. fi
  768. if [ "$linux_user" = "yes" ]; then
  769. mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
  770. fi
  771. fi
  772. if [ "$bsd_user" != no ]; then
  773. if [ "$bsd_user" = "" ]; then
  774. test $host_os = freebsd && bsd_user=yes
  775. fi
  776. if [ "$bsd_user" = yes ] && ! [ -d "$source_path/bsd-user/$host_os" ]; then
  777. error_exit "bsd-user not supported on this host OS"
  778. fi
  779. if [ "$bsd_user" = "yes" ]; then
  780. mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
  781. fi
  782. fi
  783. else
  784. if [ "$linux_user" = yes ] || [ "$bsd_user" = yes ]; then
  785. error_exit "user mode emulation not supported on this architecture"
  786. fi
  787. fi
  788. if [ "$system" = "yes" ]; then
  789. mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
  790. fi
  791. for config in $mak_wilds; do
  792. target="$(basename "$config" .mak)"
  793. if echo "$target_list_exclude" | grep -vq "$target"; then
  794. default_target_list="${default_target_list} $target"
  795. fi
  796. done
  797. if test x"$show_help" = x"yes" ; then
  798. cat << EOF
  799. Usage: configure [options]
  800. Options: [defaults in brackets after descriptions]
  801. Standard options:
  802. --help print this message
  803. --target-list=LIST set target list (default: build all)
  804. $(echo Available targets: $default_target_list | \
  805. fold -s -w 53 | sed -e 's/^/ /')
  806. --target-list-exclude=LIST exclude a set of targets from the default target-list
  807. Advanced options (experts only):
  808. -Dmesonoptname=val passthrough option to meson unmodified
  809. --cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
  810. --cc=CC use C compiler CC [$cc]
  811. --host-cc=CC when cross compiling, use C compiler CC for code run
  812. at build time [$host_cc]
  813. --cxx=CXX use C++ compiler CXX [$cxx]
  814. --objcc=OBJCC use Objective-C compiler OBJCC [$objcc]
  815. --rustc=RUSTC use Rust compiler RUSTC [$rustc]
  816. --extra-cflags=CFLAGS append extra C compiler flags CFLAGS
  817. --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
  818. --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
  819. --extra-ldflags=LDFLAGS append extra linker flags LDFLAGS
  820. --cross-cc-ARCH=CC use compiler when building ARCH guest test cases
  821. --cross-cc-cflags-ARCH= use compiler flags when building ARCH guest tests
  822. --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
  823. --python=PYTHON use specified python [$python]
  824. --ninja=NINJA use specified ninja [$ninja]
  825. --static enable static build [$static]
  826. --rust-target-triple=TRIPLE compilation target for Rust code [autodetect]
  827. --without-default-features default all --enable-* options to "disabled"
  828. --without-default-devices do not include any device that is not needed to
  829. start the emulator (only use if you are including
  830. desired devices in configs/devices/)
  831. --with-devices-ARCH=NAME override default configs/devices
  832. --enable-debug enable common debug build options
  833. --cpu=CPU Build for host CPU [$cpu]
  834. --disable-containers don't use containers for cross-building
  835. --container-engine=TYPE which container engine to use [$container_engine]
  836. --gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
  837. EOF
  838. meson_options_help
  839. cat << EOF
  840. system all system emulation targets
  841. user supported user emulation targets
  842. linux-user all linux usermode emulation targets
  843. bsd-user all BSD usermode emulation targets
  844. pie Position Independent Executables
  845. NOTE: The object files are built at the place where configure is launched
  846. EOF
  847. exit 0
  848. fi
  849. # Now that we are sure that the user did not only want to print the --help
  850. # information, we should double-check that the C compiler really works:
  851. write_c_skeleton
  852. if ! compile_object ; then
  853. error_exit "C compiler \"$cc\" either does not exist or does not work."
  854. fi
  855. # Remove old dependency files to make sure that they get properly regenerated
  856. rm -f ./*/config-devices.mak.d
  857. if test -z "$python"
  858. then
  859. # If first_python is set, there was a binary somewhere even though
  860. # it was not suitable. Use it for the error message.
  861. if test -n "$first_python"; then
  862. error_exit "Cannot use '$first_python', Python >= 3.8 is required." \
  863. "Use --python=/path/to/python to specify a supported Python."
  864. else
  865. error_exit "Python not found. Use --python=/path/to/python"
  866. fi
  867. fi
  868. if ! check_py_version "$python"; then
  869. error_exit "Cannot use '$python', Python >= 3.8 is required." \
  870. "Use --python=/path/to/python to specify a supported Python." \
  871. "Maybe try:" \
  872. " openSUSE Leap 15.3+: zypper install python39" \
  873. " CentOS 8: dnf install python38"
  874. fi
  875. # Resolve PATH
  876. python="$(command -v "$python")"
  877. # Create a Python virtual environment using our configured python.
  878. # The stdout of this script will be the location of a symlink that
  879. # points to the configured Python.
  880. # Entry point scripts for pip, meson, and sphinx are generated if those
  881. # packages are present.
  882. # Defaults assumed for now:
  883. # - venv is cleared if it exists already;
  884. # - venv is allowed to use system packages;
  885. # - all setup can be performed offline;
  886. # - missing packages may be fetched from PyPI,
  887. # unless --disable-download is passed.
  888. # - pip is not installed into the venv when possible,
  889. # but ensurepip is called as a fallback when necessary.
  890. echo "python determined to be '$python'"
  891. echo "python version: $($python --version)"
  892. python="$($python -B "${source_path}/python/scripts/mkvenv.py" create pyvenv)"
  893. if test "$?" -ne 0 ; then
  894. error_exit "python venv creation failed"
  895. fi
  896. # Suppress writing compiled files
  897. python="$python -B"
  898. mkvenv="$python ${source_path}/python/scripts/mkvenv.py"
  899. # Finish preparing the virtual environment using vendored .whl files
  900. $mkvenv ensuregroup --dir "${source_path}/python/wheels" \
  901. ${source_path}/pythondeps.toml meson || exit 1
  902. # At this point, we expect Meson to be installed and available.
  903. # We expect mkvenv or pip to have created pyvenv/bin/meson for us.
  904. # We ignore PATH completely here: we want to use the venv's Meson
  905. # *exclusively*.
  906. meson="$(cd pyvenv/bin; pwd)/meson"
  907. # Conditionally ensure Sphinx is installed.
  908. mkvenv_online_flag=""
  909. if test "$download" = "enabled" ; then
  910. mkvenv_online_flag=" --online"
  911. fi
  912. if test "$docs" != "disabled" ; then
  913. if ! $mkvenv ensuregroup \
  914. $(test "$docs" = "enabled" && echo "$mkvenv_online_flag") \
  915. ${source_path}/pythondeps.toml docs;
  916. then
  917. if test "$docs" = "enabled" ; then
  918. exit 1
  919. fi
  920. echo "Sphinx not found/usable, disabling docs."
  921. docs=disabled
  922. else
  923. docs=enabled
  924. fi
  925. fi
  926. # Probe for ninja
  927. if test -z "$ninja"; then
  928. for c in ninja ninja-build samu; do
  929. if has $c; then
  930. ninja=$(command -v "$c")
  931. break
  932. fi
  933. done
  934. if test -z "$ninja"; then
  935. error_exit "Cannot find Ninja"
  936. fi
  937. fi
  938. if test "$host_os" = "bogus"; then
  939. # Now that we know that we're not printing the help and that
  940. # the compiler works (so the results of the check_defines we used
  941. # to identify the OS are reliable), if we didn't recognize the
  942. # host OS we should stop now.
  943. error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
  944. fi
  945. # test for any invalid configuration combinations
  946. if test "$host_os" = "windows" && ! has "$dlltool"; then
  947. if test "$plugins" = "yes"; then
  948. error_exit "TCG plugins requires dlltool to build on Windows platforms"
  949. fi
  950. plugins="no"
  951. fi
  952. if test "$tcg" = "disabled" ; then
  953. if test "$plugins" = "yes"; then
  954. error_exit "Can't enable plugins on non-TCG builds"
  955. fi
  956. plugins="no"
  957. fi
  958. if test "$static" = "yes" ; then
  959. if test "$plugins" = "yes"; then
  960. error_exit "static and plugins are mutually incompatible"
  961. fi
  962. plugins="no"
  963. fi
  964. if test "$plugins" != "no"; then
  965. if has_meson_option "-Dtcg_interpreter=true"; then
  966. plugins="no"
  967. else
  968. plugins=yes
  969. fi
  970. fi
  971. cat > $TMPC << EOF
  972. #ifdef __linux__
  973. # define THREAD __thread
  974. #else
  975. # define THREAD
  976. #endif
  977. static THREAD int tls_var;
  978. int main(void) { return tls_var; }
  979. EOF
  980. if test "$host_os" = windows || test "$host_os" = haiku; then
  981. if test "$pie" = "yes"; then
  982. error_exit "PIE not available due to missing OS support"
  983. fi
  984. pie=no
  985. fi
  986. if test "$pie" != "no"; then
  987. if test "$static" = "yes"; then
  988. pie_ldflags=-static-pie
  989. else
  990. pie_ldflags=-pie
  991. fi
  992. if compile_prog "-Werror -fPIE -DPIE" "$pie_ldflags"; then
  993. pie="yes"
  994. elif test "$pie" = "yes"; then
  995. error_exit "-static-pie not available due to missing toolchain support"
  996. else
  997. echo "Disabling PIE due to missing toolchain support"
  998. pie="no"
  999. fi
  1000. fi
  1001. ##########################################
  1002. if test -z "${target_list+xxx}" ; then
  1003. default_targets=yes
  1004. for target in $default_target_list; do
  1005. target_list="$target_list $target"
  1006. done
  1007. target_list="${target_list# }"
  1008. else
  1009. default_targets=no
  1010. target_list=$(echo "$target_list" | sed -e 's/,/ /g')
  1011. for target in $target_list; do
  1012. # Check that we recognised the target name; this allows a more
  1013. # friendly error message than if we let it fall through.
  1014. case " $default_target_list " in
  1015. *" $target "*)
  1016. ;;
  1017. *)
  1018. error_exit "Unknown target name '$target'"
  1019. ;;
  1020. esac
  1021. done
  1022. fi
  1023. if test "$tcg" = "auto"; then
  1024. if test -z "$target_list"; then
  1025. tcg="disabled"
  1026. else
  1027. tcg="enabled"
  1028. fi
  1029. fi
  1030. #########################################
  1031. # gdb test
  1032. if test -n "$gdb_bin"; then
  1033. gdb_version_string=$($gdb_bin --version | head -n 1)
  1034. # Extract last field in the version string
  1035. gdb_version=${gdb_version_string##* }
  1036. if version_ge $gdb_version 9.1; then
  1037. gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
  1038. else
  1039. gdb_bin=""
  1040. fi
  1041. fi
  1042. ##########################################
  1043. # big/little endian test
  1044. cat > $TMPC << EOF
  1045. #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  1046. # error LITTLE
  1047. #endif
  1048. int main(void) { return 0; }
  1049. EOF
  1050. if ! compile_prog ; then
  1051. bigendian="no"
  1052. else
  1053. cat > $TMPC << EOF
  1054. #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  1055. # error BIG
  1056. #endif
  1057. int main(void) { return 0; }
  1058. EOF
  1059. if ! compile_prog ; then
  1060. bigendian="yes"
  1061. else
  1062. echo big/little test failed
  1063. exit 1
  1064. fi
  1065. fi
  1066. ##########################################
  1067. # detect rust triple
  1068. if test "$rust" != disabled && has "$rustc" && $rustc -vV > "${TMPDIR1}/${TMPB}.out"; then
  1069. rust_host_triple=$(sed -n 's/^host: //p' "${TMPDIR1}/${TMPB}.out")
  1070. else
  1071. if test "$rust" = enabled; then
  1072. error_exit "could not execute rustc binary \"$rustc\""
  1073. fi
  1074. rust=disabled
  1075. fi
  1076. if test "$rust" != disabled && test -z "$rust_target_triple"; then
  1077. # arch and os generally matches between meson and rust
  1078. rust_arch=$host_arch
  1079. rust_os=$host_os
  1080. rust_machine=unknown
  1081. rust_osvariant=
  1082. # tweak rust_os if needed; also, machine and variant depend on the OS
  1083. android=no
  1084. case "$host_os" in
  1085. darwin)
  1086. # e.g. aarch64-apple-darwin
  1087. rust_machine=apple
  1088. ;;
  1089. linux)
  1090. # detect android/glibc/musl
  1091. if check_define __ANDROID__; then
  1092. rust_osvariant=android
  1093. android=yes
  1094. else
  1095. cat > $TMPC << EOF
  1096. #define _GNU_SOURCE
  1097. #include <features.h>
  1098. #ifndef __USE_GNU
  1099. error using musl
  1100. #endif
  1101. EOF
  1102. if compile_object; then
  1103. rust_osvariant=gnu
  1104. else
  1105. rust_osvariant=musl
  1106. fi
  1107. fi
  1108. case "$cpu" in
  1109. arm)
  1110. # e.g. arm-unknown-linux-gnueabi, arm-unknown-linux-gnueabihf
  1111. write_c_skeleton
  1112. compile_object
  1113. if $READELF -A $TMPO | grep Tag_API_VFP_args: > /dev/null; then
  1114. rust_osvariant=${rust_osvariant}eabihf
  1115. else
  1116. rust_osvariant=${rust_osvariant}eabi
  1117. fi
  1118. ;;
  1119. mips64)
  1120. # e.g. mips64-unknown-linux-gnuabi64
  1121. rust_osvariant=${rust_osvariant}abi64
  1122. ;;
  1123. esac
  1124. ;;
  1125. netbsd)
  1126. # e.g. arm-unknown-netbsd-eabihf
  1127. test "$host_arch" = arm && rust_osvariant=eabihf
  1128. ;;
  1129. sunos)
  1130. rust_machine=pc
  1131. rust_os=solaris
  1132. ;;
  1133. windows)
  1134. # e.g. aarch64-pc-windows-gnullvm, x86_64-pc-windows-gnu (MSVC not supported)
  1135. rust_machine=pc
  1136. if test "$host_arch" = aarch64; then
  1137. rust_osvariant=gnullvm
  1138. else
  1139. rust_osvariant=gnu
  1140. fi
  1141. ;;
  1142. esac
  1143. # now tweak the architecture part, possibly based on pre-canonicalization --cpu
  1144. case "$host_arch" in
  1145. arm)
  1146. # preserve ISA version (armv7 etc.) from $raw_cpu if passed via --cpu
  1147. rust_arch=$raw_cpu
  1148. test "$rust_arch" = arm && test "$rust_os" != linux && rust_arch=armv7
  1149. ;;
  1150. mips)
  1151. # preserve ISA version (mipsisa64r6 etc.) and include endianness
  1152. rust_arch=${raw_cpu%el}
  1153. test "$bigendian" = no && rust_arch=${rust_arch}el
  1154. ;;
  1155. riscv32|riscv64)
  1156. # e.g. riscv64gc-unknown-linux-gnu, but riscv64-linux-android
  1157. test "$android" = no && rust_arch=${rust_arch}gc
  1158. ;;
  1159. sparc64)
  1160. if test "$rust_os" = solaris; then
  1161. rust_arch=sparcv9
  1162. rust_machine=sun
  1163. fi
  1164. ;;
  1165. x86_64)
  1166. # e.g. x86_64-unknown-linux-gnux32
  1167. test "$raw_cpu" = x32 && rust_osvariant=${rust_osvariant}x32
  1168. ;;
  1169. esac
  1170. if test "$android" = yes; then
  1171. # e.g. aarch64-linux-android
  1172. rust_target_triple=$rust_arch-$rust_os-$rust_osvariant
  1173. else
  1174. rust_target_triple=$rust_arch-$rust_machine-$rust_os${rust_osvariant:+-$rust_osvariant}
  1175. fi
  1176. fi
  1177. ##########################################
  1178. # functions to probe cross compilers
  1179. container="no"
  1180. runc=""
  1181. if test $use_containers = "yes" && (has "docker" || has "podman"); then
  1182. case $($python "$source_path"/tests/docker/docker.py --engine "$container_engine" probe) in
  1183. *docker) container=docker ;;
  1184. podman) container=podman ;;
  1185. no) container=no ;;
  1186. esac
  1187. if test "$container" != "no"; then
  1188. docker_py="$python $source_path/tests/docker/docker.py --engine $container"
  1189. runc=$container
  1190. fi
  1191. fi
  1192. # cross compilers defaults, can be overridden with --cross-cc-ARCH
  1193. : ${cross_prefix_aarch64="aarch64-linux-gnu-"}
  1194. : ${cross_prefix_aarch64_be="$cross_prefix_aarch64"}
  1195. : ${cross_prefix_alpha="alpha-linux-gnu-"}
  1196. : ${cross_prefix_arm="arm-linux-gnueabihf-"}
  1197. : ${cross_prefix_armeb="$cross_prefix_arm"}
  1198. : ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
  1199. : ${cross_prefix_loongarch64="loongarch64-unknown-linux-gnu-"}
  1200. : ${cross_prefix_hppa="hppa-linux-gnu-"}
  1201. : ${cross_prefix_i386="i686-linux-gnu-"}
  1202. : ${cross_prefix_m68k="m68k-linux-gnu-"}
  1203. : ${cross_prefix_microblaze="microblaze-linux-musl-"}
  1204. : ${cross_prefix_mips64el="mips64el-linux-gnuabi64-"}
  1205. : ${cross_prefix_mips64="mips64-linux-gnuabi64-"}
  1206. : ${cross_prefix_mipsel="mipsel-linux-gnu-"}
  1207. : ${cross_prefix_mips="mips-linux-gnu-"}
  1208. : ${cross_prefix_ppc="powerpc-linux-gnu-"}
  1209. : ${cross_prefix_ppc64="powerpc64-linux-gnu-"}
  1210. : ${cross_prefix_ppc64le="$cross_prefix_ppc64"}
  1211. : ${cross_prefix_riscv64="riscv64-linux-gnu-"}
  1212. : ${cross_prefix_s390x="s390x-linux-gnu-"}
  1213. : ${cross_prefix_sh4="sh4-linux-gnu-"}
  1214. : ${cross_prefix_sparc64="sparc64-linux-gnu-"}
  1215. : ${cross_prefix_sparc="$cross_prefix_sparc64"}
  1216. : ${cross_prefix_tricore="tricore-"}
  1217. : ${cross_prefix_x86_64="x86_64-linux-gnu-"}
  1218. : ${cross_cc_aarch64_be="$cross_cc_aarch64"}
  1219. : ${cross_cc_cflags_aarch64_be="-mbig-endian"}
  1220. : ${cross_cc_armeb="$cross_cc_arm"}
  1221. : ${cross_cc_cflags_armeb="-mbig-endian"}
  1222. : ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
  1223. : ${cross_cc_cflags_hexagon="-mv73 -O2 -static"}
  1224. : ${cross_cc_cflags_i386="-m32"}
  1225. : ${cross_cc_cflags_ppc="-m32 -mbig-endian"}
  1226. : ${cross_cc_cflags_ppc64="-m64 -mbig-endian"}
  1227. : ${cross_cc_ppc64le="$cross_cc_ppc64"}
  1228. : ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"}
  1229. : ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
  1230. : ${cross_cc_sparc="$cross_cc_sparc64"}
  1231. : ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
  1232. : ${cross_cc_cflags_x86_64="-m64 -mcx16"}
  1233. compute_target_variable() {
  1234. eval "$2="
  1235. if eval test -n "\"\${cross_prefix_$1}\""; then
  1236. if eval has "\"\${cross_prefix_$1}\$3\""; then
  1237. eval "$2=\"\${cross_prefix_$1}\$3\""
  1238. fi
  1239. fi
  1240. }
  1241. have_target() {
  1242. for i; do
  1243. case " $target_list " in
  1244. *" $i "*) return 0;;
  1245. *) ;;
  1246. esac
  1247. done
  1248. return 1
  1249. }
  1250. # probe_target_compiler TARGET
  1251. #
  1252. # Look for a compiler for the given target, either native or cross.
  1253. # Set variables target_* if a compiler is found, and container_cross_*
  1254. # if a Docker-based cross-compiler image is known for the target.
  1255. # Set got_cross_cc to yes/no depending on whether a non-container-based
  1256. # compiler was found.
  1257. #
  1258. # If TARGET is a user-mode emulation target, also set build_static to
  1259. # "y" if static linking is possible.
  1260. #
  1261. probe_target_compiler() {
  1262. # reset all output variables
  1263. got_cross_cc=no
  1264. container_image=
  1265. container_hosts=
  1266. container_cross_prefix=
  1267. container_cross_cc=
  1268. container_cross_ar=
  1269. container_cross_as=
  1270. container_cross_ld=
  1271. container_cross_nm=
  1272. container_cross_objcopy=
  1273. container_cross_ranlib=
  1274. container_cross_strip=
  1275. target_arch=${1%%-*}
  1276. case $target_arch in
  1277. aarch64) container_hosts="x86_64 aarch64" ;;
  1278. aarch64_be) container_hosts="x86_64 aarch64" ;;
  1279. alpha) container_hosts=x86_64 ;;
  1280. arm) container_hosts="x86_64 aarch64" ;;
  1281. hexagon) container_hosts=x86_64 ;;
  1282. hppa) container_hosts=x86_64 ;;
  1283. i386) container_hosts=x86_64 ;;
  1284. loongarch64) container_hosts=x86_64 ;;
  1285. m68k) container_hosts=x86_64 ;;
  1286. microblaze) container_hosts=x86_64 ;;
  1287. mips64el) container_hosts=x86_64 ;;
  1288. mips64) container_hosts=x86_64 ;;
  1289. mipsel) container_hosts=x86_64 ;;
  1290. mips) container_hosts=x86_64 ;;
  1291. ppc) container_hosts=x86_64 ;;
  1292. ppc64|ppc64le) container_hosts=x86_64 ;;
  1293. riscv64) container_hosts=x86_64 ;;
  1294. s390x) container_hosts=x86_64 ;;
  1295. sh4) container_hosts=x86_64 ;;
  1296. sparc64) container_hosts=x86_64 ;;
  1297. tricore) container_hosts=x86_64 ;;
  1298. x86_64) container_hosts="aarch64 ppc64le x86_64" ;;
  1299. xtensa*) container_hosts=x86_64 ;;
  1300. esac
  1301. for host in $container_hosts; do
  1302. test "$container" != no || continue
  1303. test "$host" = "$cpu" || continue
  1304. case $target_arch in
  1305. # debian-all-test-cross architectures
  1306. aarch64_be)
  1307. container_image=debian-all-test-cross
  1308. container_cross_prefix=aarch64-linux-gnu-
  1309. ;;
  1310. hppa|m68k|mips|riscv64|sparc64)
  1311. container_image=debian-all-test-cross
  1312. ;;
  1313. mips64)
  1314. container_image=debian-all-test-cross
  1315. container_cross_prefix=mips64-linux-gnuabi64-
  1316. ;;
  1317. ppc|ppc64|ppc64le)
  1318. container_image=debian-all-test-cross
  1319. container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu-
  1320. ;;
  1321. # debian-legacy-test-cross architectures (need Debian 11)
  1322. # - libc6.1-dev-alpha-cross: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1054412
  1323. # - sh4-linux-user: binaries don't run with bookworm compiler
  1324. alpha|sh4)
  1325. container_image=debian-legacy-test-cross
  1326. ;;
  1327. # architectures with individual containers
  1328. aarch64)
  1329. # We don't have any bigendian build tools so we only use this for AArch64
  1330. container_image=debian-arm64-cross
  1331. ;;
  1332. arm)
  1333. # We don't have any bigendian build tools so we only use this for ARM
  1334. container_image=debian-armhf-cross
  1335. container_cross_prefix=arm-linux-gnueabihf-
  1336. ;;
  1337. hexagon)
  1338. container_cross_prefix=hexagon-unknown-linux-musl-
  1339. container_cross_cc=${container_cross_prefix}clang
  1340. ;;
  1341. i386)
  1342. container_image=debian-i686-cross
  1343. container_cross_prefix=i686-linux-gnu-
  1344. ;;
  1345. loongarch64)
  1346. container_image=debian-loongarch-cross
  1347. container_cross_prefix=loongarch64-unknown-linux-gnu-
  1348. ;;
  1349. microblaze)
  1350. container_cross_prefix=microblaze-linux-musl-
  1351. ;;
  1352. mips64el)
  1353. container_image=debian-all-test-cross
  1354. container_cross_prefix=mips64el-linux-gnuabi64-
  1355. ;;
  1356. tricore)
  1357. container_image=debian-tricore-cross
  1358. container_cross_prefix=tricore-
  1359. ;;
  1360. x86_64)
  1361. container_image=debian-amd64-cross
  1362. ;;
  1363. xtensa*)
  1364. container_image=debian-xtensa-cross
  1365. # default to the dc232b cpu
  1366. container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
  1367. ;;
  1368. esac
  1369. # Debian and GNU architecture names usually match
  1370. : ${container_image:=debian-$target_arch-cross}
  1371. : ${container_cross_prefix:=$target_arch-linux-gnu-}
  1372. : ${container_cross_cc:=${container_cross_prefix}gcc}
  1373. : ${container_cross_ar:=${container_cross_prefix}ar}
  1374. : ${container_cross_as:=${container_cross_prefix}as}
  1375. : ${container_cross_ld:=${container_cross_prefix}ld}
  1376. : ${container_cross_nm:=${container_cross_prefix}nm}
  1377. : ${container_cross_objcopy:=${container_cross_prefix}objcopy}
  1378. : ${container_cross_ranlib:=${container_cross_prefix}ranlib}
  1379. : ${container_cross_strip:=${container_cross_prefix}strip}
  1380. done
  1381. try=cross
  1382. # For softmmu/roms also look for a bi-endian or multilib-enabled host compiler
  1383. if [ "${1%softmmu}" != "$1" ] || test "$target_arch" = "$cpu"; then
  1384. case "$target_arch:$cpu" in
  1385. aarch64_be:aarch64 | \
  1386. armeb:arm | \
  1387. i386:x86_64 | \
  1388. mips*:mips64 | \
  1389. ppc*:ppc64 | \
  1390. sparc:sparc64 | \
  1391. "$cpu:$cpu")
  1392. try='native cross' ;;
  1393. esac
  1394. fi
  1395. eval "target_cflags=\${cross_cc_cflags_$target_arch}"
  1396. for thistry in $try; do
  1397. case $thistry in
  1398. native)
  1399. target_cc=$cc
  1400. target_ccas=$ccas
  1401. target_ar=$ar
  1402. target_as=$as
  1403. target_ld=$ld
  1404. target_nm=$nm
  1405. target_objcopy=$objcopy
  1406. target_ranlib=$ranlib
  1407. target_strip=$strip
  1408. ;;
  1409. cross)
  1410. target_cc=
  1411. if eval test -n "\"\${cross_cc_$target_arch}\""; then
  1412. if eval has "\"\${cross_cc_$target_arch}\""; then
  1413. eval "target_cc=\"\${cross_cc_$target_arch}\""
  1414. fi
  1415. else
  1416. compute_target_variable $target_arch target_cc gcc
  1417. fi
  1418. target_ccas=$target_cc
  1419. compute_target_variable $target_arch target_ar ar
  1420. compute_target_variable $target_arch target_as as
  1421. compute_target_variable $target_arch target_ld ld
  1422. compute_target_variable $target_arch target_nm nm
  1423. compute_target_variable $target_arch target_objcopy objcopy
  1424. compute_target_variable $target_arch target_ranlib ranlib
  1425. compute_target_variable $target_arch target_strip strip
  1426. ;;
  1427. esac
  1428. if test -n "$target_cc"; then
  1429. case $target_arch in
  1430. i386|x86_64)
  1431. if $target_cc --version | grep -qi "clang"; then
  1432. continue
  1433. fi
  1434. ;;
  1435. esac
  1436. elif test -n "$target_as" && test -n "$target_ld"; then
  1437. # Special handling for assembler only targets
  1438. case $target in
  1439. tricore-softmmu)
  1440. build_static=
  1441. got_cross_cc=yes
  1442. break
  1443. ;;
  1444. *)
  1445. continue
  1446. ;;
  1447. esac
  1448. else
  1449. continue
  1450. fi
  1451. write_c_skeleton
  1452. case $1 in
  1453. *-softmmu)
  1454. if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC &&
  1455. do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then
  1456. got_cross_cc=yes
  1457. break
  1458. fi
  1459. ;;
  1460. *)
  1461. if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC -static ; then
  1462. build_static=y
  1463. got_cross_cc=yes
  1464. break
  1465. fi
  1466. if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC ; then
  1467. build_static=
  1468. got_cross_cc=yes
  1469. break
  1470. fi
  1471. ;;
  1472. esac
  1473. done
  1474. if test $got_cross_cc != yes; then
  1475. build_static=
  1476. target_cc=
  1477. target_ccas=
  1478. target_ar=
  1479. target_as=
  1480. target_ld=
  1481. target_nm=
  1482. target_objcopy=
  1483. target_ranlib=
  1484. target_strip=
  1485. fi
  1486. test -n "$target_cc"
  1487. }
  1488. write_target_makefile() {
  1489. echo "EXTRA_CFLAGS=$target_cflags"
  1490. if test -z "$target_cc" && test -z "$target_as"; then
  1491. test -z "$container_image" && error_exit "Internal error: could not find cross compiler for $1?"
  1492. echo "$1: docker-image-$container_image" >> Makefile.prereqs
  1493. if test -n "$container_cross_cc"; then
  1494. echo "CC=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
  1495. echo "CCAS=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
  1496. fi
  1497. echo "AR=$docker_py cc --cc $container_cross_ar -i qemu/$container_image -s $source_path --"
  1498. echo "AS=$docker_py cc --cc $container_cross_as -i qemu/$container_image -s $source_path --"
  1499. echo "LD=$docker_py cc --cc $container_cross_ld -i qemu/$container_image -s $source_path --"
  1500. echo "NM=$docker_py cc --cc $container_cross_nm -i qemu/$container_image -s $source_path --"
  1501. echo "OBJCOPY=$docker_py cc --cc $container_cross_objcopy -i qemu/$container_image -s $source_path --"
  1502. echo "RANLIB=$docker_py cc --cc $container_cross_ranlib -i qemu/$container_image -s $source_path --"
  1503. echo "STRIP=$docker_py cc --cc $container_cross_strip -i qemu/$container_image -s $source_path --"
  1504. else
  1505. if test -n "$target_cc"; then
  1506. echo "CC=$target_cc"
  1507. echo "CCAS=$target_ccas"
  1508. fi
  1509. if test -n "$target_ar"; then
  1510. echo "AR=$target_ar"
  1511. fi
  1512. if test -n "$target_as"; then
  1513. echo "AS=$target_as"
  1514. fi
  1515. if test -n "$target_ld"; then
  1516. echo "LD=$target_ld"
  1517. fi
  1518. if test -n "$target_nm"; then
  1519. echo "NM=$target_nm"
  1520. fi
  1521. if test -n "$target_objcopy"; then
  1522. echo "OBJCOPY=$target_objcopy"
  1523. fi
  1524. if test -n "$target_ranlib"; then
  1525. echo "RANLIB=$target_ranlib"
  1526. fi
  1527. if test -n "$target_strip"; then
  1528. echo "STRIP=$target_strip"
  1529. fi
  1530. fi
  1531. }
  1532. #######################################
  1533. # cross-compiled firmware targets
  1534. # Set up build tree symlinks that point back into the source tree
  1535. # (these can be both files and directories).
  1536. # Caution: avoid adding files or directories here using wildcards. This
  1537. # will result in problems later if a new file matching the wildcard is
  1538. # added to the source tree -- nothing will cause configure to be rerun
  1539. # so the build tree will be missing the link back to the new file, and
  1540. # tests might fail. Prefer to keep the relevant files in their own
  1541. # directory and symlink the directory instead.
  1542. LINKS="Makefile"
  1543. LINKS="$LINKS docs/config"
  1544. LINKS="$LINKS pc-bios/optionrom/Makefile"
  1545. LINKS="$LINKS pc-bios/s390-ccw/Makefile"
  1546. LINKS="$LINKS pc-bios/vof/Makefile"
  1547. LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
  1548. LINKS="$LINKS tests/avocado tests/data"
  1549. LINKS="$LINKS tests/qemu-iotests/check tests/qemu-iotests/Makefile"
  1550. LINKS="$LINKS python"
  1551. for f in $LINKS ; do
  1552. if [ -e "$source_path/$f" ]; then
  1553. symlink "$source_path/$f" "$f"
  1554. fi
  1555. done
  1556. # use included Linux headers for KVM architectures
  1557. if test "$host_os" = "linux" && test -n "$linux_arch"; then
  1558. symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
  1559. fi
  1560. echo "# Automatically generated by configure - do not modify" > Makefile.prereqs
  1561. # Mac OS X ships with a broken assembler
  1562. if have_target i386-softmmu x86_64-softmmu && \
  1563. test "$host_os" != "darwin" && test "$host_os" != "sunos" && \
  1564. test "$host_os" != "haiku" && \
  1565. probe_target_compiler i386-softmmu; then
  1566. subdirs="$subdirs pc-bios/optionrom"
  1567. config_mak=pc-bios/optionrom/config.mak
  1568. echo "# Automatically generated by configure - do not modify" > $config_mak
  1569. echo "TOPSRC_DIR=$source_path" >> $config_mak
  1570. write_target_makefile >> $config_mak
  1571. fi
  1572. if have_target ppc-softmmu ppc64-softmmu && \
  1573. probe_target_compiler ppc-softmmu; then
  1574. subdirs="$subdirs pc-bios/vof"
  1575. config_mak=pc-bios/vof/config.mak
  1576. echo "# Automatically generated by configure - do not modify" > $config_mak
  1577. echo "SRC_DIR=$source_path/pc-bios/vof" >> $config_mak
  1578. write_target_makefile >> $config_mak
  1579. fi
  1580. # Only build s390-ccw bios if the compiler has -march=z900 or -march=z10
  1581. # (which is the lowest architecture level that Clang supports)
  1582. if have_target s390x-softmmu && probe_target_compiler s390x-softmmu && \
  1583. GIT=git "$source_path/scripts/git-submodule.sh" "$git_submodules_action" roms/SLOF >> config.log 2>&1; then
  1584. write_c_skeleton
  1585. do_compiler "$target_cc" $target_cc_cflags -march=z900 -o $TMPO -c $TMPC
  1586. has_z900=$?
  1587. if [ $has_z900 = 0 ] || do_compiler "$target_cc" $target_cc_cflags -march=z10 -msoft-float -Werror -o $TMPO -c $TMPC; then
  1588. if [ $has_z900 != 0 ]; then
  1589. echo "WARNING: Your compiler does not support the z900!"
  1590. echo " The s390-ccw bios will only work with guest CPUs >= z10."
  1591. fi
  1592. subdirs="$subdirs pc-bios/s390-ccw"
  1593. config_mak=pc-bios/s390-ccw/config-host.mak
  1594. echo "# Automatically generated by configure - do not modify" > $config_mak
  1595. echo "SRC_PATH=$source_path/pc-bios/s390-ccw" >> $config_mak
  1596. echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_mak
  1597. write_target_makefile >> $config_mak
  1598. fi
  1599. fi
  1600. #######################################
  1601. # generate config-host.mak
  1602. config_host_mak="config-host.mak"
  1603. echo "# Automatically generated by configure - do not modify" > $config_host_mak
  1604. echo >> $config_host_mak
  1605. echo all: >> $config_host_mak
  1606. echo "SRC_PATH=$source_path" >> $config_host_mak
  1607. echo "TARGET_DIRS=$target_list" >> $config_host_mak
  1608. echo "GDB=$gdb_bin" >> $config_host_mak
  1609. if test "$container" != no; then
  1610. echo "RUNC=$runc" >> $config_host_mak
  1611. fi
  1612. echo "SUBDIRS=$subdirs" >> $config_host_mak
  1613. if test "$rust" != disabled; then
  1614. echo "RUST_TARGET_TRIPLE=$rust_target_triple" >> $config_host_mak
  1615. fi
  1616. echo "PYTHON=$python" >> $config_host_mak
  1617. echo "MKVENV_ENSUREGROUP=$mkvenv ensuregroup $mkvenv_online_flag" >> $config_host_mak
  1618. echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
  1619. echo "MESON=$meson" >> $config_host_mak
  1620. echo "NINJA=$ninja" >> $config_host_mak
  1621. echo "EXESUF=$EXESUF" >> $config_host_mak
  1622. if test "$default_targets" = "yes"; then
  1623. echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
  1624. fi
  1625. # tests/tcg configuration
  1626. mkdir -p tests/tcg
  1627. echo "# Automatically generated by configure - do not modify" > tests/tcg/$config_host_mak
  1628. echo "SRC_PATH=$source_path" >> tests/tcg/$config_host_mak
  1629. if test "$plugins" = "yes" ; then
  1630. echo "CONFIG_PLUGIN=y" >> tests/tcg/$config_host_mak
  1631. fi
  1632. tcg_tests_targets=
  1633. for target in $target_list; do
  1634. arch=${target%%-*}
  1635. case $target in
  1636. xtensa*-linux-user)
  1637. # the toolchain is not complete with headers, only build system tests
  1638. continue
  1639. ;;
  1640. *-softmmu)
  1641. test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || continue
  1642. qemu="qemu-system-$arch"
  1643. ;;
  1644. *-linux-user|*-bsd-user)
  1645. qemu="qemu-$arch"
  1646. ;;
  1647. esac
  1648. if probe_target_compiler $target || test -n "$container_image"; then
  1649. test -n "$container_image" && build_static=y
  1650. mkdir -p "tests/tcg/$target"
  1651. config_target_mak=tests/tcg/$target/config-target.mak
  1652. ln -sf "$source_path/tests/tcg/Makefile.target" "tests/tcg/$target/Makefile"
  1653. echo "# Automatically generated by configure - do not modify" > "$config_target_mak"
  1654. echo "TARGET_NAME=$arch" >> "$config_target_mak"
  1655. echo "TARGET=$target" >> "$config_target_mak"
  1656. write_target_makefile "build-tcg-tests-$target" >> "$config_target_mak"
  1657. echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
  1658. echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
  1659. # will GDB work with these binaries?
  1660. if test "${gdb_arches#*$arch}" != "$gdb_arches"; then
  1661. echo "GDB=$gdb_bin" >> $config_target_mak
  1662. fi
  1663. if test "${gdb_arches#*aarch64}" != "$gdb_arches" && version_ge $gdb_version 15.1; then
  1664. echo "GDB_HAS_MTE=y" >> $config_target_mak
  1665. fi
  1666. if test "${gdb_arches#*aarch64}" != "$gdb_arches" && version_ge $gdb_version 16.0; then
  1667. # GDB has to support MTE in baremetal to allow debugging MTE in QEMU system mode
  1668. echo "GDB_SUPPORTS_MTE_IN_BAREMETAL=y" >> $config_target_mak
  1669. fi
  1670. echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs
  1671. tcg_tests_targets="$tcg_tests_targets $target"
  1672. fi
  1673. done
  1674. if test "$tcg" = "enabled"; then
  1675. echo "TCG_TESTS_TARGETS=$tcg_tests_targets" >> $config_host_mak
  1676. fi
  1677. if test "$skip_meson" = no; then
  1678. cross="config-meson.cross.new"
  1679. meson_quote() {
  1680. test $# = 0 && return
  1681. echo "'$(echo $* | sed "s/ /','/g")'"
  1682. }
  1683. echo "# Automatically generated by configure - do not modify" > $cross
  1684. echo "[properties]" >> $cross
  1685. # unroll any custom device configs
  1686. for a in $device_archs; do
  1687. eval "c=\$devices_${a}"
  1688. echo "${a}-softmmu = '$c'" >> $cross
  1689. done
  1690. echo "[built-in options]" >> $cross
  1691. echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
  1692. echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
  1693. test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
  1694. echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
  1695. echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
  1696. # Only enable by default for git builds and on select OSes
  1697. echo "# environment defaults, can still be overridden on " >> $cross
  1698. echo "# the command line" >> $cross
  1699. if test -e "$source_path/.git" && \
  1700. { test "$host_os" = linux || test "$host_os" = "windows"; }; then
  1701. echo 'werror = true' >> $cross
  1702. fi
  1703. echo "[project options]" >> $cross
  1704. if test "$SMBD" != ''; then
  1705. echo "smbd = $(meson_quote "$SMBD")" >> $cross
  1706. fi
  1707. if test "${QEMU_GA_MANUFACTURER}" != ''; then
  1708. echo "qemu_ga_manufacturer = $(meson_quote "${QEMU_GA_MANUFACTURER}")" >> $cross
  1709. fi
  1710. if test "${QEMU_GA_DISTRO}" != ''; then
  1711. echo "qemu_ga_distro = $(meson_quote "${QEMU_GA_DISTRO}")" >> $cross
  1712. fi
  1713. if test "${QEMU_GA_VERSION}" != ''; then
  1714. echo "qemu_ga_version = $(meson_quote "${QEMU_GA_VERSION}")" >> $cross
  1715. fi
  1716. echo >> $cross
  1717. echo "[binaries]" >> $cross
  1718. echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
  1719. test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
  1720. test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
  1721. if test "$rust" != disabled; then
  1722. if test "$rust_host_triple" != "$rust_target_triple"; then
  1723. echo "rust = [$(meson_quote $rustc --target "$rust_target_triple")]" >> $cross
  1724. else
  1725. echo "rust = [$(meson_quote $rustc)]" >> $cross
  1726. fi
  1727. fi
  1728. echo "ar = [$(meson_quote $ar)]" >> $cross
  1729. echo "dlltool = [$(meson_quote $dlltool)]" >> $cross
  1730. echo "nm = [$(meson_quote $nm)]" >> $cross
  1731. echo "pkgconfig = [$(meson_quote $pkg_config)]" >> $cross
  1732. echo "pkg-config = [$(meson_quote $pkg_config)]" >> $cross
  1733. echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
  1734. echo "readelf = [$(meson_quote $readelf)]" >> $cross
  1735. if has $sdl2_config; then
  1736. echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
  1737. fi
  1738. echo "strip = [$(meson_quote $strip)]" >> $cross
  1739. echo "widl = [$(meson_quote $widl)]" >> $cross
  1740. echo "windres = [$(meson_quote $windres)]" >> $cross
  1741. echo "windmc = [$(meson_quote $windmc)]" >> $cross
  1742. if test "$cross_compile" = "yes"; then
  1743. echo "[host_machine]" >> $cross
  1744. echo "system = '$host_os'" >> $cross
  1745. case "$cpu" in
  1746. i386)
  1747. echo "cpu_family = 'x86'" >> $cross
  1748. ;;
  1749. *)
  1750. echo "cpu_family = '$cpu'" >> $cross
  1751. ;;
  1752. esac
  1753. echo "cpu = '$cpu'" >> $cross
  1754. if test "$bigendian" = "yes" ; then
  1755. echo "endian = 'big'" >> $cross
  1756. else
  1757. echo "endian = 'little'" >> $cross
  1758. fi
  1759. native="config-meson.native.new"
  1760. echo "# Automatically generated by configure - do not modify" > $native
  1761. echo "[binaries]" >> $native
  1762. echo "c = [$(meson_quote $host_cc)]" >> $native
  1763. if test "$rust" != disabled; then
  1764. echo "rust = [$(meson_quote $rustc)]" >> $cross
  1765. fi
  1766. mv $native config-meson.native
  1767. meson_option_add --native-file
  1768. meson_option_add config-meson.native
  1769. fi
  1770. mv $cross config-meson.cross
  1771. meson_add_machine_file config-meson.cross
  1772. if test -f "$source_path/configs/meson/$host_os.txt"; then
  1773. meson_add_machine_file $source_path/configs/meson/$host_os.txt
  1774. fi
  1775. rm -rf meson-private meson-info meson-logs
  1776. test "$download" = "disabled" && meson_option_add "--wrap-mode=nodownload"
  1777. test "$default_feature" = no && meson_option_add -Dauto_features=disabled
  1778. test "$static" = yes && meson_option_add -Dprefer_static=true
  1779. test "$pie" = no && meson_option_add -Db_pie=false
  1780. # QEMU options
  1781. test "$rust" != "disabled" && meson_option_add "-Drust=$rust"
  1782. test "$cfi" != false && meson_option_add "-Dcfi=$cfi" "-Db_lto=$cfi"
  1783. test "$docs" != auto && meson_option_add "-Ddocs=$docs"
  1784. test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
  1785. test "$plugins" = yes && meson_option_add "-Dplugins=true"
  1786. test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
  1787. run_meson() {
  1788. NINJA=$ninja $meson setup "$@" "$PWD" "$source_path"
  1789. }
  1790. eval run_meson $meson_options
  1791. if test "$?" -ne 0 ; then
  1792. error_exit "meson setup failed"
  1793. fi
  1794. echo "$meson" > build.ninja.stamp
  1795. else
  1796. if test -f meson-private/cmd_line.txt; then
  1797. # Adjust old command line options that were removed
  1798. # sed -i is not portable
  1799. perl -i -ne '
  1800. /^sphinx_build/ && next;
  1801. print;' meson-private/cmd_line.txt
  1802. fi
  1803. fi
  1804. # Save the configure command line for later reuse.
  1805. cat <<EOD >config.status
  1806. #!/bin/sh
  1807. # Generated by configure.
  1808. # Run this file to recreate the current configuration.
  1809. # Compiler output produced by configure, useful for debugging
  1810. # configure, is in config.log if it exists.
  1811. EOD
  1812. preserve_env() {
  1813. envname=$1
  1814. eval envval=\$$envname
  1815. if test -n "$envval"
  1816. then
  1817. echo "$envname='$envval'" >> config.status
  1818. echo "export $envname" >> config.status
  1819. else
  1820. echo "unset $envname" >> config.status
  1821. fi
  1822. }
  1823. # Preserve various env variables that influence what
  1824. # features/build target configure will detect
  1825. preserve_env AR
  1826. preserve_env AS
  1827. preserve_env CC
  1828. preserve_env CFLAGS
  1829. preserve_env CXX
  1830. preserve_env CXXFLAGS
  1831. preserve_env DLLTOOL
  1832. preserve_env LD
  1833. preserve_env LDFLAGS
  1834. preserve_env LD_LIBRARY_PATH
  1835. preserve_env NM
  1836. preserve_env OBJCFLAGS
  1837. preserve_env OBJCOPY
  1838. preserve_env PATH
  1839. preserve_env PKG_CONFIG
  1840. preserve_env PKG_CONFIG_LIBDIR
  1841. preserve_env PKG_CONFIG_PATH
  1842. preserve_env PYTHON
  1843. preserve_env QEMU_GA_MANUFACTURER
  1844. preserve_env QEMU_GA_DISTRO
  1845. preserve_env QEMU_GA_VERSION
  1846. preserve_env SDL2_CONFIG
  1847. preserve_env SMBD
  1848. preserve_env STRIP
  1849. preserve_env WIDL
  1850. preserve_env WINDRES
  1851. preserve_env WINDMC
  1852. printf "exec" >>config.status
  1853. for i in "$0" "$@"; do
  1854. test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
  1855. done
  1856. echo ' "$@"' >>config.status
  1857. chmod +x config.status
  1858. rm -r "$TMPDIR1"
  1859. if test "$rust" != disabled; then
  1860. echo
  1861. echo 'INFO: Rust bindings generation with `bindgen` might fail in some cases where'
  1862. echo 'the detected `libclang` does not match the expected `clang` version/target. In'
  1863. echo 'this case you must pass the path to `clang` and `libclang` to your build'
  1864. echo 'command invocation using the environment variables CLANG_PATH and LIBCLANG_PATH'
  1865. fi