configure 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061
  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. # Now we have our CPU_CFLAGS we can check if we are targeting a 32 or
  480. # 64 bit host.
  481. check_64bit_host() {
  482. cat > $TMPC <<EOF
  483. #if __SIZEOF_POINTER__ != 8
  484. #error not 64 bit system
  485. #endif
  486. int main(void) { return 0; }
  487. EOF
  488. compile_object "$1"
  489. }
  490. if check_64bit_host "$CPU_CFLAGS"; then
  491. host_bits=64
  492. else
  493. host_bits=32
  494. fi
  495. if test -n "$host_arch" && {
  496. ! test -d "$source_path/linux-user/include/host/$host_arch" ||
  497. ! test -d "$source_path/common-user/host/$host_arch"; }; then
  498. error_exit "linux-user/include/host/$host_arch does not exist." \
  499. "This is a bug in the configure script, please report it."
  500. fi
  501. if test -n "$linux_arch" && ! test -d "$source_path/linux-headers/asm-$linux_arch"; then
  502. error_exit "linux-headers/asm-$linux_arch does not exist." \
  503. "This is a bug in the configure script, please report it."
  504. fi
  505. check_py_version() {
  506. # We require python >= 3.8.
  507. # NB: a True python conditional creates a non-zero return code (Failure)
  508. "$1" -c 'import sys; sys.exit(sys.version_info < (3,8))'
  509. }
  510. first_python=
  511. if test -z "${PYTHON}"; then
  512. # A bare 'python' is traditionally python 2.x, but some distros
  513. # have it as python 3.x, so check in both places.
  514. for binary in python3 python python3.12 python3.11 \
  515. python3.10 python3.9 python3.8; do
  516. if has "$binary"; then
  517. python=$(command -v "$binary")
  518. if check_py_version "$python"; then
  519. # This one is good.
  520. first_python=
  521. break
  522. else
  523. first_python=$python
  524. fi
  525. fi
  526. done
  527. else
  528. # Same as above, but only check the environment variable.
  529. has "${PYTHON}" || error_exit "The PYTHON environment variable does not point to an executable"
  530. python=$(command -v "$PYTHON")
  531. if check_py_version "$python"; then
  532. # This one is good.
  533. first_python=
  534. else
  535. first_python=$first_python
  536. fi
  537. fi
  538. # Check for ancillary tools used in testing
  539. genisoimage=
  540. for binary in genisoimage mkisofs
  541. do
  542. if has $binary
  543. then
  544. genisoimage=$(command -v "$binary")
  545. break
  546. fi
  547. done
  548. if test "$host_os" = "windows" ; then
  549. EXESUF=".exe"
  550. fi
  551. meson_option_build_array() {
  552. printf '['
  553. (if test "$host_os" = windows; then
  554. IFS=\;
  555. else
  556. IFS=:
  557. fi
  558. for e in $1; do
  559. printf '"""'
  560. # backslash escape any '\' and '"' characters
  561. printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g'
  562. printf '""",'
  563. done)
  564. printf ']\n'
  565. }
  566. . "$source_path/scripts/meson-buildoptions.sh"
  567. meson_options=
  568. meson_option_add() {
  569. local arg
  570. for arg; do
  571. meson_options="$meson_options $(quote_sh "$arg")"
  572. done
  573. }
  574. meson_option_parse() {
  575. meson_options="$meson_options $(_meson_option_parse "$@")"
  576. if test $? -eq 1; then
  577. echo "ERROR: unknown option $1"
  578. echo "Try '$0 --help' for more information"
  579. exit 1
  580. fi
  581. }
  582. has_meson_option() {
  583. test "${meson_options#*"$1"}" != "$meson_options"
  584. }
  585. meson_add_machine_file() {
  586. if test "$cross_compile" = "yes"; then
  587. meson_option_add --cross-file "$1"
  588. else
  589. meson_option_add --native-file "$1"
  590. fi
  591. }
  592. for opt do
  593. optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
  594. case "$opt" in
  595. --help|-h) show_help=yes
  596. ;;
  597. --version|-V) exec cat "$source_path/VERSION"
  598. ;;
  599. --cross-prefix=*)
  600. ;;
  601. --cc=*)
  602. ;;
  603. --host-cc=*) host_cc="$optarg"
  604. ;;
  605. --cxx=*)
  606. ;;
  607. --objcc=*)
  608. ;;
  609. --rustc=*)
  610. ;;
  611. --make=*)
  612. ;;
  613. --install=*)
  614. ;;
  615. --python=*) python="$optarg"
  616. ;;
  617. --skip-meson) skip_meson=yes
  618. ;;
  619. --ninja=*) ninja="$optarg"
  620. ;;
  621. --extra-cflags=*)
  622. ;;
  623. --extra-cxxflags=*)
  624. ;;
  625. --extra-objcflags=*)
  626. ;;
  627. --extra-ldflags=*)
  628. ;;
  629. --cross-cc-*)
  630. ;;
  631. --cross-prefix-*)
  632. ;;
  633. --enable-docs) docs=enabled
  634. ;;
  635. --disable-docs) docs=disabled
  636. ;;
  637. --cpu=*)
  638. ;;
  639. --target-list=*) target_list="$optarg"
  640. if test "$target_list_exclude"; then
  641. error_exit "Can't mix --target-list with --target-list-exclude"
  642. fi
  643. ;;
  644. --target-list-exclude=*) target_list_exclude="$optarg"
  645. if test "$target_list"; then
  646. error_exit "Can't mix --target-list-exclude with --target-list"
  647. fi
  648. ;;
  649. --with-default-devices) meson_option_add -Ddefault_devices=true
  650. ;;
  651. --without-default-devices) meson_option_add -Ddefault_devices=false
  652. ;;
  653. --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
  654. ;;
  655. --with-devices-*) device_arch=${opt#--with-devices-};
  656. device_arch=${device_arch%%=*}
  657. cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
  658. if test -f "$cf"; then
  659. device_archs="$device_archs $device_arch"
  660. eval "devices_${device_arch}=\$optarg"
  661. else
  662. error_exit "File $cf does not exist"
  663. fi
  664. ;;
  665. --without-default-features) # processed above
  666. ;;
  667. --static) static="yes"
  668. ;;
  669. --host=*|--build=*|\
  670. --disable-dependency-tracking|\
  671. --sbindir=*|--sharedstatedir=*|\
  672. --oldincludedir=*|--datarootdir=*|--infodir=*|\
  673. --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
  674. # These switches are silently ignored, for compatibility with
  675. # autoconf-generated configure scripts. This allows QEMU's
  676. # configure to be used by RPM and similar macros that set
  677. # lots of directory switches by default.
  678. ;;
  679. --enable-debug)
  680. # Enable debugging options that aren't excessively noisy
  681. meson_option_parse --enable-debug-tcg ""
  682. meson_option_parse --enable-debug-graph-lock ""
  683. meson_option_parse --enable-debug-mutex ""
  684. meson_option_add -Doptimization=0
  685. default_cflags='-O0 -g'
  686. ;;
  687. --disable-tcg) tcg="disabled"
  688. ;;
  689. --enable-tcg) tcg="enabled"
  690. ;;
  691. --disable-system) system="no"
  692. ;;
  693. --enable-system) system="yes"
  694. ;;
  695. --disable-user)
  696. linux_user="no" ;
  697. bsd_user="no" ;
  698. ;;
  699. --enable-user) ;;
  700. --disable-linux-user) linux_user="no"
  701. ;;
  702. --enable-linux-user) linux_user="yes"
  703. ;;
  704. --disable-bsd-user) bsd_user="no"
  705. ;;
  706. --enable-bsd-user) bsd_user="yes"
  707. ;;
  708. --enable-pie) pie="yes"
  709. ;;
  710. --disable-pie) pie="no"
  711. ;;
  712. --enable-cfi) cfi=true
  713. ;;
  714. --disable-cfi) cfi=false
  715. ;;
  716. --disable-download) download="disabled"; git_submodules_action=validate;
  717. ;;
  718. --enable-download) download="enabled"; git_submodules_action=update;
  719. ;;
  720. --enable-plugins) plugins="yes"
  721. ;;
  722. --disable-plugins) plugins="no"
  723. ;;
  724. --enable-containers) use_containers="yes"
  725. ;;
  726. --disable-containers) use_containers="no"
  727. ;;
  728. --container-engine=*) container_engine="$optarg"
  729. ;;
  730. --rust-target-triple=*) rust_target_triple="$optarg"
  731. ;;
  732. --gdb=*) gdb_bin="$optarg"
  733. ;;
  734. --enable-rust) rust=enabled
  735. ;;
  736. --disable-rust) rust=disabled
  737. ;;
  738. # everything else has the same name in configure and meson
  739. --*) meson_option_parse "$opt" "$optarg"
  740. ;;
  741. # Pass through -Dxxxx options to meson
  742. -D*) meson_option_add "$opt"
  743. ;;
  744. esac
  745. done
  746. if ! test -e "$source_path/.git"
  747. then
  748. git_submodules_action="validate"
  749. fi
  750. if ! test -f "$source_path/subprojects/keycodemapdb/README" \
  751. && test "$download" = disabled
  752. then
  753. echo
  754. echo "ERROR: missing subprojects"
  755. echo
  756. if test -e "$source_path/.git"; then
  757. echo "--disable-download specified but subprojects were not"
  758. echo 'checked out. Please invoke "meson subprojects download"'
  759. echo "before configuring QEMU, or remove --disable-download"
  760. echo "from the command line."
  761. else
  762. echo "This is not a GIT checkout but subproject content appears to"
  763. echo "be missing. Do not use 'git archive' or GitHub download links"
  764. echo "to acquire QEMU source archives. Non-GIT builds are only"
  765. echo "supported with source archives linked from:"
  766. echo
  767. echo " https://www.qemu.org/download/#source"
  768. echo
  769. echo "Developers working with GIT can use scripts/archive-source.sh"
  770. echo "if they need to create valid source archives."
  771. fi
  772. echo
  773. exit 1
  774. fi
  775. default_target_list=""
  776. mak_wilds=""
  777. if [ -n "$host_arch" ] && [ -d "$source_path/common-user/host/$host_arch" ]; then
  778. if [ "$linux_user" != no ]; then
  779. if [ "$host_os" = linux ]; then
  780. linux_user=yes
  781. elif [ "$linux_user" = yes ]; then
  782. error_exit "linux-user not supported on this architecture"
  783. fi
  784. if [ "$linux_user" = "yes" ]; then
  785. mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
  786. fi
  787. fi
  788. if [ "$bsd_user" != no ]; then
  789. if [ "$bsd_user" = "" ]; then
  790. test $host_os = freebsd && bsd_user=yes
  791. fi
  792. if [ "$bsd_user" = yes ] && ! [ -d "$source_path/bsd-user/$host_os" ]; then
  793. error_exit "bsd-user not supported on this host OS"
  794. fi
  795. if [ "$bsd_user" = "yes" ]; then
  796. mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
  797. fi
  798. fi
  799. else
  800. if [ "$linux_user" = yes ] || [ "$bsd_user" = yes ]; then
  801. error_exit "user mode emulation not supported on this architecture"
  802. fi
  803. fi
  804. if [ "$system" = "yes" ]; then
  805. mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
  806. fi
  807. for config in $mak_wilds; do
  808. target="$(basename "$config" .mak)"
  809. if echo "$target_list_exclude" | grep -vq "$target"; then
  810. default_target_list="${default_target_list} $target"
  811. fi
  812. done
  813. if test x"$show_help" = x"yes" ; then
  814. cat << EOF
  815. Usage: configure [options]
  816. Options: [defaults in brackets after descriptions]
  817. Standard options:
  818. --help print this message
  819. --target-list=LIST set target list (default: build all)
  820. $(echo Available targets: $default_target_list | \
  821. fold -s -w 53 | sed -e 's/^/ /')
  822. --target-list-exclude=LIST exclude a set of targets from the default target-list
  823. Advanced options (experts only):
  824. -Dmesonoptname=val passthrough option to meson unmodified
  825. --cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
  826. --cc=CC use C compiler CC [$cc]
  827. --host-cc=CC when cross compiling, use C compiler CC for code run
  828. at build time [$host_cc]
  829. --cxx=CXX use C++ compiler CXX [$cxx]
  830. --objcc=OBJCC use Objective-C compiler OBJCC [$objcc]
  831. --rustc=RUSTC use Rust compiler RUSTC [$rustc]
  832. --extra-cflags=CFLAGS append extra C compiler flags CFLAGS
  833. --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
  834. --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
  835. --extra-ldflags=LDFLAGS append extra linker flags LDFLAGS
  836. --cross-cc-ARCH=CC use compiler when building ARCH guest test cases
  837. --cross-cc-cflags-ARCH= use compiler flags when building ARCH guest tests
  838. --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
  839. --python=PYTHON use specified python [$python]
  840. --ninja=NINJA use specified ninja [$ninja]
  841. --static enable static build [$static]
  842. --rust-target-triple=TRIPLE compilation target for Rust code [autodetect]
  843. --without-default-features default all --enable-* options to "disabled"
  844. --without-default-devices do not include any device that is not needed to
  845. start the emulator (only use if you are including
  846. desired devices in configs/devices/)
  847. --with-devices-ARCH=NAME override default configs/devices
  848. --enable-debug enable common debug build options
  849. --cpu=CPU Build for host CPU [$cpu]
  850. --disable-containers don't use containers for cross-building
  851. --container-engine=TYPE which container engine to use [$container_engine]
  852. --gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
  853. EOF
  854. meson_options_help
  855. cat << EOF
  856. system all system emulation targets
  857. user supported user emulation targets
  858. linux-user all linux usermode emulation targets
  859. bsd-user all BSD usermode emulation targets
  860. pie Position Independent Executables
  861. NOTE: The object files are built at the place where configure is launched
  862. EOF
  863. exit 0
  864. fi
  865. # Now that we are sure that the user did not only want to print the --help
  866. # information, we should double-check that the C compiler really works:
  867. write_c_skeleton
  868. if ! compile_object ; then
  869. error_exit "C compiler \"$cc\" either does not exist or does not work."
  870. fi
  871. # Remove old dependency files to make sure that they get properly regenerated
  872. rm -f ./*/config-devices.mak.d
  873. if test -z "$python"
  874. then
  875. # If first_python is set, there was a binary somewhere even though
  876. # it was not suitable. Use it for the error message.
  877. if test -n "$first_python"; then
  878. error_exit "Cannot use '$first_python', Python >= 3.8 is required." \
  879. "Use --python=/path/to/python to specify a supported Python."
  880. else
  881. error_exit "Python not found. Use --python=/path/to/python"
  882. fi
  883. fi
  884. if ! check_py_version "$python"; then
  885. error_exit "Cannot use '$python', Python >= 3.8 is required." \
  886. "Use --python=/path/to/python to specify a supported Python." \
  887. "Maybe try:" \
  888. " openSUSE Leap 15.3+: zypper install python39" \
  889. " CentOS 8: dnf install python38"
  890. fi
  891. # Resolve PATH
  892. python="$(command -v "$python")"
  893. # Create a Python virtual environment using our configured python.
  894. # The stdout of this script will be the location of a symlink that
  895. # points to the configured Python.
  896. # Entry point scripts for pip, meson, and sphinx are generated if those
  897. # packages are present.
  898. # Defaults assumed for now:
  899. # - venv is cleared if it exists already;
  900. # - venv is allowed to use system packages;
  901. # - all setup can be performed offline;
  902. # - missing packages may be fetched from PyPI,
  903. # unless --disable-download is passed.
  904. # - pip is not installed into the venv when possible,
  905. # but ensurepip is called as a fallback when necessary.
  906. echo "python determined to be '$python'"
  907. echo "python version: $($python --version)"
  908. python="$($python -B "${source_path}/python/scripts/mkvenv.py" create pyvenv)"
  909. if test "$?" -ne 0 ; then
  910. error_exit "python venv creation failed"
  911. fi
  912. # Suppress writing compiled files
  913. python="$python -B"
  914. mkvenv="$python ${source_path}/python/scripts/mkvenv.py"
  915. # Finish preparing the virtual environment using vendored .whl files
  916. $mkvenv ensuregroup --dir "${source_path}/python/wheels" \
  917. ${source_path}/pythondeps.toml meson || exit 1
  918. # At this point, we expect Meson to be installed and available.
  919. # We expect mkvenv or pip to have created pyvenv/bin/meson for us.
  920. # We ignore PATH completely here: we want to use the venv's Meson
  921. # *exclusively*.
  922. meson="$(cd pyvenv/bin; pwd)/meson"
  923. # Conditionally ensure Sphinx is installed.
  924. mkvenv_online_flag=""
  925. if test "$download" = "enabled" ; then
  926. mkvenv_online_flag=" --online"
  927. fi
  928. if test "$docs" != "disabled" ; then
  929. if ! $mkvenv ensuregroup \
  930. $(test "$docs" = "enabled" && echo "$mkvenv_online_flag") \
  931. ${source_path}/pythondeps.toml docs;
  932. then
  933. if test "$docs" = "enabled" ; then
  934. exit 1
  935. fi
  936. echo "Sphinx not found/usable, disabling docs."
  937. docs=disabled
  938. else
  939. docs=enabled
  940. fi
  941. fi
  942. # Probe for ninja
  943. if test -z "$ninja"; then
  944. for c in ninja ninja-build samu; do
  945. if has $c; then
  946. ninja=$(command -v "$c")
  947. break
  948. fi
  949. done
  950. if test -z "$ninja"; then
  951. error_exit "Cannot find Ninja"
  952. fi
  953. fi
  954. if test "$host_os" = "bogus"; then
  955. # Now that we know that we're not printing the help and that
  956. # the compiler works (so the results of the check_defines we used
  957. # to identify the OS are reliable), if we didn't recognize the
  958. # host OS we should stop now.
  959. error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
  960. fi
  961. # test for any invalid configuration combinations
  962. if test "$host_os" = "windows" && ! has "$dlltool"; then
  963. if test "$plugins" = "yes"; then
  964. error_exit "TCG plugins requires dlltool to build on Windows platforms"
  965. fi
  966. plugins="no"
  967. fi
  968. if test "$tcg" = "disabled" ; then
  969. if test "$plugins" = "yes"; then
  970. error_exit "Can't enable plugins on non-TCG builds"
  971. fi
  972. plugins="no"
  973. fi
  974. if test "$static" = "yes" ; then
  975. if test "$plugins" = "yes"; then
  976. error_exit "static and plugins are mutually incompatible"
  977. fi
  978. plugins="no"
  979. fi
  980. if test "$plugins" != "no" && test $host_bits -eq 64; then
  981. if has_meson_option "-Dtcg_interpreter=true"; then
  982. plugins="no"
  983. else
  984. plugins=yes
  985. fi
  986. fi
  987. cat > $TMPC << EOF
  988. #ifdef __linux__
  989. # define THREAD __thread
  990. #else
  991. # define THREAD
  992. #endif
  993. static THREAD int tls_var;
  994. int main(void) { return tls_var; }
  995. EOF
  996. if test "$host_os" = windows || test "$host_os" = haiku; then
  997. if test "$pie" = "yes"; then
  998. error_exit "PIE not available due to missing OS support"
  999. fi
  1000. pie=no
  1001. fi
  1002. if test "$pie" != "no"; then
  1003. if test "$static" = "yes"; then
  1004. pie_ldflags=-static-pie
  1005. else
  1006. pie_ldflags=-pie
  1007. fi
  1008. if compile_prog "-Werror -fPIE -DPIE" "$pie_ldflags"; then
  1009. pie="yes"
  1010. elif test "$pie" = "yes"; then
  1011. error_exit "-static-pie not available due to missing toolchain support"
  1012. else
  1013. echo "Disabling PIE due to missing toolchain support"
  1014. pie="no"
  1015. fi
  1016. fi
  1017. ##########################################
  1018. if test -z "${target_list+xxx}" ; then
  1019. default_targets=yes
  1020. for target in $default_target_list; do
  1021. target_list="$target_list $target"
  1022. done
  1023. target_list="${target_list# }"
  1024. else
  1025. default_targets=no
  1026. target_list=$(echo "$target_list" | sed -e 's/,/ /g')
  1027. for target in $target_list; do
  1028. # Check that we recognised the target name; this allows a more
  1029. # friendly error message than if we let it fall through.
  1030. case " $default_target_list " in
  1031. *" $target "*)
  1032. ;;
  1033. *)
  1034. error_exit "Unknown target name '$target'"
  1035. ;;
  1036. esac
  1037. done
  1038. fi
  1039. if test "$tcg" = "auto"; then
  1040. if test -z "$target_list"; then
  1041. tcg="disabled"
  1042. else
  1043. tcg="enabled"
  1044. fi
  1045. fi
  1046. #########################################
  1047. # gdb test
  1048. if test -n "$gdb_bin"; then
  1049. gdb_version_string=$($gdb_bin --version | head -n 1)
  1050. # Extract last field in the version string
  1051. gdb_version=${gdb_version_string##* }
  1052. if version_ge $gdb_version 9.1; then
  1053. gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
  1054. else
  1055. gdb_bin=""
  1056. fi
  1057. fi
  1058. ##########################################
  1059. # big/little endian test
  1060. cat > $TMPC << EOF
  1061. #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  1062. # error LITTLE
  1063. #endif
  1064. int main(void) { return 0; }
  1065. EOF
  1066. if ! compile_prog ; then
  1067. bigendian="no"
  1068. else
  1069. cat > $TMPC << EOF
  1070. #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  1071. # error BIG
  1072. #endif
  1073. int main(void) { return 0; }
  1074. EOF
  1075. if ! compile_prog ; then
  1076. bigendian="yes"
  1077. else
  1078. echo big/little test failed
  1079. exit 1
  1080. fi
  1081. fi
  1082. ##########################################
  1083. # detect rust triple
  1084. if test "$rust" != disabled && has "$rustc" && $rustc -vV > "${TMPDIR1}/${TMPB}.out"; then
  1085. rust_host_triple=$(sed -n 's/^host: //p' "${TMPDIR1}/${TMPB}.out")
  1086. else
  1087. if test "$rust" = enabled; then
  1088. error_exit "could not execute rustc binary \"$rustc\""
  1089. fi
  1090. rust=disabled
  1091. fi
  1092. if test "$rust" != disabled && test -z "$rust_target_triple"; then
  1093. # arch and os generally matches between meson and rust
  1094. rust_arch=$host_arch
  1095. rust_os=$host_os
  1096. rust_machine=unknown
  1097. rust_osvariant=
  1098. # tweak rust_os if needed; also, machine and variant depend on the OS
  1099. android=no
  1100. case "$host_os" in
  1101. darwin)
  1102. # e.g. aarch64-apple-darwin
  1103. rust_machine=apple
  1104. ;;
  1105. linux)
  1106. # detect android/glibc/musl
  1107. if check_define __ANDROID__; then
  1108. rust_osvariant=android
  1109. android=yes
  1110. else
  1111. cat > $TMPC << EOF
  1112. #define _GNU_SOURCE
  1113. #include <features.h>
  1114. #ifndef __USE_GNU
  1115. error using musl
  1116. #endif
  1117. EOF
  1118. if compile_object; then
  1119. rust_osvariant=gnu
  1120. else
  1121. rust_osvariant=musl
  1122. fi
  1123. fi
  1124. case "$cpu" in
  1125. arm)
  1126. # e.g. arm-unknown-linux-gnueabi, arm-unknown-linux-gnueabihf
  1127. write_c_skeleton
  1128. compile_object
  1129. if $READELF -A $TMPO | grep Tag_API_VFP_args: > /dev/null; then
  1130. rust_osvariant=${rust_osvariant}eabihf
  1131. else
  1132. rust_osvariant=${rust_osvariant}eabi
  1133. fi
  1134. ;;
  1135. mips64)
  1136. # e.g. mips64-unknown-linux-gnuabi64
  1137. rust_osvariant=${rust_osvariant}abi64
  1138. ;;
  1139. esac
  1140. ;;
  1141. netbsd)
  1142. # e.g. arm-unknown-netbsd-eabihf
  1143. test "$host_arch" = arm && rust_osvariant=eabihf
  1144. ;;
  1145. sunos)
  1146. rust_machine=pc
  1147. rust_os=solaris
  1148. ;;
  1149. windows)
  1150. # e.g. aarch64-pc-windows-gnullvm, x86_64-pc-windows-gnu (MSVC not supported)
  1151. rust_machine=pc
  1152. if test "$host_arch" = aarch64; then
  1153. rust_osvariant=gnullvm
  1154. else
  1155. rust_osvariant=gnu
  1156. fi
  1157. ;;
  1158. esac
  1159. # now tweak the architecture part, possibly based on pre-canonicalization --cpu
  1160. case "$host_arch" in
  1161. arm)
  1162. # preserve ISA version (armv7 etc.) from $raw_cpu if passed via --cpu
  1163. rust_arch=$raw_cpu
  1164. test "$rust_arch" = arm && test "$rust_os" != linux && rust_arch=armv7
  1165. ;;
  1166. mips)
  1167. # preserve ISA version (mipsisa64r6 etc.) and include endianness
  1168. rust_arch=${raw_cpu%el}
  1169. test "$bigendian" = no && rust_arch=${rust_arch}el
  1170. ;;
  1171. riscv32|riscv64)
  1172. # e.g. riscv64gc-unknown-linux-gnu, but riscv64-linux-android
  1173. test "$android" = no && rust_arch=${rust_arch}gc
  1174. ;;
  1175. sparc64)
  1176. if test "$rust_os" = solaris; then
  1177. rust_arch=sparcv9
  1178. rust_machine=sun
  1179. fi
  1180. ;;
  1181. x86_64)
  1182. # e.g. x86_64-unknown-linux-gnux32
  1183. test "$raw_cpu" = x32 && rust_osvariant=${rust_osvariant}x32
  1184. ;;
  1185. esac
  1186. if test "$android" = yes; then
  1187. # e.g. aarch64-linux-android
  1188. rust_target_triple=$rust_arch-$rust_os-$rust_osvariant
  1189. else
  1190. rust_target_triple=$rust_arch-$rust_machine-$rust_os${rust_osvariant:+-$rust_osvariant}
  1191. fi
  1192. fi
  1193. ##########################################
  1194. # functions to probe cross compilers
  1195. container="no"
  1196. runc=""
  1197. if test $use_containers = "yes" && (has "docker" || has "podman"); then
  1198. case $($python "$source_path"/tests/docker/docker.py --engine "$container_engine" probe) in
  1199. *docker) container=docker ;;
  1200. podman) container=podman ;;
  1201. no) container=no ;;
  1202. esac
  1203. if test "$container" != "no"; then
  1204. docker_py="$python $source_path/tests/docker/docker.py --engine $container"
  1205. runc=$container
  1206. fi
  1207. fi
  1208. # cross compilers defaults, can be overridden with --cross-cc-ARCH
  1209. : ${cross_prefix_aarch64="aarch64-linux-gnu-"}
  1210. : ${cross_prefix_aarch64_be="$cross_prefix_aarch64"}
  1211. : ${cross_prefix_alpha="alpha-linux-gnu-"}
  1212. : ${cross_prefix_arm="arm-linux-gnueabihf-"}
  1213. : ${cross_prefix_armeb="$cross_prefix_arm"}
  1214. : ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
  1215. : ${cross_prefix_loongarch64="loongarch64-unknown-linux-gnu-"}
  1216. : ${cross_prefix_hppa="hppa-linux-gnu-"}
  1217. : ${cross_prefix_i386="i686-linux-gnu-"}
  1218. : ${cross_prefix_m68k="m68k-linux-gnu-"}
  1219. : ${cross_prefix_microblaze="microblaze-linux-musl-"}
  1220. : ${cross_prefix_mips64el="mips64el-linux-gnuabi64-"}
  1221. : ${cross_prefix_mips64="mips64-linux-gnuabi64-"}
  1222. : ${cross_prefix_mipsel="mipsel-linux-gnu-"}
  1223. : ${cross_prefix_mips="mips-linux-gnu-"}
  1224. : ${cross_prefix_ppc="powerpc-linux-gnu-"}
  1225. : ${cross_prefix_ppc64="powerpc64-linux-gnu-"}
  1226. : ${cross_prefix_ppc64le="$cross_prefix_ppc64"}
  1227. : ${cross_prefix_riscv64="riscv64-linux-gnu-"}
  1228. : ${cross_prefix_s390x="s390x-linux-gnu-"}
  1229. : ${cross_prefix_sh4="sh4-linux-gnu-"}
  1230. : ${cross_prefix_sparc64="sparc64-linux-gnu-"}
  1231. : ${cross_prefix_sparc="$cross_prefix_sparc64"}
  1232. : ${cross_prefix_tricore="tricore-"}
  1233. : ${cross_prefix_x86_64="x86_64-linux-gnu-"}
  1234. : ${cross_cc_aarch64_be="$cross_cc_aarch64"}
  1235. : ${cross_cc_cflags_aarch64_be="-mbig-endian"}
  1236. : ${cross_cc_armeb="$cross_cc_arm"}
  1237. : ${cross_cc_cflags_armeb="-mbig-endian"}
  1238. : ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
  1239. : ${cross_cc_cflags_hexagon="-mv73 -O2 -static"}
  1240. : ${cross_cc_cflags_i386="-m32"}
  1241. : ${cross_cc_cflags_ppc="-m32 -mbig-endian"}
  1242. : ${cross_cc_cflags_ppc64="-m64 -mbig-endian"}
  1243. : ${cross_cc_ppc64le="$cross_cc_ppc64"}
  1244. : ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"}
  1245. : ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
  1246. : ${cross_cc_sparc="$cross_cc_sparc64"}
  1247. : ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
  1248. : ${cross_cc_cflags_x86_64="-m64 -mcx16"}
  1249. compute_target_variable() {
  1250. eval "$2="
  1251. if eval test -n "\"\${cross_prefix_$1}\""; then
  1252. if eval has "\"\${cross_prefix_$1}\$3\""; then
  1253. eval "$2=\"\${cross_prefix_$1}\$3\""
  1254. fi
  1255. fi
  1256. }
  1257. have_target() {
  1258. for i; do
  1259. case " $target_list " in
  1260. *" $i "*) return 0;;
  1261. *) ;;
  1262. esac
  1263. done
  1264. return 1
  1265. }
  1266. # probe_target_compiler TARGET
  1267. #
  1268. # Look for a compiler for the given target, either native or cross.
  1269. # Set variables target_* if a compiler is found, and container_cross_*
  1270. # if a Docker-based cross-compiler image is known for the target.
  1271. # Set got_cross_cc to yes/no depending on whether a non-container-based
  1272. # compiler was found.
  1273. #
  1274. # If TARGET is a user-mode emulation target, also set build_static to
  1275. # "y" if static linking is possible.
  1276. #
  1277. probe_target_compiler() {
  1278. # reset all output variables
  1279. got_cross_cc=no
  1280. container_image=
  1281. container_hosts=
  1282. container_cross_prefix=
  1283. container_cross_cc=
  1284. container_cross_ar=
  1285. container_cross_as=
  1286. container_cross_ld=
  1287. container_cross_nm=
  1288. container_cross_objcopy=
  1289. container_cross_ranlib=
  1290. container_cross_strip=
  1291. target_arch=${1%%-*}
  1292. case $target_arch in
  1293. aarch64) container_hosts="x86_64 aarch64" ;;
  1294. aarch64_be) container_hosts="x86_64 aarch64" ;;
  1295. alpha) container_hosts=x86_64 ;;
  1296. arm) container_hosts="x86_64 aarch64" ;;
  1297. hexagon) container_hosts=x86_64 ;;
  1298. hppa) container_hosts=x86_64 ;;
  1299. i386) container_hosts=x86_64 ;;
  1300. loongarch64) container_hosts=x86_64 ;;
  1301. m68k) container_hosts=x86_64 ;;
  1302. microblaze) container_hosts=x86_64 ;;
  1303. mips64el) container_hosts=x86_64 ;;
  1304. mips64) container_hosts=x86_64 ;;
  1305. mipsel) container_hosts=x86_64 ;;
  1306. mips) container_hosts=x86_64 ;;
  1307. ppc) container_hosts=x86_64 ;;
  1308. ppc64|ppc64le) container_hosts=x86_64 ;;
  1309. riscv64) container_hosts=x86_64 ;;
  1310. s390x) container_hosts=x86_64 ;;
  1311. sh4) container_hosts=x86_64 ;;
  1312. sparc64) container_hosts=x86_64 ;;
  1313. tricore) container_hosts=x86_64 ;;
  1314. x86_64) container_hosts="aarch64 ppc64le x86_64" ;;
  1315. xtensa*) container_hosts=x86_64 ;;
  1316. esac
  1317. for host in $container_hosts; do
  1318. test "$container" != no || continue
  1319. test "$host" = "$cpu" || continue
  1320. case $target_arch in
  1321. # debian-all-test-cross architectures
  1322. aarch64_be)
  1323. container_image=debian-all-test-cross
  1324. container_cross_prefix=aarch64-linux-gnu-
  1325. ;;
  1326. hppa|m68k|mips|riscv64|sparc64)
  1327. container_image=debian-all-test-cross
  1328. ;;
  1329. mips64)
  1330. container_image=debian-all-test-cross
  1331. container_cross_prefix=mips64-linux-gnuabi64-
  1332. ;;
  1333. ppc|ppc64|ppc64le)
  1334. container_image=debian-all-test-cross
  1335. container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu-
  1336. ;;
  1337. # debian-legacy-test-cross architectures (need Debian 11)
  1338. # - libc6.1-dev-alpha-cross: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1054412
  1339. # - sh4-linux-user: binaries don't run with bookworm compiler
  1340. alpha|sh4)
  1341. container_image=debian-legacy-test-cross
  1342. ;;
  1343. # architectures with individual containers
  1344. aarch64)
  1345. # We don't have any bigendian build tools so we only use this for AArch64
  1346. container_image=debian-arm64-cross
  1347. ;;
  1348. arm)
  1349. # We don't have any bigendian build tools so we only use this for ARM
  1350. container_image=debian-armhf-cross
  1351. container_cross_prefix=arm-linux-gnueabihf-
  1352. ;;
  1353. hexagon)
  1354. container_cross_prefix=hexagon-unknown-linux-musl-
  1355. container_cross_cc=${container_cross_prefix}clang
  1356. ;;
  1357. i386)
  1358. container_image=debian-i686-cross
  1359. container_cross_prefix=i686-linux-gnu-
  1360. ;;
  1361. loongarch64)
  1362. container_image=debian-loongarch-cross
  1363. container_cross_prefix=loongarch64-unknown-linux-gnu-
  1364. ;;
  1365. microblaze)
  1366. container_cross_prefix=microblaze-linux-musl-
  1367. ;;
  1368. mips64el)
  1369. container_image=debian-all-test-cross
  1370. container_cross_prefix=mips64el-linux-gnuabi64-
  1371. ;;
  1372. tricore)
  1373. container_image=debian-tricore-cross
  1374. container_cross_prefix=tricore-
  1375. ;;
  1376. x86_64)
  1377. container_image=debian-amd64-cross
  1378. ;;
  1379. xtensa*)
  1380. container_image=debian-xtensa-cross
  1381. # default to the dc232b cpu
  1382. container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
  1383. ;;
  1384. esac
  1385. # Debian and GNU architecture names usually match
  1386. : ${container_image:=debian-$target_arch-cross}
  1387. : ${container_cross_prefix:=$target_arch-linux-gnu-}
  1388. : ${container_cross_cc:=${container_cross_prefix}gcc}
  1389. : ${container_cross_ar:=${container_cross_prefix}ar}
  1390. : ${container_cross_as:=${container_cross_prefix}as}
  1391. : ${container_cross_ld:=${container_cross_prefix}ld}
  1392. : ${container_cross_nm:=${container_cross_prefix}nm}
  1393. : ${container_cross_objcopy:=${container_cross_prefix}objcopy}
  1394. : ${container_cross_ranlib:=${container_cross_prefix}ranlib}
  1395. : ${container_cross_strip:=${container_cross_prefix}strip}
  1396. done
  1397. try=cross
  1398. # For softmmu/roms also look for a bi-endian or multilib-enabled host compiler
  1399. if [ "${1%softmmu}" != "$1" ] || test "$target_arch" = "$cpu"; then
  1400. case "$target_arch:$cpu" in
  1401. aarch64_be:aarch64 | \
  1402. armeb:arm | \
  1403. i386:x86_64 | \
  1404. mips*:mips64 | \
  1405. ppc*:ppc64 | \
  1406. sparc:sparc64 | \
  1407. "$cpu:$cpu")
  1408. try='native cross' ;;
  1409. esac
  1410. fi
  1411. eval "target_cflags=\${cross_cc_cflags_$target_arch}"
  1412. for thistry in $try; do
  1413. case $thistry in
  1414. native)
  1415. target_cc=$cc
  1416. target_ccas=$ccas
  1417. target_ar=$ar
  1418. target_as=$as
  1419. target_ld=$ld
  1420. target_nm=$nm
  1421. target_objcopy=$objcopy
  1422. target_ranlib=$ranlib
  1423. target_strip=$strip
  1424. ;;
  1425. cross)
  1426. target_cc=
  1427. if eval test -n "\"\${cross_cc_$target_arch}\""; then
  1428. if eval has "\"\${cross_cc_$target_arch}\""; then
  1429. eval "target_cc=\"\${cross_cc_$target_arch}\""
  1430. fi
  1431. else
  1432. compute_target_variable $target_arch target_cc gcc
  1433. fi
  1434. target_ccas=$target_cc
  1435. compute_target_variable $target_arch target_ar ar
  1436. compute_target_variable $target_arch target_as as
  1437. compute_target_variable $target_arch target_ld ld
  1438. compute_target_variable $target_arch target_nm nm
  1439. compute_target_variable $target_arch target_objcopy objcopy
  1440. compute_target_variable $target_arch target_ranlib ranlib
  1441. compute_target_variable $target_arch target_strip strip
  1442. ;;
  1443. esac
  1444. if test -n "$target_cc"; then
  1445. case $target_arch in
  1446. i386|x86_64)
  1447. if $target_cc --version | grep -qi "clang"; then
  1448. continue
  1449. fi
  1450. ;;
  1451. esac
  1452. elif test -n "$target_as" && test -n "$target_ld"; then
  1453. # Special handling for assembler only targets
  1454. case $target in
  1455. tricore-softmmu)
  1456. build_static=
  1457. got_cross_cc=yes
  1458. break
  1459. ;;
  1460. *)
  1461. continue
  1462. ;;
  1463. esac
  1464. else
  1465. continue
  1466. fi
  1467. write_c_skeleton
  1468. case $1 in
  1469. *-softmmu)
  1470. if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC &&
  1471. do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then
  1472. got_cross_cc=yes
  1473. break
  1474. fi
  1475. ;;
  1476. *)
  1477. if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC -static ; then
  1478. build_static=y
  1479. got_cross_cc=yes
  1480. break
  1481. fi
  1482. if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC ; then
  1483. build_static=
  1484. got_cross_cc=yes
  1485. break
  1486. fi
  1487. ;;
  1488. esac
  1489. done
  1490. if test $got_cross_cc != yes; then
  1491. build_static=
  1492. target_cc=
  1493. target_ccas=
  1494. target_ar=
  1495. target_as=
  1496. target_ld=
  1497. target_nm=
  1498. target_objcopy=
  1499. target_ranlib=
  1500. target_strip=
  1501. fi
  1502. test -n "$target_cc"
  1503. }
  1504. write_target_makefile() {
  1505. echo "EXTRA_CFLAGS=$target_cflags"
  1506. if test -z "$target_cc" && test -z "$target_as"; then
  1507. test -z "$container_image" && error_exit "Internal error: could not find cross compiler for $1?"
  1508. echo "$1: docker-image-$container_image" >> Makefile.prereqs
  1509. if test -n "$container_cross_cc"; then
  1510. echo "CC=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
  1511. echo "CCAS=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
  1512. fi
  1513. echo "AR=$docker_py cc --cc $container_cross_ar -i qemu/$container_image -s $source_path --"
  1514. echo "AS=$docker_py cc --cc $container_cross_as -i qemu/$container_image -s $source_path --"
  1515. echo "LD=$docker_py cc --cc $container_cross_ld -i qemu/$container_image -s $source_path --"
  1516. echo "NM=$docker_py cc --cc $container_cross_nm -i qemu/$container_image -s $source_path --"
  1517. echo "OBJCOPY=$docker_py cc --cc $container_cross_objcopy -i qemu/$container_image -s $source_path --"
  1518. echo "RANLIB=$docker_py cc --cc $container_cross_ranlib -i qemu/$container_image -s $source_path --"
  1519. echo "STRIP=$docker_py cc --cc $container_cross_strip -i qemu/$container_image -s $source_path --"
  1520. else
  1521. if test -n "$target_cc"; then
  1522. echo "CC=$target_cc"
  1523. echo "CCAS=$target_ccas"
  1524. fi
  1525. if test -n "$target_ar"; then
  1526. echo "AR=$target_ar"
  1527. fi
  1528. if test -n "$target_as"; then
  1529. echo "AS=$target_as"
  1530. fi
  1531. if test -n "$target_ld"; then
  1532. echo "LD=$target_ld"
  1533. fi
  1534. if test -n "$target_nm"; then
  1535. echo "NM=$target_nm"
  1536. fi
  1537. if test -n "$target_objcopy"; then
  1538. echo "OBJCOPY=$target_objcopy"
  1539. fi
  1540. if test -n "$target_ranlib"; then
  1541. echo "RANLIB=$target_ranlib"
  1542. fi
  1543. if test -n "$target_strip"; then
  1544. echo "STRIP=$target_strip"
  1545. fi
  1546. fi
  1547. }
  1548. #######################################
  1549. # cross-compiled firmware targets
  1550. # Set up build tree symlinks that point back into the source tree
  1551. # (these can be both files and directories).
  1552. # Caution: avoid adding files or directories here using wildcards. This
  1553. # will result in problems later if a new file matching the wildcard is
  1554. # added to the source tree -- nothing will cause configure to be rerun
  1555. # so the build tree will be missing the link back to the new file, and
  1556. # tests might fail. Prefer to keep the relevant files in their own
  1557. # directory and symlink the directory instead.
  1558. LINKS="Makefile"
  1559. LINKS="$LINKS docs/config"
  1560. LINKS="$LINKS pc-bios/optionrom/Makefile"
  1561. LINKS="$LINKS pc-bios/s390-ccw/Makefile"
  1562. LINKS="$LINKS pc-bios/vof/Makefile"
  1563. LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
  1564. LINKS="$LINKS tests/avocado tests/data"
  1565. LINKS="$LINKS tests/qemu-iotests/check tests/qemu-iotests/Makefile"
  1566. LINKS="$LINKS python"
  1567. for f in $LINKS ; do
  1568. if [ -e "$source_path/$f" ]; then
  1569. symlink "$source_path/$f" "$f"
  1570. fi
  1571. done
  1572. # use included Linux headers for KVM architectures
  1573. if test "$host_os" = "linux" && test -n "$linux_arch"; then
  1574. symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
  1575. fi
  1576. echo "# Automatically generated by configure - do not modify" > Makefile.prereqs
  1577. # Mac OS X ships with a broken assembler
  1578. if have_target i386-softmmu x86_64-softmmu && \
  1579. test "$host_os" != "darwin" && test "$host_os" != "sunos" && \
  1580. test "$host_os" != "haiku" && \
  1581. probe_target_compiler i386-softmmu; then
  1582. subdirs="$subdirs pc-bios/optionrom"
  1583. config_mak=pc-bios/optionrom/config.mak
  1584. echo "# Automatically generated by configure - do not modify" > $config_mak
  1585. echo "TOPSRC_DIR=$source_path" >> $config_mak
  1586. write_target_makefile >> $config_mak
  1587. fi
  1588. if have_target ppc-softmmu ppc64-softmmu && \
  1589. probe_target_compiler ppc-softmmu; then
  1590. subdirs="$subdirs pc-bios/vof"
  1591. config_mak=pc-bios/vof/config.mak
  1592. echo "# Automatically generated by configure - do not modify" > $config_mak
  1593. echo "SRC_DIR=$source_path/pc-bios/vof" >> $config_mak
  1594. write_target_makefile >> $config_mak
  1595. fi
  1596. # Only build s390-ccw bios if the compiler has -march=z900 or -march=z10
  1597. # (which is the lowest architecture level that Clang supports)
  1598. if have_target s390x-softmmu && probe_target_compiler s390x-softmmu && \
  1599. GIT=git "$source_path/scripts/git-submodule.sh" "$git_submodules_action" roms/SLOF >> config.log 2>&1; then
  1600. write_c_skeleton
  1601. do_compiler "$target_cc" $target_cc_cflags -march=z900 -o $TMPO -c $TMPC
  1602. has_z900=$?
  1603. if [ $has_z900 = 0 ] || do_compiler "$target_cc" $target_cc_cflags -march=z10 -msoft-float -Werror -o $TMPO -c $TMPC; then
  1604. if [ $has_z900 != 0 ]; then
  1605. echo "WARNING: Your compiler does not support the z900!"
  1606. echo " The s390-ccw bios will only work with guest CPUs >= z10."
  1607. fi
  1608. subdirs="$subdirs pc-bios/s390-ccw"
  1609. config_mak=pc-bios/s390-ccw/config-host.mak
  1610. echo "# Automatically generated by configure - do not modify" > $config_mak
  1611. echo "SRC_PATH=$source_path/pc-bios/s390-ccw" >> $config_mak
  1612. echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_mak
  1613. write_target_makefile >> $config_mak
  1614. fi
  1615. fi
  1616. #######################################
  1617. # generate config-host.mak
  1618. config_host_mak="config-host.mak"
  1619. echo "# Automatically generated by configure - do not modify" > $config_host_mak
  1620. echo >> $config_host_mak
  1621. echo all: >> $config_host_mak
  1622. echo "SRC_PATH=$source_path" >> $config_host_mak
  1623. echo "TARGET_DIRS=$target_list" >> $config_host_mak
  1624. echo "GDB=$gdb_bin" >> $config_host_mak
  1625. if test "$container" != no; then
  1626. echo "RUNC=$runc" >> $config_host_mak
  1627. fi
  1628. echo "SUBDIRS=$subdirs" >> $config_host_mak
  1629. if test "$rust" != disabled; then
  1630. echo "RUST_TARGET_TRIPLE=$rust_target_triple" >> $config_host_mak
  1631. fi
  1632. echo "PYTHON=$python" >> $config_host_mak
  1633. echo "MKVENV_ENSUREGROUP=$mkvenv ensuregroup $mkvenv_online_flag" >> $config_host_mak
  1634. echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
  1635. echo "MESON=$meson" >> $config_host_mak
  1636. echo "NINJA=$ninja" >> $config_host_mak
  1637. echo "EXESUF=$EXESUF" >> $config_host_mak
  1638. if test "$default_targets" = "yes"; then
  1639. echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
  1640. fi
  1641. # tests/tcg configuration
  1642. mkdir -p tests/tcg
  1643. echo "# Automatically generated by configure - do not modify" > tests/tcg/$config_host_mak
  1644. echo "SRC_PATH=$source_path" >> tests/tcg/$config_host_mak
  1645. if test "$plugins" = "yes" ; then
  1646. echo "CONFIG_PLUGIN=y" >> tests/tcg/$config_host_mak
  1647. fi
  1648. tcg_tests_targets=
  1649. for target in $target_list; do
  1650. arch=${target%%-*}
  1651. case $target in
  1652. xtensa*-linux-user)
  1653. # the toolchain is not complete with headers, only build system tests
  1654. continue
  1655. ;;
  1656. *-softmmu)
  1657. test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || continue
  1658. qemu="qemu-system-$arch"
  1659. ;;
  1660. *-linux-user|*-bsd-user)
  1661. qemu="qemu-$arch"
  1662. ;;
  1663. esac
  1664. if probe_target_compiler $target || test -n "$container_image"; then
  1665. test -n "$container_image" && build_static=y
  1666. mkdir -p "tests/tcg/$target"
  1667. config_target_mak=tests/tcg/$target/config-target.mak
  1668. ln -sf "$source_path/tests/tcg/Makefile.target" "tests/tcg/$target/Makefile"
  1669. echo "# Automatically generated by configure - do not modify" > "$config_target_mak"
  1670. echo "TARGET_NAME=$arch" >> "$config_target_mak"
  1671. echo "TARGET=$target" >> "$config_target_mak"
  1672. write_target_makefile "build-tcg-tests-$target" >> "$config_target_mak"
  1673. echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
  1674. echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
  1675. # will GDB work with these binaries?
  1676. if test "${gdb_arches#*$arch}" != "$gdb_arches"; then
  1677. echo "GDB=$gdb_bin" >> $config_target_mak
  1678. fi
  1679. if test "${gdb_arches#*aarch64}" != "$gdb_arches" && version_ge $gdb_version 15.1; then
  1680. echo "GDB_HAS_MTE=y" >> $config_target_mak
  1681. fi
  1682. if test "${gdb_arches#*aarch64}" != "$gdb_arches" && version_ge $gdb_version 16.0; then
  1683. # GDB has to support MTE in baremetal to allow debugging MTE in QEMU system mode
  1684. echo "GDB_SUPPORTS_MTE_IN_BAREMETAL=y" >> $config_target_mak
  1685. fi
  1686. echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs
  1687. tcg_tests_targets="$tcg_tests_targets $target"
  1688. fi
  1689. done
  1690. if test "$tcg" = "enabled"; then
  1691. echo "TCG_TESTS_TARGETS=$tcg_tests_targets" >> $config_host_mak
  1692. fi
  1693. if test "$skip_meson" = no; then
  1694. cross="config-meson.cross.new"
  1695. meson_quote() {
  1696. test $# = 0 && return
  1697. echo "'$(echo $* | sed "s/ /','/g")'"
  1698. }
  1699. echo "# Automatically generated by configure - do not modify" > $cross
  1700. echo "[properties]" >> $cross
  1701. # unroll any custom device configs
  1702. for a in $device_archs; do
  1703. eval "c=\$devices_${a}"
  1704. echo "${a}-softmmu = '$c'" >> $cross
  1705. done
  1706. echo "[built-in options]" >> $cross
  1707. echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
  1708. echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
  1709. test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
  1710. echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
  1711. echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
  1712. # Only enable by default for git builds and on select OSes
  1713. echo "# environment defaults, can still be overridden on " >> $cross
  1714. echo "# the command line" >> $cross
  1715. if test -e "$source_path/.git" && \
  1716. { test "$host_os" = linux || test "$host_os" = "windows"; }; then
  1717. echo 'werror = true' >> $cross
  1718. fi
  1719. echo "[project options]" >> $cross
  1720. if test "$SMBD" != ''; then
  1721. echo "smbd = $(meson_quote "$SMBD")" >> $cross
  1722. fi
  1723. if test "${QEMU_GA_MANUFACTURER}" != ''; then
  1724. echo "qemu_ga_manufacturer = $(meson_quote "${QEMU_GA_MANUFACTURER}")" >> $cross
  1725. fi
  1726. if test "${QEMU_GA_DISTRO}" != ''; then
  1727. echo "qemu_ga_distro = $(meson_quote "${QEMU_GA_DISTRO}")" >> $cross
  1728. fi
  1729. if test "${QEMU_GA_VERSION}" != ''; then
  1730. echo "qemu_ga_version = $(meson_quote "${QEMU_GA_VERSION}")" >> $cross
  1731. fi
  1732. echo >> $cross
  1733. echo "[binaries]" >> $cross
  1734. echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
  1735. test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
  1736. test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
  1737. if test "$rust" != disabled; then
  1738. if test "$rust_host_triple" != "$rust_target_triple"; then
  1739. echo "rust = [$(meson_quote $rustc --target "$rust_target_triple")]" >> $cross
  1740. else
  1741. echo "rust = [$(meson_quote $rustc)]" >> $cross
  1742. fi
  1743. fi
  1744. echo "ar = [$(meson_quote $ar)]" >> $cross
  1745. echo "dlltool = [$(meson_quote $dlltool)]" >> $cross
  1746. echo "nm = [$(meson_quote $nm)]" >> $cross
  1747. echo "pkgconfig = [$(meson_quote $pkg_config)]" >> $cross
  1748. echo "pkg-config = [$(meson_quote $pkg_config)]" >> $cross
  1749. echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
  1750. echo "readelf = [$(meson_quote $readelf)]" >> $cross
  1751. if has $sdl2_config; then
  1752. echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
  1753. fi
  1754. echo "strip = [$(meson_quote $strip)]" >> $cross
  1755. echo "widl = [$(meson_quote $widl)]" >> $cross
  1756. echo "windres = [$(meson_quote $windres)]" >> $cross
  1757. echo "windmc = [$(meson_quote $windmc)]" >> $cross
  1758. if test "$cross_compile" = "yes"; then
  1759. echo "[host_machine]" >> $cross
  1760. echo "system = '$host_os'" >> $cross
  1761. case "$cpu" in
  1762. i386)
  1763. echo "cpu_family = 'x86'" >> $cross
  1764. ;;
  1765. *)
  1766. echo "cpu_family = '$cpu'" >> $cross
  1767. ;;
  1768. esac
  1769. echo "cpu = '$cpu'" >> $cross
  1770. if test "$bigendian" = "yes" ; then
  1771. echo "endian = 'big'" >> $cross
  1772. else
  1773. echo "endian = 'little'" >> $cross
  1774. fi
  1775. native="config-meson.native.new"
  1776. echo "# Automatically generated by configure - do not modify" > $native
  1777. echo "[binaries]" >> $native
  1778. echo "c = [$(meson_quote $host_cc)]" >> $native
  1779. if test "$rust" != disabled; then
  1780. echo "rust = [$(meson_quote $rustc)]" >> $cross
  1781. fi
  1782. mv $native config-meson.native
  1783. meson_option_add --native-file
  1784. meson_option_add config-meson.native
  1785. fi
  1786. mv $cross config-meson.cross
  1787. meson_add_machine_file config-meson.cross
  1788. if test -f "$source_path/configs/meson/$host_os.txt"; then
  1789. meson_add_machine_file $source_path/configs/meson/$host_os.txt
  1790. fi
  1791. rm -rf meson-private meson-info meson-logs
  1792. test "$download" = "disabled" && meson_option_add "--wrap-mode=nodownload"
  1793. test "$default_feature" = no && meson_option_add -Dauto_features=disabled
  1794. test "$static" = yes && meson_option_add -Dprefer_static=true
  1795. test "$pie" = no && meson_option_add -Db_pie=false
  1796. # QEMU options
  1797. test "$rust" != "disabled" && meson_option_add "-Drust=$rust"
  1798. test "$cfi" != false && meson_option_add "-Dcfi=$cfi" "-Db_lto=$cfi"
  1799. test "$docs" != auto && meson_option_add "-Ddocs=$docs"
  1800. test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
  1801. test "$plugins" = yes && meson_option_add "-Dplugins=true"
  1802. test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
  1803. run_meson() {
  1804. NINJA=$ninja $meson setup "$@" "$PWD" "$source_path"
  1805. }
  1806. eval run_meson $meson_options
  1807. if test "$?" -ne 0 ; then
  1808. error_exit "meson setup failed"
  1809. fi
  1810. echo "$meson" > build.ninja.stamp
  1811. else
  1812. if test -f meson-private/cmd_line.txt; then
  1813. # Adjust old command line options that were removed
  1814. # sed -i is not portable
  1815. perl -i -ne '
  1816. /^sphinx_build/ && next;
  1817. print;' meson-private/cmd_line.txt
  1818. fi
  1819. fi
  1820. # Save the configure command line for later reuse.
  1821. cat <<EOD >config.status
  1822. #!/bin/sh
  1823. # Generated by configure.
  1824. # Run this file to recreate the current configuration.
  1825. # Compiler output produced by configure, useful for debugging
  1826. # configure, is in config.log if it exists.
  1827. EOD
  1828. preserve_env() {
  1829. envname=$1
  1830. eval envval=\$$envname
  1831. if test -n "$envval"
  1832. then
  1833. echo "$envname='$envval'" >> config.status
  1834. echo "export $envname" >> config.status
  1835. else
  1836. echo "unset $envname" >> config.status
  1837. fi
  1838. }
  1839. # Preserve various env variables that influence what
  1840. # features/build target configure will detect
  1841. preserve_env AR
  1842. preserve_env AS
  1843. preserve_env CC
  1844. preserve_env CFLAGS
  1845. preserve_env CXX
  1846. preserve_env CXXFLAGS
  1847. preserve_env DLLTOOL
  1848. preserve_env LD
  1849. preserve_env LDFLAGS
  1850. preserve_env LD_LIBRARY_PATH
  1851. preserve_env NM
  1852. preserve_env OBJCFLAGS
  1853. preserve_env OBJCOPY
  1854. preserve_env PATH
  1855. preserve_env PKG_CONFIG
  1856. preserve_env PKG_CONFIG_LIBDIR
  1857. preserve_env PKG_CONFIG_PATH
  1858. preserve_env PYTHON
  1859. preserve_env QEMU_GA_MANUFACTURER
  1860. preserve_env QEMU_GA_DISTRO
  1861. preserve_env QEMU_GA_VERSION
  1862. preserve_env SDL2_CONFIG
  1863. preserve_env SMBD
  1864. preserve_env STRIP
  1865. preserve_env WIDL
  1866. preserve_env WINDRES
  1867. preserve_env WINDMC
  1868. printf "exec" >>config.status
  1869. for i in "$0" "$@"; do
  1870. test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
  1871. done
  1872. echo ' "$@"' >>config.status
  1873. chmod +x config.status
  1874. rm -r "$TMPDIR1"
  1875. if test "$rust" != disabled; then
  1876. echo
  1877. echo 'INFO: Rust bindings generation with `bindgen` might fail in some cases where'
  1878. echo 'the detected `libclang` does not match the expected `clang` version/target. In'
  1879. echo 'this case you must pass the path to `clang` and `libclang` to your build'
  1880. echo 'command invocation using the environment variables CLANG_PATH and LIBCLANG_PATH'
  1881. fi