configure 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734
  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.
  7. CLICOLOR_FORCE= GREP_OPTIONS=
  8. unset CLICOLOR_FORCE GREP_OPTIONS
  9. # Don't allow CCACHE, if present, to use cached results of compile tests!
  10. export CCACHE_RECACHE=yes
  11. # make source path absolute
  12. source_path=$(cd "$(dirname -- "$0")"; pwd)
  13. if test "$PWD" = "$source_path"
  14. then
  15. echo "Using './build' as the directory for build output"
  16. MARKER=build/auto-created-by-configure
  17. if test -e build
  18. then
  19. if test -f $MARKER
  20. then
  21. rm -rf build
  22. else
  23. echo "ERROR: ./build dir already exists and was not previously created by configure"
  24. exit 1
  25. fi
  26. fi
  27. if ! mkdir build || ! touch $MARKER
  28. then
  29. echo "ERROR: Could not create ./build directory. Check the permissions on"
  30. echo "your source directory, or try doing an out-of-tree build."
  31. exit 1
  32. fi
  33. cat > GNUmakefile <<'EOF'
  34. # This file is auto-generated by configure to support in-source tree
  35. # 'make' command invocation
  36. ifeq ($(MAKECMDGOALS),)
  37. recurse: all
  38. endif
  39. .NOTPARALLEL: %
  40. %: force
  41. @echo 'changing dir to build for $(MAKE) "$(MAKECMDGOALS)"...'
  42. @$(MAKE) -C build -f Makefile $(MAKECMDGOALS)
  43. @if test "$(MAKECMDGOALS)" = "distclean" && \
  44. test -e build/auto-created-by-configure ; \
  45. then \
  46. rm -rf build GNUmakefile ; \
  47. fi
  48. force: ;
  49. .PHONY: force
  50. GNUmakefile: ;
  51. EOF
  52. cd build
  53. exec "$source_path/configure" "$@"
  54. fi
  55. # Temporary directory used for files created while
  56. # configure runs. Since it is in the build directory
  57. # we can safely blow away any previous version of it
  58. # (and we need not jump through hoops to try to delete
  59. # it when configure exits.)
  60. TMPDIR1="config-temp"
  61. rm -rf "${TMPDIR1}"
  62. if ! mkdir -p "${TMPDIR1}"; then
  63. echo "ERROR: failed to create temporary directory"
  64. exit 1
  65. fi
  66. TMPB="qemu-conf"
  67. TMPC="${TMPDIR1}/${TMPB}.c"
  68. TMPO="${TMPDIR1}/${TMPB}.o"
  69. TMPM="${TMPDIR1}/${TMPB}.m"
  70. TMPE="${TMPDIR1}/${TMPB}.exe"
  71. rm -f config.log
  72. # Print a helpful header at the top of config.log
  73. echo "# QEMU configure log $(date)" >> config.log
  74. printf "# Configured with:" >> config.log
  75. # repeat the invocation to log and stdout for CI
  76. invoke=$(printf " '%s'" "$0" "$@")
  77. test -n "$GITLAB_CI" && echo "configuring with: $invoke"
  78. { echo "$invoke"; echo; echo "#"; } >> config.log
  79. quote_sh() {
  80. printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
  81. }
  82. print_error() {
  83. (echo
  84. echo "ERROR: $1"
  85. while test -n "$2"; do
  86. echo " $2"
  87. shift
  88. done
  89. echo) >&2
  90. }
  91. error_exit() {
  92. print_error "$@"
  93. exit 1
  94. }
  95. do_compiler() {
  96. # Run the compiler, capturing its output to the log. First argument
  97. # is compiler binary to execute.
  98. compiler="$1"
  99. shift
  100. if test -n "$BASH_VERSION"; then eval '
  101. echo >>config.log "
  102. funcs: ${FUNCNAME[*]}
  103. lines: ${BASH_LINENO[*]}"
  104. '; fi
  105. echo $compiler "$@" >> config.log
  106. $compiler "$@" >> config.log 2>&1 || return $?
  107. }
  108. do_compiler_werror() {
  109. # Run the compiler, capturing its output to the log. First argument
  110. # is compiler binary to execute.
  111. compiler="$1"
  112. shift
  113. if test -n "$BASH_VERSION"; then eval '
  114. echo >>config.log "
  115. funcs: ${FUNCNAME[*]}
  116. lines: ${BASH_LINENO[*]}"
  117. '; fi
  118. echo $compiler "$@" >> config.log
  119. $compiler "$@" >> config.log 2>&1 || return $?
  120. # Test passed. If this is an --enable-werror build, rerun
  121. # the test with -Werror and bail out if it fails. This
  122. # makes warning-generating-errors in configure test code
  123. # obvious to developers.
  124. if test "$werror" != "yes"; then
  125. return 0
  126. fi
  127. # Don't bother rerunning the compile if we were already using -Werror
  128. case "$*" in
  129. *-Werror*)
  130. return 0
  131. ;;
  132. esac
  133. echo $compiler -Werror "$@" >> config.log
  134. $compiler -Werror "$@" >> config.log 2>&1 && return $?
  135. error_exit "configure test passed without -Werror but failed with -Werror." \
  136. "This is probably a bug in the configure script. The failing command" \
  137. "will be at the bottom of config.log." \
  138. "You can run configure with --disable-werror to bypass this check."
  139. }
  140. do_cc() {
  141. do_compiler_werror "$cc" $CPU_CFLAGS "$@"
  142. }
  143. do_objc() {
  144. do_compiler_werror "$objcc" $CPU_CFLAGS "$@"
  145. }
  146. # Append $2 to the variable named $1, with space separation
  147. add_to() {
  148. eval $1=\${$1:+\"\$$1 \"}\$2
  149. }
  150. compile_object() {
  151. local_cflags="$1"
  152. do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
  153. }
  154. compile_prog() {
  155. local_cflags="$1"
  156. local_ldflags="$2"
  157. do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
  158. $LDFLAGS $EXTRA_LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
  159. }
  160. # symbolically link $1 to $2. Portable version of "ln -sf".
  161. symlink() {
  162. rm -rf "$2"
  163. mkdir -p "$(dirname "$2")"
  164. ln -s "$1" "$2"
  165. }
  166. # check whether a command is available to this shell (may be either an
  167. # executable or a builtin)
  168. has() {
  169. type "$1" >/dev/null 2>&1
  170. }
  171. version_ge () {
  172. local_ver1=$(expr "$1" : '\([0-9.]*\)' | tr . ' ')
  173. local_ver2=$(echo "$2" | tr . ' ')
  174. while true; do
  175. set x $local_ver1
  176. local_first=${2-0}
  177. # 'shift 2' if $2 is set, or 'shift' if $2 is not set
  178. shift ${2:+2}
  179. local_ver1=$*
  180. set x $local_ver2
  181. # the second argument finished, the first must be greater or equal
  182. test $# = 1 && return 0
  183. test $local_first -lt $2 && return 1
  184. test $local_first -gt $2 && return 0
  185. shift ${2:+2}
  186. local_ver2=$*
  187. done
  188. }
  189. if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
  190. then
  191. error_exit "main directory cannot contain spaces nor colons"
  192. fi
  193. # default parameters
  194. cpu=""
  195. static="no"
  196. cross_compile="no"
  197. cross_prefix=""
  198. host_cc="cc"
  199. stack_protector=""
  200. safe_stack=""
  201. use_containers="yes"
  202. gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
  203. gdb_arches=""
  204. glib_has_gslice="no"
  205. if test -e "$source_path/.git"
  206. then
  207. git_submodules_action="update"
  208. else
  209. git_submodules_action="ignore"
  210. fi
  211. git_submodules="ui/keycodemapdb"
  212. git="git"
  213. # Don't accept a target_list environment variable.
  214. unset target_list
  215. unset target_list_exclude
  216. # Default value for a variable defining feature "foo".
  217. # * foo="no" feature will only be used if --enable-foo arg is given
  218. # * foo="" feature will be searched for, and if found, will be used
  219. # unless --disable-foo is given
  220. # * foo="yes" this value will only be set by --enable-foo flag.
  221. # feature will searched for,
  222. # if not found, configure exits with error
  223. #
  224. # Always add --enable-foo and --disable-foo command line args.
  225. # Distributions want to ensure that several features are compiled in, and it
  226. # is impossible without a --enable-foo that exits if a feature is not found.
  227. default_feature=""
  228. # parse CC options second
  229. for opt do
  230. optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
  231. case "$opt" in
  232. --without-default-features)
  233. default_feature="no"
  234. ;;
  235. esac
  236. done
  237. EXTRA_CFLAGS=""
  238. EXTRA_CXXFLAGS=""
  239. EXTRA_OBJCFLAGS=""
  240. EXTRA_LDFLAGS=""
  241. debug_tcg="no"
  242. sanitizers="no"
  243. tsan="no"
  244. fortify_source="yes"
  245. EXESUF=""
  246. modules="no"
  247. prefix="/usr/local"
  248. qemu_suffix="qemu"
  249. softmmu="yes"
  250. linux_user=""
  251. bsd_user=""
  252. pie=""
  253. coroutine=""
  254. plugins="$default_feature"
  255. meson=""
  256. ninja=""
  257. bindir="bin"
  258. skip_meson=no
  259. shared_lib="no"
  260. vfio_user_server="disabled"
  261. # The following Meson options are handled manually (still they
  262. # are included in the automatically generated help message)
  263. # 1. Track which submodules are needed
  264. fdt="auto"
  265. # 2. Automatically enable/disable other options
  266. tcg="auto"
  267. cfi="false"
  268. # parse CC options second
  269. for opt do
  270. optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
  271. case "$opt" in
  272. --cross-prefix=*) cross_prefix="$optarg"
  273. cross_compile="yes"
  274. ;;
  275. --cc=*) CC="$optarg"
  276. ;;
  277. --cxx=*) CXX="$optarg"
  278. ;;
  279. --cpu=*) cpu="$optarg"
  280. ;;
  281. --extra-cflags=*)
  282. EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
  283. EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
  284. EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
  285. ;;
  286. --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
  287. ;;
  288. --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
  289. ;;
  290. --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
  291. ;;
  292. --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
  293. ;;
  294. --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
  295. eval "cross_cc_cflags_${cc_arch}=\$optarg"
  296. ;;
  297. --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
  298. eval "cross_cc_${cc_arch}=\$optarg"
  299. ;;
  300. --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-prefix-FOO option"
  301. ;;
  302. --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
  303. eval "cross_prefix_${cc_arch}=\$optarg"
  304. ;;
  305. esac
  306. done
  307. # Preferred compiler:
  308. # ${CC} (if set)
  309. # ${cross_prefix}gcc (if cross-prefix specified)
  310. # system compiler
  311. if test -z "${CC}${cross_prefix}"; then
  312. cc="$host_cc"
  313. else
  314. cc="${CC-${cross_prefix}gcc}"
  315. fi
  316. if test -z "${CXX}${cross_prefix}"; then
  317. cxx="c++"
  318. else
  319. cxx="${CXX-${cross_prefix}g++}"
  320. fi
  321. ar="${AR-${cross_prefix}ar}"
  322. as="${AS-${cross_prefix}as}"
  323. ccas="${CCAS-$cc}"
  324. objcopy="${OBJCOPY-${cross_prefix}objcopy}"
  325. ld="${LD-${cross_prefix}ld}"
  326. ranlib="${RANLIB-${cross_prefix}ranlib}"
  327. nm="${NM-${cross_prefix}nm}"
  328. smbd="$SMBD"
  329. strip="${STRIP-${cross_prefix}strip}"
  330. widl="${WIDL-${cross_prefix}widl}"
  331. windres="${WINDRES-${cross_prefix}windres}"
  332. windmc="${WINDMC-${cross_prefix}windmc}"
  333. pkg_config_exe="${PKG_CONFIG-${cross_prefix}pkg-config}"
  334. query_pkg_config() {
  335. "${pkg_config_exe}" ${QEMU_PKG_CONFIG_FLAGS} "$@"
  336. }
  337. pkg_config=query_pkg_config
  338. sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
  339. # default flags for all hosts
  340. # We use -fwrapv to tell the compiler that we require a C dialect where
  341. # left shift of signed integers is well defined and has the expected
  342. # 2s-complement style results. (Both clang and gcc agree that it
  343. # provides these semantics.)
  344. QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
  345. QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
  346. QEMU_LDFLAGS=
  347. # Flags that are needed during configure but later taken care of by Meson
  348. CONFIGURE_CFLAGS="-std=gnu11 -Wall"
  349. CONFIGURE_LDFLAGS=
  350. check_define() {
  351. cat > $TMPC <<EOF
  352. #if !defined($1)
  353. #error $1 not defined
  354. #endif
  355. int main(void) { return 0; }
  356. EOF
  357. compile_object
  358. }
  359. check_include() {
  360. cat > $TMPC <<EOF
  361. #include <$1>
  362. int main(void) { return 0; }
  363. EOF
  364. compile_object
  365. }
  366. write_c_skeleton() {
  367. cat > $TMPC <<EOF
  368. int main(void) { return 0; }
  369. EOF
  370. }
  371. if check_define __linux__ ; then
  372. targetos=linux
  373. elif check_define _WIN32 ; then
  374. targetos=windows
  375. elif check_define __OpenBSD__ ; then
  376. targetos=openbsd
  377. elif check_define __sun__ ; then
  378. targetos=sunos
  379. elif check_define __HAIKU__ ; then
  380. targetos=haiku
  381. elif check_define __FreeBSD__ ; then
  382. targetos=freebsd
  383. elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then
  384. targetos=gnu/kfreebsd
  385. elif check_define __DragonFly__ ; then
  386. targetos=dragonfly
  387. elif check_define __NetBSD__; then
  388. targetos=netbsd
  389. elif check_define __APPLE__; then
  390. targetos=darwin
  391. else
  392. # This is a fatal error, but don't report it yet, because we
  393. # might be going to just print the --help text, or it might
  394. # be the result of a missing compiler.
  395. targetos=bogus
  396. fi
  397. # OS specific
  398. mingw32="no"
  399. bsd="no"
  400. linux="no"
  401. solaris="no"
  402. case $targetos in
  403. windows)
  404. mingw32="yes"
  405. plugins="no"
  406. pie="no"
  407. ;;
  408. gnu/kfreebsd)
  409. bsd="yes"
  410. ;;
  411. freebsd)
  412. bsd="yes"
  413. make="${MAKE-gmake}"
  414. # needed for kinfo_getvmmap(3) in libutil.h
  415. ;;
  416. dragonfly)
  417. bsd="yes"
  418. make="${MAKE-gmake}"
  419. ;;
  420. netbsd)
  421. bsd="yes"
  422. make="${MAKE-gmake}"
  423. ;;
  424. openbsd)
  425. bsd="yes"
  426. make="${MAKE-gmake}"
  427. ;;
  428. darwin)
  429. bsd="yes"
  430. darwin="yes"
  431. # Disable attempts to use ObjectiveC features in os/object.h since they
  432. # won't work when we're compiling with gcc as a C compiler.
  433. QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
  434. ;;
  435. sunos)
  436. solaris="yes"
  437. make="${MAKE-gmake}"
  438. # needed for CMSG_ macros in sys/socket.h
  439. QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS"
  440. # needed for TIOCWIN* defines in termios.h
  441. QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS"
  442. ;;
  443. haiku)
  444. pie="no"
  445. QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS"
  446. ;;
  447. linux)
  448. linux="yes"
  449. ;;
  450. esac
  451. if test ! -z "$cpu" ; then
  452. # command line argument
  453. :
  454. elif check_define __i386__ ; then
  455. cpu="i386"
  456. elif check_define __x86_64__ ; then
  457. if check_define __ILP32__ ; then
  458. cpu="x32"
  459. else
  460. cpu="x86_64"
  461. fi
  462. elif check_define __sparc__ ; then
  463. if check_define __arch64__ ; then
  464. cpu="sparc64"
  465. else
  466. cpu="sparc"
  467. fi
  468. elif check_define _ARCH_PPC ; then
  469. if check_define _ARCH_PPC64 ; then
  470. if check_define _LITTLE_ENDIAN ; then
  471. cpu="ppc64le"
  472. else
  473. cpu="ppc64"
  474. fi
  475. else
  476. cpu="ppc"
  477. fi
  478. elif check_define __mips__ ; then
  479. cpu="mips"
  480. elif check_define __s390__ ; then
  481. if check_define __s390x__ ; then
  482. cpu="s390x"
  483. else
  484. cpu="s390"
  485. fi
  486. elif check_define __riscv ; then
  487. cpu="riscv"
  488. elif check_define __arm__ ; then
  489. cpu="arm"
  490. elif check_define __aarch64__ ; then
  491. cpu="aarch64"
  492. elif check_define __loongarch64 ; then
  493. cpu="loongarch64"
  494. else
  495. # Using uname is really broken, but it is just a fallback for architectures
  496. # that are going to use TCI anyway
  497. cpu=$(uname -m)
  498. echo "WARNING: unrecognized host CPU, proceeding with 'uname -m' output '$cpu'"
  499. fi
  500. # Normalise host CPU name and set multilib cflags. The canonicalization
  501. # isn't really necessary, because the architectures that we check for
  502. # should not hit the 'uname -m' case, but better safe than sorry.
  503. # Note that this case should only have supported host CPUs, not guests.
  504. case "$cpu" in
  505. armv*b|armv*l|arm)
  506. cpu="arm" ;;
  507. i386|i486|i586|i686)
  508. cpu="i386"
  509. CPU_CFLAGS="-m32" ;;
  510. x32)
  511. cpu="x86_64"
  512. CPU_CFLAGS="-mx32" ;;
  513. x86_64|amd64)
  514. cpu="x86_64"
  515. # ??? Only extremely old AMD cpus do not have cmpxchg16b.
  516. # If we truly care, we should simply detect this case at
  517. # runtime and generate the fallback to serial emulation.
  518. CPU_CFLAGS="-m64 -mcx16" ;;
  519. mips*)
  520. cpu="mips" ;;
  521. ppc)
  522. CPU_CFLAGS="-m32" ;;
  523. ppc64)
  524. CPU_CFLAGS="-m64 -mbig-endian" ;;
  525. ppc64le)
  526. cpu="ppc64"
  527. CPU_CFLAGS="-m64 -mlittle-endian" ;;
  528. s390)
  529. CPU_CFLAGS="-m31" ;;
  530. s390x)
  531. CPU_CFLAGS="-m64" ;;
  532. sparc|sun4[cdmuv])
  533. cpu="sparc"
  534. CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;;
  535. sparc64)
  536. CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
  537. esac
  538. : ${make=${MAKE-make}}
  539. check_py_version() {
  540. # We require python >= 3.6.
  541. # NB: a True python conditional creates a non-zero return code (Failure)
  542. "$1" -c 'import sys; sys.exit(sys.version_info < (3,6))'
  543. }
  544. python=
  545. first_python=
  546. if test -z "${PYTHON}"; then
  547. explicit_python=no
  548. # A bare 'python' is traditionally python 2.x, but some distros
  549. # have it as python 3.x, so check in both places.
  550. for binary in python3 python python3.11 python3.10 python3.9 python3.8 python3.7 python3.6; do
  551. if has "$binary"; then
  552. python=$(command -v "$binary")
  553. if check_py_version "$python"; then
  554. # This one is good.
  555. first_python=
  556. break
  557. else
  558. first_python=$python
  559. fi
  560. fi
  561. done
  562. else
  563. # Same as above, but only check the environment variable.
  564. has "${PYTHON}" || error_exit "The PYTHON environment variable does not point to an executable"
  565. python=$(command -v "$PYTHON")
  566. explicit_python=yes
  567. if check_py_version "$python"; then
  568. # This one is good.
  569. first_python=
  570. else
  571. first_python=$first_python
  572. fi
  573. fi
  574. # Check for ancillary tools used in testing
  575. genisoimage=
  576. for binary in genisoimage mkisofs
  577. do
  578. if has $binary
  579. then
  580. genisoimage=$(command -v "$binary")
  581. break
  582. fi
  583. done
  584. # Default objcc to clang if available, otherwise use CC
  585. if has clang; then
  586. objcc=clang
  587. else
  588. objcc="$cc"
  589. fi
  590. if test "$mingw32" = "yes" ; then
  591. EXESUF=".exe"
  592. # MinGW needs -mthreads for TLS and macro _MT.
  593. CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS"
  594. prefix="/qemu"
  595. bindir=""
  596. qemu_suffix=""
  597. fi
  598. werror=""
  599. meson_option_build_array() {
  600. printf '['
  601. (if test "$targetos" = windows; then
  602. IFS=\;
  603. else
  604. IFS=:
  605. fi
  606. for e in $1; do
  607. printf '"""'
  608. # backslash escape any '\' and '"' characters
  609. printf "%s" "$e" | sed -e 's/\([\"]\)/\\\1/g'
  610. printf '""",'
  611. done)
  612. printf ']\n'
  613. }
  614. . "$source_path/scripts/meson-buildoptions.sh"
  615. meson_options=
  616. meson_option_add() {
  617. meson_options="$meson_options $(quote_sh "$1")"
  618. }
  619. meson_option_parse() {
  620. meson_options="$meson_options $(_meson_option_parse "$@")"
  621. if test $? -eq 1; then
  622. echo "ERROR: unknown option $1"
  623. echo "Try '$0 --help' for more information"
  624. exit 1
  625. fi
  626. }
  627. for opt do
  628. optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
  629. case "$opt" in
  630. --help|-h) show_help=yes
  631. ;;
  632. --version|-V) exec cat "$source_path/VERSION"
  633. ;;
  634. --prefix=*) prefix="$optarg"
  635. ;;
  636. --cross-prefix=*)
  637. ;;
  638. --cc=*)
  639. ;;
  640. --host-cc=*) host_cc="$optarg"
  641. ;;
  642. --cxx=*)
  643. ;;
  644. --objcc=*) objcc="$optarg"
  645. ;;
  646. --make=*) make="$optarg"
  647. ;;
  648. --install=*)
  649. ;;
  650. --python=*) python="$optarg" ; explicit_python=yes
  651. ;;
  652. --skip-meson) skip_meson=yes
  653. ;;
  654. --meson=*) meson="$optarg"
  655. ;;
  656. --ninja=*) ninja="$optarg"
  657. ;;
  658. --smbd=*) smbd="$optarg"
  659. ;;
  660. --extra-cflags=*)
  661. ;;
  662. --extra-cxxflags=*)
  663. ;;
  664. --extra-objcflags=*)
  665. ;;
  666. --extra-ldflags=*)
  667. ;;
  668. --cross-cc-*)
  669. ;;
  670. --cross-prefix-*)
  671. ;;
  672. --enable-debug-info) meson_option_add -Ddebug=true
  673. ;;
  674. --disable-debug-info) meson_option_add -Ddebug=false
  675. ;;
  676. --enable-modules)
  677. modules="yes"
  678. ;;
  679. --disable-modules)
  680. modules="no"
  681. ;;
  682. --cpu=*)
  683. ;;
  684. --target-list=*) target_list="$optarg"
  685. if test "$target_list_exclude"; then
  686. error_exit "Can't mix --target-list with --target-list-exclude"
  687. fi
  688. ;;
  689. --target-list-exclude=*) target_list_exclude="$optarg"
  690. if test "$target_list"; then
  691. error_exit "Can't mix --target-list-exclude with --target-list"
  692. fi
  693. ;;
  694. --with-default-devices) meson_option_add -Ddefault_devices=true
  695. ;;
  696. --without-default-devices) meson_option_add -Ddefault_devices=false
  697. ;;
  698. --with-devices-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --with-devices-FOO option"
  699. ;;
  700. --with-devices-*) device_arch=${opt#--with-devices-};
  701. device_arch=${device_arch%%=*}
  702. cf=$source_path/configs/devices/$device_arch-softmmu/$optarg.mak
  703. if test -f "$cf"; then
  704. device_archs="$device_archs $device_arch"
  705. eval "devices_${device_arch}=\$optarg"
  706. else
  707. error_exit "File $cf does not exist"
  708. fi
  709. ;;
  710. --without-default-features) # processed above
  711. ;;
  712. --static)
  713. static="yes"
  714. QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
  715. ;;
  716. --bindir=*) bindir="$optarg"
  717. ;;
  718. --with-suffix=*) qemu_suffix="$optarg"
  719. ;;
  720. --host=*|--build=*|\
  721. --disable-dependency-tracking|\
  722. --sbindir=*|--sharedstatedir=*|\
  723. --oldincludedir=*|--datarootdir=*|--infodir=*|\
  724. --htmldir=*|--dvidir=*|--pdfdir=*|--psdir=*)
  725. # These switches are silently ignored, for compatibility with
  726. # autoconf-generated configure scripts. This allows QEMU's
  727. # configure to be used by RPM and similar macros that set
  728. # lots of directory switches by default.
  729. ;;
  730. --enable-debug-tcg) debug_tcg="yes"
  731. ;;
  732. --disable-debug-tcg) debug_tcg="no"
  733. ;;
  734. --enable-debug)
  735. # Enable debugging options that aren't excessively noisy
  736. debug_tcg="yes"
  737. meson_option_parse --enable-debug-mutex ""
  738. meson_option_add -Doptimization=0
  739. fortify_source="no"
  740. ;;
  741. --enable-sanitizers) sanitizers="yes"
  742. ;;
  743. --disable-sanitizers) sanitizers="no"
  744. ;;
  745. --enable-tsan) tsan="yes"
  746. ;;
  747. --disable-tsan) tsan="no"
  748. ;;
  749. --disable-tcg) tcg="disabled"
  750. plugins="no"
  751. ;;
  752. --enable-tcg) tcg="enabled"
  753. ;;
  754. --disable-system) softmmu="no"
  755. ;;
  756. --enable-system) softmmu="yes"
  757. ;;
  758. --disable-user)
  759. linux_user="no" ;
  760. bsd_user="no" ;
  761. ;;
  762. --enable-user) ;;
  763. --disable-linux-user) linux_user="no"
  764. ;;
  765. --enable-linux-user) linux_user="yes"
  766. ;;
  767. --disable-bsd-user) bsd_user="no"
  768. ;;
  769. --enable-bsd-user) bsd_user="yes"
  770. ;;
  771. --enable-pie) pie="yes"
  772. ;;
  773. --disable-pie) pie="no"
  774. ;;
  775. --enable-werror) werror="yes"
  776. ;;
  777. --disable-werror) werror="no"
  778. ;;
  779. --enable-stack-protector) stack_protector="yes"
  780. ;;
  781. --disable-stack-protector) stack_protector="no"
  782. ;;
  783. --enable-safe-stack) safe_stack="yes"
  784. ;;
  785. --disable-safe-stack) safe_stack="no"
  786. ;;
  787. --enable-cfi)
  788. cfi="true";
  789. meson_option_add -Db_lto=true
  790. ;;
  791. --disable-cfi) cfi="false"
  792. ;;
  793. --disable-fdt) fdt="disabled"
  794. ;;
  795. --enable-fdt) fdt="enabled"
  796. ;;
  797. --enable-fdt=git) fdt="internal"
  798. ;;
  799. --enable-fdt=*) fdt="$optarg"
  800. ;;
  801. --with-coroutine=*) coroutine="$optarg"
  802. ;;
  803. --with-git=*) git="$optarg"
  804. ;;
  805. --with-git-submodules=*)
  806. git_submodules_action="$optarg"
  807. ;;
  808. --enable-plugins) if test "$mingw32" = "yes"; then
  809. error_exit "TCG plugins not currently supported on Windows platforms"
  810. else
  811. plugins="yes"
  812. fi
  813. ;;
  814. --disable-plugins) plugins="no"
  815. ;;
  816. --enable-containers) use_containers="yes"
  817. ;;
  818. --disable-containers) use_containers="no"
  819. ;;
  820. --gdb=*) gdb_bin="$optarg"
  821. ;;
  822. --enable-vfio-user-server) vfio_user_server="enabled"
  823. ;;
  824. --disable-vfio-user-server) vfio_user_server="disabled"
  825. ;;
  826. --enable-shared-lib)
  827. shared_lib="yes"
  828. plugins="no"
  829. ;;
  830. --disable-shared-lib) shared_lib="no"
  831. ;;
  832. # everything else has the same name in configure and meson
  833. --*) meson_option_parse "$opt" "$optarg"
  834. ;;
  835. esac
  836. done
  837. # test for any invalid configuration combinations
  838. if test "$plugins" = "yes" -a "$tcg" = "disabled"; then
  839. error_exit "Can't enable plugins on non-TCG builds"
  840. fi
  841. if test "$plugins" = "yes" -a "$shared_lib" = "yes"; then
  842. error_exit "Can't enable plugins on shared library builds"
  843. fi
  844. case $git_submodules_action in
  845. update|validate)
  846. if test ! -e "$source_path/.git"; then
  847. echo "ERROR: cannot $git_submodules_action git submodules without .git"
  848. exit 1
  849. fi
  850. ;;
  851. ignore)
  852. if ! test -f "$source_path/ui/keycodemapdb/README"
  853. then
  854. echo
  855. echo "ERROR: missing GIT submodules"
  856. echo
  857. if test -e "$source_path/.git"; then
  858. echo "--with-git-submodules=ignore specified but submodules were not"
  859. echo "checked out. Please initialize and update submodules."
  860. else
  861. echo "This is not a GIT checkout but module content appears to"
  862. echo "be missing. Do not use 'git archive' or GitHub download links"
  863. echo "to acquire QEMU source archives. Non-GIT builds are only"
  864. echo "supported with source archives linked from:"
  865. echo
  866. echo " https://www.qemu.org/download/#source"
  867. echo
  868. echo "Developers working with GIT can use scripts/archive-source.sh"
  869. echo "if they need to create valid source archives."
  870. fi
  871. echo
  872. exit 1
  873. fi
  874. ;;
  875. *)
  876. echo "ERROR: invalid --with-git-submodules= value '$git_submodules_action'"
  877. exit 1
  878. ;;
  879. esac
  880. default_target_list=""
  881. mak_wilds=""
  882. if [ "$linux_user" != no ]; then
  883. if [ "$targetos" = linux ] && [ -d "$source_path/linux-user/include/host/$cpu" ]; then
  884. linux_user=yes
  885. elif [ "$linux_user" = yes ]; then
  886. error_exit "linux-user not supported on this architecture"
  887. fi
  888. fi
  889. if [ "$bsd_user" != no ]; then
  890. if [ "$bsd_user" = "" ]; then
  891. test $targetos = freebsd && bsd_user=yes
  892. fi
  893. if [ "$bsd_user" = yes ] && ! [ -d "$source_path/bsd-user/$targetos" ]; then
  894. error_exit "bsd-user not supported on this host OS"
  895. fi
  896. fi
  897. if [ "$softmmu" = "yes" ]; then
  898. mak_wilds="${mak_wilds} $source_path/configs/targets/*-softmmu.mak"
  899. fi
  900. if [ "$linux_user" = "yes" ]; then
  901. mak_wilds="${mak_wilds} $source_path/configs/targets/*-linux-user.mak"
  902. fi
  903. if [ "$bsd_user" = "yes" ]; then
  904. mak_wilds="${mak_wilds} $source_path/configs/targets/*-bsd-user.mak"
  905. fi
  906. for config in $mak_wilds; do
  907. target="$(basename "$config" .mak)"
  908. if echo "$target_list_exclude" | grep -vq "$target"; then
  909. default_target_list="${default_target_list} $target"
  910. fi
  911. done
  912. if test x"$show_help" = x"yes" ; then
  913. cat << EOF
  914. Usage: configure [options]
  915. Options: [defaults in brackets after descriptions]
  916. Standard options:
  917. --help print this message
  918. --prefix=PREFIX install in PREFIX [$prefix]
  919. --target-list=LIST set target list (default: build all)
  920. $(echo Available targets: $default_target_list | \
  921. fold -s -w 53 | sed -e 's/^/ /')
  922. --target-list-exclude=LIST exclude a set of targets from the default target-list
  923. Advanced options (experts only):
  924. --cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
  925. --cc=CC use C compiler CC [$cc]
  926. --host-cc=CC use C compiler CC [$host_cc] for code run at
  927. build time
  928. --cxx=CXX use C++ compiler CXX [$cxx]
  929. --objcc=OBJCC use Objective-C compiler OBJCC [$objcc]
  930. --extra-cflags=CFLAGS append extra C compiler flags CFLAGS
  931. --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
  932. --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
  933. --extra-ldflags=LDFLAGS append extra linker flags LDFLAGS
  934. --cross-cc-ARCH=CC use compiler when building ARCH guest test cases
  935. --cross-cc-cflags-ARCH= use compiler flags when building ARCH guest tests
  936. --cross-prefix-ARCH=PREFIX cross compiler prefix when building ARCH guest test cases
  937. --make=MAKE use specified make [$make]
  938. --python=PYTHON use specified python [$python]
  939. --meson=MESON use specified meson [$meson]
  940. --ninja=NINJA use specified ninja [$ninja]
  941. --smbd=SMBD use specified smbd [$smbd]
  942. --with-git=GIT use specified git [$git]
  943. --with-git-submodules=update update git submodules (default if .git dir exists)
  944. --with-git-submodules=validate fail if git submodules are not up to date
  945. --with-git-submodules=ignore do not update or check git submodules (default if no .git dir)
  946. --static enable static build [$static]
  947. --bindir=PATH install binaries in PATH
  948. --with-suffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir/docdir [$qemu_suffix]
  949. --without-default-features default all --enable-* options to "disabled"
  950. --without-default-devices do not include any device that is not needed to
  951. start the emulator (only use if you are including
  952. desired devices in configs/devices/)
  953. --with-devices-ARCH=NAME override default configs/devices
  954. --enable-debug enable common debug build options
  955. --enable-sanitizers enable default sanitizers
  956. --enable-tsan enable thread sanitizer
  957. --disable-werror disable compilation abort on warning
  958. --disable-stack-protector disable compiler-provided stack protection
  959. --cpu=CPU Build for host CPU [$cpu]
  960. --with-coroutine=BACKEND coroutine backend. Supported options:
  961. ucontext, libucontext, sigaltstack, windows
  962. --enable-plugins
  963. enable plugins via shared library loading
  964. --disable-containers don't use containers for cross-building
  965. --gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
  966. EOF
  967. meson_options_help
  968. cat << EOF
  969. system all system emulation targets
  970. user supported user emulation targets
  971. linux-user all linux usermode emulation targets
  972. bsd-user all BSD usermode emulation targets
  973. pie Position Independent Executables
  974. modules modules support (non-Windows)
  975. debug-tcg TCG debugging (default is disabled)
  976. debug-info debugging information
  977. safe-stack SafeStack Stack Smash Protection. Depends on
  978. clang/llvm and requires coroutine backend ucontext.
  979. NOTE: The object files are built at the place where configure is launched
  980. EOF
  981. exit 0
  982. fi
  983. # Remove old dependency files to make sure that they get properly regenerated
  984. rm -f ./*/config-devices.mak.d
  985. if test -z "$python"
  986. then
  987. # If first_python is set, there was a binary somewhere even though
  988. # it was not suitable. Use it for the error message.
  989. if test -n "$first_python"; then
  990. error_exit "Cannot use '$first_python', Python >= 3.6 is required." \
  991. "Use --python=/path/to/python to specify a supported Python."
  992. else
  993. error_exit "Python not found. Use --python=/path/to/python"
  994. fi
  995. fi
  996. if ! has "$make"
  997. then
  998. error_exit "GNU make ($make) not found"
  999. fi
  1000. if ! check_py_version "$python"; then
  1001. error_exit "Cannot use '$python', Python >= 3.6 is required." \
  1002. "Use --python=/path/to/python to specify a supported Python."
  1003. fi
  1004. # Resolve PATH + suppress writing compiled files
  1005. python="$(command -v "$python") -B"
  1006. has_meson() {
  1007. local python_dir=$(dirname "$python")
  1008. # PEP405: pyvenv.cfg is either adjacent to the Python executable
  1009. # or one directory above
  1010. if test -f $python_dir/pyvenv.cfg || test -f $python_dir/../pyvenv.cfg; then
  1011. # Ensure that Meson and Python come from the same virtual environment
  1012. test -x "$python_dir/meson" &&
  1013. test "$(command -v meson)" -ef "$python_dir/meson"
  1014. else
  1015. has meson
  1016. fi
  1017. }
  1018. if test -z "$meson"; then
  1019. if test "$explicit_python" = no && has_meson && version_ge "$(meson --version)" 0.61.5; then
  1020. meson=meson
  1021. elif test "$git_submodules_action" != 'ignore' ; then
  1022. meson=git
  1023. elif test -e "${source_path}/meson/meson.py" ; then
  1024. meson=internal
  1025. else
  1026. if test "$explicit_python" = yes; then
  1027. error_exit "--python requires using QEMU's embedded Meson distribution, but it was not found."
  1028. else
  1029. error_exit "Meson not found. Use --meson=/path/to/meson"
  1030. fi
  1031. fi
  1032. else
  1033. # Meson uses its own Python interpreter to invoke other Python scripts,
  1034. # but the user wants to use the one they specified with --python.
  1035. #
  1036. # We do not want to override the distro Python interpreter (and sometimes
  1037. # cannot: for example in Homebrew /usr/bin/meson is a bash script), so
  1038. # just require --meson=git|internal together with --python.
  1039. if test "$explicit_python" = yes; then
  1040. case "$meson" in
  1041. git | internal) ;;
  1042. *) error_exit "--python requires using QEMU's embedded Meson distribution." ;;
  1043. esac
  1044. fi
  1045. fi
  1046. if test "$meson" = git; then
  1047. git_submodules="${git_submodules} meson"
  1048. fi
  1049. case "$meson" in
  1050. git | internal)
  1051. meson="$python ${source_path}/meson/meson.py"
  1052. ;;
  1053. *) meson=$(command -v "$meson") ;;
  1054. esac
  1055. # Probe for ninja
  1056. if test -z "$ninja"; then
  1057. for c in ninja ninja-build samu; do
  1058. if has $c; then
  1059. ninja=$(command -v "$c")
  1060. break
  1061. fi
  1062. done
  1063. if test -z "$ninja"; then
  1064. error_exit "Cannot find Ninja"
  1065. fi
  1066. fi
  1067. # Check that the C compiler works. Doing this here before testing
  1068. # the host CPU ensures that we had a valid CC to autodetect the
  1069. # $cpu var (and we should bail right here if that's not the case).
  1070. # It also allows the help message to be printed without a CC.
  1071. write_c_skeleton;
  1072. if compile_object ; then
  1073. : C compiler works ok
  1074. else
  1075. error_exit "\"$cc\" either does not exist or does not work"
  1076. fi
  1077. if ! compile_prog ; then
  1078. error_exit "\"$cc\" cannot build an executable (is your linker broken?)"
  1079. fi
  1080. # Consult white-list to determine whether to enable werror
  1081. # by default. Only enable by default for git builds
  1082. if test -z "$werror" ; then
  1083. if test "$git_submodules_action" != "ignore" && \
  1084. { test "$linux" = "yes" || test "$mingw32" = "yes"; }; then
  1085. werror="yes"
  1086. else
  1087. werror="no"
  1088. fi
  1089. fi
  1090. if test "$targetos" = "bogus"; then
  1091. # Now that we know that we're not printing the help and that
  1092. # the compiler works (so the results of the check_defines we used
  1093. # to identify the OS are reliable), if we didn't recognize the
  1094. # host OS we should stop now.
  1095. error_exit "Unrecognized host OS (uname -s reports '$(uname -s)')"
  1096. fi
  1097. # Check whether the compiler matches our minimum requirements:
  1098. cat > $TMPC << EOF
  1099. #if defined(__clang_major__) && defined(__clang_minor__)
  1100. # ifdef __apple_build_version__
  1101. # if __clang_major__ < 12 || (__clang_major__ == 12 && __clang_minor__ < 0)
  1102. # error You need at least XCode Clang v12.0 to compile QEMU
  1103. # endif
  1104. # else
  1105. # if __clang_major__ < 10 || (__clang_major__ == 10 && __clang_minor__ < 0)
  1106. # error You need at least Clang v10.0 to compile QEMU
  1107. # endif
  1108. # endif
  1109. #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
  1110. # if __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 4)
  1111. # error You need at least GCC v7.4.0 to compile QEMU
  1112. # endif
  1113. #else
  1114. # error You either need GCC or Clang to compiler QEMU
  1115. #endif
  1116. int main (void) { return 0; }
  1117. EOF
  1118. if ! compile_prog "" "" ; then
  1119. error_exit "You need at least GCC v7.4 or Clang v10.0 (or XCode Clang v12.0)"
  1120. fi
  1121. # Accumulate -Wfoo and -Wno-bar separately.
  1122. # We will list all of the enable flags first, and the disable flags second.
  1123. # Note that we do not add -Werror, because that would enable it for all
  1124. # configure tests. If a configure test failed due to -Werror this would
  1125. # just silently disable some features, so it's too error prone.
  1126. warn_flags=
  1127. add_to warn_flags -Wundef
  1128. add_to warn_flags -Wwrite-strings
  1129. add_to warn_flags -Wmissing-prototypes
  1130. add_to warn_flags -Wstrict-prototypes
  1131. add_to warn_flags -Wredundant-decls
  1132. add_to warn_flags -Wold-style-declaration
  1133. add_to warn_flags -Wold-style-definition
  1134. add_to warn_flags -Wtype-limits
  1135. add_to warn_flags -Wformat-security
  1136. add_to warn_flags -Wformat-y2k
  1137. add_to warn_flags -Winit-self
  1138. add_to warn_flags -Wignored-qualifiers
  1139. add_to warn_flags -Wempty-body
  1140. add_to warn_flags -Wnested-externs
  1141. add_to warn_flags -Wendif-labels
  1142. add_to warn_flags -Wexpansion-to-defined
  1143. add_to warn_flags -Wimplicit-fallthrough=2
  1144. add_to warn_flags -Wmissing-format-attribute
  1145. if test "$targetos" != "darwin"; then
  1146. add_to warn_flags -Wthread-safety
  1147. fi
  1148. nowarn_flags=
  1149. add_to nowarn_flags -Wno-initializer-overrides
  1150. add_to nowarn_flags -Wno-missing-include-dirs
  1151. add_to nowarn_flags -Wno-shift-negative-value
  1152. add_to nowarn_flags -Wno-string-plus-int
  1153. add_to nowarn_flags -Wno-typedef-redefinition
  1154. add_to nowarn_flags -Wno-tautological-type-limit-compare
  1155. add_to nowarn_flags -Wno-psabi
  1156. add_to nowarn_flags -Wno-gnu-variable-sized-type-not-at-end
  1157. gcc_flags="$warn_flags $nowarn_flags"
  1158. cc_has_warning_flag() {
  1159. write_c_skeleton;
  1160. # Use the positive sense of the flag when testing for -Wno-wombat
  1161. # support (gcc will happily accept the -Wno- form of unknown
  1162. # warning options).
  1163. optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
  1164. compile_prog "-Werror $optflag" ""
  1165. }
  1166. objcc_has_warning_flag() {
  1167. cat > $TMPM <<EOF
  1168. int main(void) { return 0; }
  1169. EOF
  1170. # Use the positive sense of the flag when testing for -Wno-wombat
  1171. # support (gcc will happily accept the -Wno- form of unknown
  1172. # warning options).
  1173. optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
  1174. do_objc -Werror $optflag \
  1175. $OBJCFLAGS $EXTRA_OBJCFLAGS $CONFIGURE_OBJCFLAGS $QEMU_OBJCFLAGS \
  1176. -o $TMPE $TMPM $QEMU_LDFLAGS
  1177. }
  1178. for flag in $gcc_flags; do
  1179. if cc_has_warning_flag $flag ; then
  1180. QEMU_CFLAGS="$QEMU_CFLAGS $flag"
  1181. fi
  1182. if objcc_has_warning_flag $flag ; then
  1183. QEMU_OBJCFLAGS="$QEMU_OBJCFLAGS $flag"
  1184. fi
  1185. done
  1186. if test "$stack_protector" != "no"; then
  1187. cat > $TMPC << EOF
  1188. int main(int argc, char *argv[])
  1189. {
  1190. char arr[64], *p = arr, *c = argv[argc - 1];
  1191. while (*c) {
  1192. *p++ = *c++;
  1193. }
  1194. return 0;
  1195. }
  1196. EOF
  1197. gcc_flags="-fstack-protector-strong -fstack-protector-all"
  1198. sp_on=0
  1199. for flag in $gcc_flags; do
  1200. # We need to check both a compile and a link, since some compiler
  1201. # setups fail only on a .c->.o compile and some only at link time
  1202. if compile_object "-Werror $flag" &&
  1203. compile_prog "-Werror $flag" ""; then
  1204. QEMU_CFLAGS="$QEMU_CFLAGS $flag"
  1205. QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
  1206. sp_on=1
  1207. break
  1208. fi
  1209. done
  1210. if test "$stack_protector" = yes; then
  1211. if test $sp_on = 0; then
  1212. error_exit "Stack protector not supported"
  1213. fi
  1214. fi
  1215. fi
  1216. # Our module code doesn't support Windows
  1217. if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
  1218. error_exit "Modules are not available for Windows"
  1219. fi
  1220. # Static linking is not possible with plugins, modules or PIE
  1221. if test "$static" = "yes" ; then
  1222. if test "$modules" = "yes" ; then
  1223. error_exit "static and modules are mutually incompatible"
  1224. fi
  1225. if test "$plugins" = "yes"; then
  1226. error_exit "static and plugins are mutually incompatible"
  1227. else
  1228. plugins="no"
  1229. fi
  1230. fi
  1231. test "$plugins" = "" && plugins=yes
  1232. cat > $TMPC << EOF
  1233. #ifdef __linux__
  1234. # define THREAD __thread
  1235. #else
  1236. # define THREAD
  1237. #endif
  1238. static THREAD int tls_var;
  1239. int main(void) { return tls_var; }
  1240. EOF
  1241. # Meson currently only handles pie as a boolean for now so if we have
  1242. # explicitly disabled PIE we need to extend our cflags because it wont.
  1243. if test "$static" = "yes"; then
  1244. if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then
  1245. CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
  1246. pie="yes"
  1247. elif test "$pie" = "yes"; then
  1248. error_exit "-static-pie not available due to missing toolchain support"
  1249. else
  1250. pie="no"
  1251. QEMU_CFLAGS="-fno-pie $QEMU_CFLAGS"
  1252. fi
  1253. elif test "$pie" = "no"; then
  1254. if compile_prog "-Werror -fno-pie" "-no-pie"; then
  1255. CONFIGURE_CFLAGS="-fno-pie $CONFIGURE_CFLAGS"
  1256. CONFIGURE_LDFLAGS="-no-pie $CONFIGURE_LDFLAGS"
  1257. QEMU_CFLAGS="-fno-pie -no-pie $QEMU_CFLAGS"
  1258. fi
  1259. elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then
  1260. CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS"
  1261. CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS"
  1262. pie="yes"
  1263. elif test "$pie" = "yes"; then
  1264. error_exit "PIE not available due to missing toolchain support"
  1265. else
  1266. echo "Disabling PIE due to missing toolchain support"
  1267. pie="no"
  1268. fi
  1269. ##########################################
  1270. # __sync_fetch_and_and requires at least -march=i486. Many toolchains
  1271. # use i686 as default anyway, but for those that don't, an explicit
  1272. # specification is necessary
  1273. if test "$cpu" = "i386"; then
  1274. cat > $TMPC << EOF
  1275. static int sfaa(int *ptr)
  1276. {
  1277. return __sync_fetch_and_and(ptr, 0);
  1278. }
  1279. int main(void)
  1280. {
  1281. int val = 42;
  1282. val = __sync_val_compare_and_swap(&val, 0, 1);
  1283. sfaa(&val);
  1284. return val;
  1285. }
  1286. EOF
  1287. if ! compile_prog "" "" ; then
  1288. QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS"
  1289. fi
  1290. fi
  1291. if test -z "${target_list+xxx}" ; then
  1292. default_targets=yes
  1293. for target in $default_target_list; do
  1294. target_list="$target_list $target"
  1295. done
  1296. target_list="${target_list# }"
  1297. else
  1298. default_targets=no
  1299. target_list=$(echo "$target_list" | sed -e 's/,/ /g')
  1300. for target in $target_list; do
  1301. # Check that we recognised the target name; this allows a more
  1302. # friendly error message than if we let it fall through.
  1303. case " $default_target_list " in
  1304. *" $target "*)
  1305. ;;
  1306. *)
  1307. error_exit "Unknown target name '$target'"
  1308. ;;
  1309. esac
  1310. done
  1311. fi
  1312. # see if system emulation was really requested
  1313. case " $target_list " in
  1314. *"-softmmu "*) softmmu=yes
  1315. ;;
  1316. *) softmmu=no
  1317. ;;
  1318. esac
  1319. if test "$tcg" = "auto"; then
  1320. if test -z "$target_list"; then
  1321. tcg="disabled"
  1322. else
  1323. tcg="enabled"
  1324. fi
  1325. fi
  1326. if test "$tcg" = "enabled"; then
  1327. git_submodules="$git_submodules tests/fp/berkeley-testfloat-3"
  1328. git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
  1329. fi
  1330. ##########################################
  1331. # big/little endian test
  1332. cat > $TMPC << EOF
  1333. #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  1334. # error LITTLE
  1335. #endif
  1336. int main(void) { return 0; }
  1337. EOF
  1338. if ! compile_prog ; then
  1339. bigendian="no"
  1340. else
  1341. cat > $TMPC << EOF
  1342. #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  1343. # error BIG
  1344. #endif
  1345. int main(void) { return 0; }
  1346. EOF
  1347. if ! compile_prog ; then
  1348. bigendian="yes"
  1349. else
  1350. echo big/little test failed
  1351. exit 1
  1352. fi
  1353. fi
  1354. ##########################################
  1355. # pkg-config probe
  1356. if ! has "$pkg_config_exe"; then
  1357. error_exit "pkg-config binary '$pkg_config_exe' not found"
  1358. fi
  1359. ##########################################
  1360. # glib support probe
  1361. # When bumping glib_req_ver, please check also whether we should increase
  1362. # the _WIN32_WINNT setting in osdep.h according to the value from glib
  1363. glib_req_ver=2.56
  1364. glib_modules=gthread-2.0
  1365. if test "$modules" = yes; then
  1366. glib_modules="$glib_modules gmodule-export-2.0"
  1367. elif test "$plugins" = "yes"; then
  1368. glib_modules="$glib_modules gmodule-no-export-2.0"
  1369. fi
  1370. for i in $glib_modules; do
  1371. if $pkg_config --atleast-version=$glib_req_ver $i; then
  1372. glib_cflags=$($pkg_config --cflags $i)
  1373. glib_libs=$($pkg_config --libs $i)
  1374. else
  1375. error_exit "glib-$glib_req_ver $i is required to compile QEMU"
  1376. fi
  1377. done
  1378. # Check whether glib has gslice, which we have to avoid for correctness.
  1379. # TODO: remove this check and the corresponding workaround (qtree) when
  1380. # the minimum supported glib is >= $glib_dropped_gslice_version.
  1381. glib_dropped_gslice_version=2.75.3
  1382. for i in $glib_modules; do
  1383. if ! $pkg_config --atleast-version=$glib_dropped_gslice_version $i; then
  1384. glib_has_gslice="yes"
  1385. break
  1386. fi
  1387. done
  1388. glib_bindir="$($pkg_config --variable=bindir glib-2.0)"
  1389. if test -z "$glib_bindir" ; then
  1390. glib_bindir="$($pkg_config --variable=prefix glib-2.0)"/bin
  1391. fi
  1392. # This workaround is required due to a bug in pkg-config file for glib as it
  1393. # doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
  1394. if test "$static" = yes && test "$mingw32" = yes; then
  1395. glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
  1396. fi
  1397. # Sanity check that the current size_t matches the
  1398. # size that glib thinks it should be. This catches
  1399. # problems on multi-arch where people try to build
  1400. # 32-bit QEMU while pointing at 64-bit glib headers
  1401. cat > $TMPC <<EOF
  1402. #include <glib.h>
  1403. #include <unistd.h>
  1404. #define QEMU_BUILD_BUG_ON(x) \
  1405. typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
  1406. int main(void) {
  1407. QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
  1408. return 0;
  1409. }
  1410. EOF
  1411. if ! compile_prog "$glib_cflags" "$glib_libs" ; then
  1412. error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
  1413. "You probably need to set PKG_CONFIG_LIBDIR"\
  1414. "to point to the right pkg-config files for your"\
  1415. "build target"
  1416. fi
  1417. # Silence clang warnings triggered by glib < 2.57.2
  1418. cat > $TMPC << EOF
  1419. #include <glib.h>
  1420. typedef struct Foo {
  1421. int i;
  1422. } Foo;
  1423. static void foo_free(Foo *f)
  1424. {
  1425. g_free(f);
  1426. }
  1427. G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
  1428. int main(void) { return 0; }
  1429. EOF
  1430. if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
  1431. if cc_has_warning_flag "-Wno-unused-function"; then
  1432. glib_cflags="$glib_cflags -Wno-unused-function"
  1433. CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
  1434. fi
  1435. fi
  1436. ##########################################
  1437. # fdt probe
  1438. case "$fdt" in
  1439. auto | enabled | internal)
  1440. # Simpler to always update submodule, even if not needed.
  1441. git_submodules="${git_submodules} dtc"
  1442. ;;
  1443. esac
  1444. ##########################################
  1445. # check and set a backend for coroutine
  1446. # We prefer ucontext, but it's not always possible. The fallback
  1447. # is sigcontext. On Windows the only valid backend is the Windows
  1448. # specific one.
  1449. ucontext_works=no
  1450. if test "$darwin" != "yes"; then
  1451. cat > $TMPC << EOF
  1452. #include <ucontext.h>
  1453. #ifdef __stub_makecontext
  1454. #error Ignoring glibc stub makecontext which will always fail
  1455. #endif
  1456. int main(void) { makecontext(0, 0, 0); return 0; }
  1457. EOF
  1458. if compile_prog "" "" ; then
  1459. ucontext_works=yes
  1460. fi
  1461. fi
  1462. if test "$coroutine" = ""; then
  1463. if test "$mingw32" = "yes"; then
  1464. coroutine=win32
  1465. elif test "$ucontext_works" = "yes"; then
  1466. coroutine=ucontext
  1467. else
  1468. coroutine=sigaltstack
  1469. fi
  1470. else
  1471. case $coroutine in
  1472. windows)
  1473. if test "$mingw32" != "yes"; then
  1474. error_exit "'windows' coroutine backend only valid for Windows"
  1475. fi
  1476. # Unfortunately the user visible backend name doesn't match the
  1477. # coroutine-*.c filename for this case, so we have to adjust it here.
  1478. coroutine=win32
  1479. ;;
  1480. ucontext)
  1481. if test "$ucontext_works" != "yes"; then
  1482. error_exit "'ucontext' backend requested but makecontext not available"
  1483. fi
  1484. ;;
  1485. sigaltstack)
  1486. if test "$mingw32" = "yes"; then
  1487. error_exit "only the 'windows' coroutine backend is valid for Windows"
  1488. fi
  1489. ;;
  1490. libucontext)
  1491. ;;
  1492. *)
  1493. error_exit "unknown coroutine backend $coroutine"
  1494. ;;
  1495. esac
  1496. fi
  1497. case $coroutine in
  1498. libucontext)
  1499. git_submodules="${git_submodules} subprojects/libucontext"
  1500. coroutine_impl=ucontext
  1501. libucontext="enabled"
  1502. ;;
  1503. *)
  1504. coroutine_impl=$coroutine
  1505. libucontext="disabled"
  1506. ;;
  1507. esac
  1508. ##################################################
  1509. # SafeStack
  1510. if test "$safe_stack" = "yes"; then
  1511. cat > $TMPC << EOF
  1512. int main(void)
  1513. {
  1514. #if ! __has_feature(safe_stack)
  1515. #error SafeStack Disabled
  1516. #endif
  1517. return 0;
  1518. }
  1519. EOF
  1520. flag="-fsanitize=safe-stack"
  1521. # Check that safe-stack is supported and enabled.
  1522. if compile_prog "-Werror $flag" "$flag"; then
  1523. # Flag needed both at compilation and at linking
  1524. QEMU_CFLAGS="$QEMU_CFLAGS $flag"
  1525. QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
  1526. else
  1527. error_exit "SafeStack not supported by your compiler"
  1528. fi
  1529. if test "$coroutine" != "ucontext"; then
  1530. error_exit "SafeStack is only supported by the coroutine backend ucontext"
  1531. fi
  1532. else
  1533. cat > $TMPC << EOF
  1534. int main(void)
  1535. {
  1536. #if defined(__has_feature)
  1537. #if __has_feature(safe_stack)
  1538. #error SafeStack Enabled
  1539. #endif
  1540. #endif
  1541. return 0;
  1542. }
  1543. EOF
  1544. if test "$safe_stack" = "no"; then
  1545. # Make sure that safe-stack is disabled
  1546. if ! compile_prog "-Werror" ""; then
  1547. # SafeStack was already enabled, try to explicitly remove the feature
  1548. flag="-fno-sanitize=safe-stack"
  1549. if ! compile_prog "-Werror $flag" "$flag"; then
  1550. error_exit "Configure cannot disable SafeStack"
  1551. fi
  1552. QEMU_CFLAGS="$QEMU_CFLAGS $flag"
  1553. QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
  1554. fi
  1555. else # "$safe_stack" = ""
  1556. # Set safe_stack to yes or no based on pre-existing flags
  1557. if compile_prog "-Werror" ""; then
  1558. safe_stack="no"
  1559. else
  1560. safe_stack="yes"
  1561. if test "$coroutine" != "ucontext"; then
  1562. error_exit "SafeStack is only supported by the coroutine backend ucontext"
  1563. fi
  1564. fi
  1565. fi
  1566. fi
  1567. ########################################
  1568. # check if ccache is interfering with
  1569. # semantic analysis of macros
  1570. unset CCACHE_CPP2
  1571. ccache_cpp2=no
  1572. cat > $TMPC << EOF
  1573. static const int Z = 1;
  1574. #define fn() ({ Z; })
  1575. #define TAUT(X) ((X) == Z)
  1576. #define PAREN(X, Y) (X == Y)
  1577. #define ID(X) (X)
  1578. int main(void)
  1579. {
  1580. int x = 0, y = 0;
  1581. x = ID(x);
  1582. x = fn();
  1583. fn();
  1584. if (PAREN(x, y)) return 0;
  1585. if (TAUT(Z)) return 0;
  1586. return 0;
  1587. }
  1588. EOF
  1589. if ! compile_object "-Werror"; then
  1590. ccache_cpp2=yes
  1591. fi
  1592. #################################################
  1593. # clang does not support glibc + FORTIFY_SOURCE.
  1594. if test "$fortify_source" != "no"; then
  1595. if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
  1596. fortify_source="no";
  1597. elif test -n "$cxx" && has $cxx &&
  1598. echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
  1599. fortify_source="no";
  1600. else
  1601. fortify_source="yes"
  1602. fi
  1603. fi
  1604. ##########################################
  1605. # checks for sanitizers
  1606. have_asan=no
  1607. have_ubsan=no
  1608. have_asan_iface_h=no
  1609. have_asan_iface_fiber=no
  1610. if test "$sanitizers" = "yes" ; then
  1611. write_c_skeleton
  1612. if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
  1613. have_asan=yes
  1614. fi
  1615. # we could use a simple skeleton for flags checks, but this also
  1616. # detect the static linking issue of ubsan, see also:
  1617. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
  1618. cat > $TMPC << EOF
  1619. #include <stdlib.h>
  1620. int main(void) {
  1621. void *tmp = malloc(10);
  1622. if (tmp != NULL) {
  1623. return *(int *)(tmp + 2);
  1624. }
  1625. return 1;
  1626. }
  1627. EOF
  1628. if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
  1629. have_ubsan=yes
  1630. fi
  1631. if check_include "sanitizer/asan_interface.h" ; then
  1632. have_asan_iface_h=yes
  1633. fi
  1634. cat > $TMPC << EOF
  1635. #include <sanitizer/asan_interface.h>
  1636. int main(void) {
  1637. __sanitizer_start_switch_fiber(0, 0, 0);
  1638. return 0;
  1639. }
  1640. EOF
  1641. if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
  1642. have_asan_iface_fiber=yes
  1643. fi
  1644. fi
  1645. # Thread sanitizer is, for now, much noisier than the other sanitizers;
  1646. # keep it separate until that is not the case.
  1647. if test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
  1648. error_exit "TSAN is not supported with other sanitiziers."
  1649. fi
  1650. have_tsan=no
  1651. have_tsan_iface_fiber=no
  1652. if test "$tsan" = "yes" ; then
  1653. write_c_skeleton
  1654. if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
  1655. have_tsan=yes
  1656. fi
  1657. cat > $TMPC << EOF
  1658. #include <sanitizer/tsan_interface.h>
  1659. int main(void) {
  1660. __tsan_create_fiber(0);
  1661. return 0;
  1662. }
  1663. EOF
  1664. if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
  1665. have_tsan_iface_fiber=yes
  1666. fi
  1667. fi
  1668. ##########################################
  1669. # functions to probe cross compilers
  1670. container="no"
  1671. runc=""
  1672. if test $use_containers = "yes" && (has "docker" || has "podman"); then
  1673. case $($python "$source_path"/tests/docker/docker.py probe) in
  1674. *docker) container=docker ;;
  1675. podman) container=podman ;;
  1676. no) container=no ;;
  1677. esac
  1678. if test "$container" != "no"; then
  1679. docker_py="$python $source_path/tests/docker/docker.py --engine $container"
  1680. runc=$($python "$source_path"/tests/docker/docker.py probe)
  1681. fi
  1682. fi
  1683. # cross compilers defaults, can be overridden with --cross-cc-ARCH
  1684. : ${cross_prefix_aarch64="aarch64-linux-gnu-"}
  1685. : ${cross_prefix_aarch64_be="$cross_prefix_aarch64"}
  1686. : ${cross_prefix_alpha="alpha-linux-gnu-"}
  1687. : ${cross_prefix_arm="arm-linux-gnueabihf-"}
  1688. : ${cross_prefix_armeb="$cross_prefix_arm"}
  1689. : ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
  1690. : ${cross_prefix_loongarch64="loongarch64-unknown-linux-gnu-"}
  1691. : ${cross_prefix_hppa="hppa-linux-gnu-"}
  1692. : ${cross_prefix_i386="i686-linux-gnu-"}
  1693. : ${cross_prefix_m68k="m68k-linux-gnu-"}
  1694. : ${cross_prefix_microblaze="microblaze-linux-musl-"}
  1695. : ${cross_prefix_mips64el="mips64el-linux-gnuabi64-"}
  1696. : ${cross_prefix_mips64="mips64-linux-gnuabi64-"}
  1697. : ${cross_prefix_mipsel="mipsel-linux-gnu-"}
  1698. : ${cross_prefix_mips="mips-linux-gnu-"}
  1699. : ${cross_prefix_nios2="nios2-linux-gnu-"}
  1700. : ${cross_prefix_ppc="powerpc-linux-gnu-"}
  1701. : ${cross_prefix_ppc64="powerpc64-linux-gnu-"}
  1702. : ${cross_prefix_ppc64le="$cross_prefix_ppc64"}
  1703. : ${cross_prefix_riscv64="riscv64-linux-gnu-"}
  1704. : ${cross_prefix_s390x="s390x-linux-gnu-"}
  1705. : ${cross_prefix_sh4="sh4-linux-gnu-"}
  1706. : ${cross_prefix_sparc64="sparc64-linux-gnu-"}
  1707. : ${cross_prefix_sparc="$cross_prefix_sparc64"}
  1708. : ${cross_prefix_x86_64="x86_64-linux-gnu-"}
  1709. : ${cross_cc_aarch64_be="$cross_cc_aarch64"}
  1710. : ${cross_cc_cflags_aarch64_be="-mbig-endian"}
  1711. : ${cross_cc_armeb="$cross_cc_arm"}
  1712. : ${cross_cc_cflags_armeb="-mbig-endian"}
  1713. : ${cross_cc_hexagon="hexagon-unknown-linux-musl-clang"}
  1714. : ${cross_cc_cflags_hexagon="-mv67 -O2 -static"}
  1715. : ${cross_cc_cflags_i386="-m32"}
  1716. : ${cross_cc_cflags_ppc="-m32 -mbig-endian"}
  1717. : ${cross_cc_cflags_ppc64="-m64 -mbig-endian"}
  1718. : ${cross_cc_ppc64le="$cross_cc_ppc64"}
  1719. : ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"}
  1720. : ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"}
  1721. : ${cross_cc_sparc="$cross_cc_sparc64"}
  1722. : ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
  1723. : ${cross_cc_cflags_x86_64="-m64"}
  1724. compute_target_variable() {
  1725. eval "$2="
  1726. if eval test -n "\"\${cross_prefix_$1}\""; then
  1727. if eval has "\"\${cross_prefix_$1}\$3\""; then
  1728. eval "$2=\"\${cross_prefix_$1}\$3\""
  1729. fi
  1730. fi
  1731. }
  1732. have_target() {
  1733. for i; do
  1734. case " $target_list " in
  1735. *" $i "*) return 0;;
  1736. *) ;;
  1737. esac
  1738. done
  1739. return 1
  1740. }
  1741. # probe_target_compiler TARGET
  1742. #
  1743. # Look for a compiler for the given target, either native or cross.
  1744. # Set variables target_* if a compiler is found, and container_cross_*
  1745. # if a Docker-based cross-compiler image is known for the target.
  1746. # Set got_cross_cc to yes/no depending on whether a non-container-based
  1747. # compiler was found.
  1748. #
  1749. # If TARGET is a user-mode emulation target, also set build_static to
  1750. # "y" if static linking is possible.
  1751. #
  1752. probe_target_compiler() {
  1753. # reset all output variables
  1754. got_cross_cc=no
  1755. container_image=
  1756. container_hosts=
  1757. container_cross_cc=
  1758. container_cross_ar=
  1759. container_cross_as=
  1760. container_cross_ld=
  1761. container_cross_nm=
  1762. container_cross_objcopy=
  1763. container_cross_ranlib=
  1764. container_cross_strip=
  1765. # We shall skip configuring the target compiler if the user didn't
  1766. # bother enabling an appropriate guest. This avoids building
  1767. # extraneous firmware images and tests.
  1768. if test "${target_list#*$1}" = "$1"; then
  1769. return 1
  1770. fi
  1771. target_arch=${1%%-*}
  1772. case $target_arch in
  1773. aarch64) container_hosts="x86_64 aarch64" ;;
  1774. alpha) container_hosts=x86_64 ;;
  1775. arm) container_hosts="x86_64 aarch64" ;;
  1776. cris) container_hosts=x86_64 ;;
  1777. hexagon) container_hosts=x86_64 ;;
  1778. hppa) container_hosts=x86_64 ;;
  1779. i386) container_hosts=x86_64 ;;
  1780. loongarch64) container_hosts=x86_64 ;;
  1781. m68k) container_hosts=x86_64 ;;
  1782. microblaze) container_hosts=x86_64 ;;
  1783. mips64el) container_hosts=x86_64 ;;
  1784. mips64) container_hosts=x86_64 ;;
  1785. mipsel) container_hosts=x86_64 ;;
  1786. mips) container_hosts=x86_64 ;;
  1787. nios2) container_hosts=x86_64 ;;
  1788. ppc) container_hosts=x86_64 ;;
  1789. ppc64|ppc64le) container_hosts=x86_64 ;;
  1790. riscv64) container_hosts=x86_64 ;;
  1791. s390x) container_hosts=x86_64 ;;
  1792. sh4) container_hosts=x86_64 ;;
  1793. sparc64) container_hosts=x86_64 ;;
  1794. tricore) container_hosts=x86_64 ;;
  1795. x86_64) container_hosts="aarch64 ppc64el x86_64" ;;
  1796. xtensa*) container_hosts=x86_64 ;;
  1797. esac
  1798. for host in $container_hosts; do
  1799. test "$container" != no || continue
  1800. test "$host" = "$cpu" || continue
  1801. case $target_arch in
  1802. aarch64)
  1803. # We don't have any bigendian build tools so we only use this for AArch64
  1804. container_image=debian-arm64-cross
  1805. container_cross_prefix=aarch64-linux-gnu-
  1806. container_cross_cc=${container_cross_prefix}gcc-10
  1807. ;;
  1808. alpha)
  1809. container_image=debian-alpha-cross
  1810. container_cross_prefix=alpha-linux-gnu-
  1811. ;;
  1812. arm)
  1813. # We don't have any bigendian build tools so we only use this for ARM
  1814. container_image=debian-armhf-cross
  1815. container_cross_prefix=arm-linux-gnueabihf-
  1816. ;;
  1817. cris)
  1818. container_image=fedora-cris-cross
  1819. container_cross_prefix=cris-linux-gnu-
  1820. ;;
  1821. hexagon)
  1822. container_image=debian-hexagon-cross
  1823. container_cross_prefix=hexagon-unknown-linux-musl-
  1824. container_cross_cc=${container_cross_prefix}clang
  1825. ;;
  1826. hppa)
  1827. container_image=debian-hppa-cross
  1828. container_cross_prefix=hppa-linux-gnu-
  1829. ;;
  1830. i386)
  1831. container_image=fedora-i386-cross
  1832. container_cross_prefix=
  1833. ;;
  1834. loongarch64)
  1835. container_image=debian-loongarch-cross
  1836. container_cross_prefix=loongarch64-unknown-linux-gnu-
  1837. ;;
  1838. m68k)
  1839. container_image=debian-m68k-cross
  1840. container_cross_prefix=m68k-linux-gnu-
  1841. ;;
  1842. microblaze)
  1843. container_image=debian-microblaze-cross
  1844. container_cross_prefix=microblaze-linux-musl-
  1845. ;;
  1846. mips64el)
  1847. container_image=debian-mips64el-cross
  1848. container_cross_prefix=mips64el-linux-gnuabi64-
  1849. ;;
  1850. mips64)
  1851. container_image=debian-mips64-cross
  1852. container_cross_prefix=mips64-linux-gnuabi64-
  1853. ;;
  1854. mipsel)
  1855. container_image=debian-mipsel-cross
  1856. container_cross_prefix=mipsel-linux-gnu-
  1857. ;;
  1858. mips)
  1859. container_image=debian-mips-cross
  1860. container_cross_prefix=mips-linux-gnu-
  1861. ;;
  1862. nios2)
  1863. container_image=debian-nios2-cross
  1864. container_cross_prefix=nios2-linux-gnu-
  1865. ;;
  1866. ppc)
  1867. container_image=debian-powerpc-test-cross
  1868. container_cross_prefix=powerpc-linux-gnu-
  1869. container_cross_cc=${container_cross_prefix}gcc-10
  1870. ;;
  1871. ppc64|ppc64le)
  1872. container_image=debian-powerpc-test-cross
  1873. container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu-
  1874. container_cross_cc=${container_cross_prefix}gcc-10
  1875. ;;
  1876. riscv64)
  1877. container_image=debian-riscv64-test-cross
  1878. container_cross_prefix=riscv64-linux-gnu-
  1879. ;;
  1880. s390x)
  1881. container_image=debian-s390x-cross
  1882. container_cross_prefix=s390x-linux-gnu-
  1883. ;;
  1884. sh4)
  1885. container_image=debian-sh4-cross
  1886. container_cross_prefix=sh4-linux-gnu-
  1887. ;;
  1888. sparc64)
  1889. container_image=debian-sparc64-cross
  1890. container_cross_prefix=sparc64-linux-gnu-
  1891. ;;
  1892. tricore)
  1893. container_image=debian-tricore-cross
  1894. container_cross_prefix=tricore-
  1895. container_cross_as=tricore-as
  1896. container_cross_ld=tricore-ld
  1897. break
  1898. ;;
  1899. x86_64)
  1900. container_image=debian-amd64-cross
  1901. container_cross_prefix=x86_64-linux-gnu-
  1902. ;;
  1903. xtensa*)
  1904. container_hosts=x86_64
  1905. container_image=debian-xtensa-cross
  1906. # default to the dc232b cpu
  1907. container_cross_prefix=/opt/2020.07/xtensa-dc232b-elf/bin/xtensa-dc232b-elf-
  1908. ;;
  1909. esac
  1910. : ${container_cross_cc:=${container_cross_prefix}gcc}
  1911. : ${container_cross_ar:=${container_cross_prefix}ar}
  1912. : ${container_cross_as:=${container_cross_prefix}as}
  1913. : ${container_cross_ld:=${container_cross_prefix}ld}
  1914. : ${container_cross_nm:=${container_cross_prefix}nm}
  1915. : ${container_cross_objcopy:=${container_cross_prefix}objcopy}
  1916. : ${container_cross_ranlib:=${container_cross_prefix}ranlib}
  1917. : ${container_cross_strip:=${container_cross_prefix}strip}
  1918. done
  1919. try=cross
  1920. case "$target_arch:$cpu" in
  1921. aarch64_be:aarch64 | \
  1922. armeb:arm | \
  1923. i386:x86_64 | \
  1924. mips*:mips64 | \
  1925. ppc*:ppc64 | \
  1926. sparc:sparc64 | \
  1927. "$cpu:$cpu")
  1928. try='native cross' ;;
  1929. esac
  1930. eval "target_cflags=\${cross_cc_cflags_$target_arch}"
  1931. for thistry in $try; do
  1932. case $thistry in
  1933. native)
  1934. target_cc=$cc
  1935. target_ccas=$ccas
  1936. target_ar=$ar
  1937. target_as=$as
  1938. target_ld=$ld
  1939. target_nm=$nm
  1940. target_objcopy=$objcopy
  1941. target_ranlib=$ranlib
  1942. target_strip=$strip
  1943. ;;
  1944. cross)
  1945. target_cc=
  1946. if eval test -n "\"\${cross_cc_$target_arch}\""; then
  1947. if eval has "\"\${cross_cc_$target_arch}\""; then
  1948. eval "target_cc=\"\${cross_cc_$target_arch}\""
  1949. fi
  1950. else
  1951. compute_target_variable $target_arch target_cc gcc
  1952. fi
  1953. target_ccas=$target_cc
  1954. compute_target_variable $target_arch target_ar ar
  1955. compute_target_variable $target_arch target_as as
  1956. compute_target_variable $target_arch target_ld ld
  1957. compute_target_variable $target_arch target_nm nm
  1958. compute_target_variable $target_arch target_objcopy objcopy
  1959. compute_target_variable $target_arch target_ranlib ranlib
  1960. compute_target_variable $target_arch target_strip strip
  1961. ;;
  1962. esac
  1963. if test -n "$target_cc"; then
  1964. case $target_arch in
  1965. i386|x86_64)
  1966. if $target_cc --version | grep -qi "clang"; then
  1967. continue
  1968. fi
  1969. ;;
  1970. esac
  1971. elif test -n "$target_as" && test -n "$target_ld"; then
  1972. # Special handling for assembler only targets
  1973. case $target in
  1974. tricore-softmmu)
  1975. build_static=
  1976. got_cross_cc=yes
  1977. break
  1978. ;;
  1979. *)
  1980. continue
  1981. ;;
  1982. esac
  1983. else
  1984. continue
  1985. fi
  1986. write_c_skeleton
  1987. case $1 in
  1988. *-softmmu)
  1989. if do_compiler "$target_cc" $target_cflags -o $TMPO -c $TMPC &&
  1990. do_compiler "$target_cc" $target_cflags -r -nostdlib -o "${TMPDIR1}/${TMPB}2.o" "$TMPO" -lgcc; then
  1991. got_cross_cc=yes
  1992. break
  1993. fi
  1994. ;;
  1995. *)
  1996. if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC -static ; then
  1997. build_static=y
  1998. got_cross_cc=yes
  1999. break
  2000. fi
  2001. if do_compiler "$target_cc" $target_cflags -o $TMPE $TMPC ; then
  2002. build_static=
  2003. got_cross_cc=yes
  2004. break
  2005. fi
  2006. ;;
  2007. esac
  2008. done
  2009. if test $got_cross_cc != yes; then
  2010. build_static=
  2011. target_cc=
  2012. target_ccas=
  2013. target_ar=
  2014. target_as=
  2015. target_ld=
  2016. target_nm=
  2017. target_objcopy=
  2018. target_ranlib=
  2019. target_strip=
  2020. fi
  2021. test -n "$target_cc"
  2022. }
  2023. write_target_makefile() {
  2024. echo "EXTRA_CFLAGS=$target_cflags"
  2025. if test -z "$target_cc" && test -z "$target_as"; then
  2026. test -z "$container_image" && error_exit "Internal error: could not find cross compiler for $1?"
  2027. echo "$1: docker-image-$container_image" >> Makefile.prereqs
  2028. if test -n "$container_cross_cc"; then
  2029. echo "CC=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
  2030. echo "CCAS=$docker_py cc --cc $container_cross_cc -i qemu/$container_image -s $source_path --"
  2031. fi
  2032. echo "AR=$docker_py cc --cc $container_cross_ar -i qemu/$container_image -s $source_path --"
  2033. echo "AS=$docker_py cc --cc $container_cross_as -i qemu/$container_image -s $source_path --"
  2034. echo "LD=$docker_py cc --cc $container_cross_ld -i qemu/$container_image -s $source_path --"
  2035. echo "NM=$docker_py cc --cc $container_cross_nm -i qemu/$container_image -s $source_path --"
  2036. echo "OBJCOPY=$docker_py cc --cc $container_cross_objcopy -i qemu/$container_image -s $source_path --"
  2037. echo "RANLIB=$docker_py cc --cc $container_cross_ranlib -i qemu/$container_image -s $source_path --"
  2038. echo "STRIP=$docker_py cc --cc $container_cross_strip -i qemu/$container_image -s $source_path --"
  2039. else
  2040. if test -n "$target_cc"; then
  2041. echo "CC=$target_cc"
  2042. echo "CCAS=$target_ccas"
  2043. fi
  2044. if test -n "$target_ar"; then
  2045. echo "AR=$target_ar"
  2046. fi
  2047. if test -n "$target_as"; then
  2048. echo "AS=$target_as"
  2049. fi
  2050. if test -n "$target_ld"; then
  2051. echo "LD=$target_ld"
  2052. fi
  2053. if test -n "$target_nm"; then
  2054. echo "NM=$target_nm"
  2055. fi
  2056. if test -n "$target_objcopy"; then
  2057. echo "OBJCOPY=$target_objcopy"
  2058. fi
  2059. if test -n "$target_ranlib"; then
  2060. echo "RANLIB=$target_ranlib"
  2061. fi
  2062. if test -n "$target_strip"; then
  2063. echo "STRIP=$target_strip"
  2064. fi
  2065. fi
  2066. }
  2067. ##########################################
  2068. # check for vfio_user_server
  2069. case "$vfio_user_server" in
  2070. enabled )
  2071. if test "$git_submodules_action" != "ignore"; then
  2072. git_submodules="${git_submodules} subprojects/libvfio-user"
  2073. fi
  2074. ;;
  2075. esac
  2076. ##########################################
  2077. # End of CC checks
  2078. # After here, no more $cc or $ld runs
  2079. write_c_skeleton
  2080. if test "$fortify_source" = "yes" ; then
  2081. QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
  2082. fi
  2083. if test "$have_asan" = "yes"; then
  2084. QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
  2085. QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
  2086. if test "$have_asan_iface_h" = "no" ; then
  2087. echo "ASAN build enabled, but ASAN header missing." \
  2088. "Without code annotation, the report may be inferior."
  2089. elif test "$have_asan_iface_fiber" = "no" ; then
  2090. echo "ASAN build enabled, but ASAN header is too old." \
  2091. "Without code annotation, the report may be inferior."
  2092. fi
  2093. fi
  2094. if test "$have_tsan" = "yes" ; then
  2095. if test "$have_tsan_iface_fiber" = "yes" ; then
  2096. QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
  2097. QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
  2098. else
  2099. error_exit "Cannot enable TSAN due to missing fiber annotation interface."
  2100. fi
  2101. elif test "$tsan" = "yes" ; then
  2102. error_exit "Cannot enable TSAN due to missing sanitize thread interface."
  2103. fi
  2104. if test "$have_ubsan" = "yes"; then
  2105. QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
  2106. QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
  2107. fi
  2108. #######################################
  2109. # cross-compiled firmware targets
  2110. # Set up build tree symlinks that point back into the source tree
  2111. # (these can be both files and directories).
  2112. # Caution: avoid adding files or directories here using wildcards. This
  2113. # will result in problems later if a new file matching the wildcard is
  2114. # added to the source tree -- nothing will cause configure to be rerun
  2115. # so the build tree will be missing the link back to the new file, and
  2116. # tests might fail. Prefer to keep the relevant files in their own
  2117. # directory and symlink the directory instead.
  2118. LINKS="Makefile"
  2119. LINKS="$LINKS docs/config"
  2120. LINKS="$LINKS pc-bios/optionrom/Makefile"
  2121. LINKS="$LINKS pc-bios/s390-ccw/Makefile"
  2122. LINKS="$LINKS pc-bios/vof/Makefile"
  2123. LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
  2124. LINKS="$LINKS tests/avocado tests/data"
  2125. LINKS="$LINKS tests/qemu-iotests/check"
  2126. LINKS="$LINKS python"
  2127. LINKS="$LINKS contrib/plugins/Makefile "
  2128. for f in $LINKS ; do
  2129. if [ -e "$source_path/$f" ]; then
  2130. mkdir -p "$(dirname ./"$f")"
  2131. symlink "$source_path/$f" "$f"
  2132. fi
  2133. done
  2134. echo "# Automatically generated by configure - do not modify" > Makefile.prereqs
  2135. # Mac OS X ships with a broken assembler
  2136. roms=
  2137. if have_target i386-softmmu x86_64-softmmu && \
  2138. test "$targetos" != "darwin" && test "$targetos" != "sunos" && \
  2139. test "$targetos" != "haiku" && \
  2140. probe_target_compiler i386-softmmu; then
  2141. roms="pc-bios/optionrom"
  2142. config_mak=pc-bios/optionrom/config.mak
  2143. echo "# Automatically generated by configure - do not modify" > $config_mak
  2144. echo "TOPSRC_DIR=$source_path" >> $config_mak
  2145. write_target_makefile >> $config_mak
  2146. fi
  2147. if have_target ppc-softmmu ppc64-softmmu && \
  2148. probe_target_compiler ppc-softmmu; then
  2149. roms="$roms pc-bios/vof"
  2150. config_mak=pc-bios/vof/config.mak
  2151. echo "# Automatically generated by configure - do not modify" > $config_mak
  2152. echo "SRC_DIR=$source_path/pc-bios/vof" >> $config_mak
  2153. write_target_makefile >> $config_mak
  2154. fi
  2155. # Only build s390-ccw bios if the compiler has -march=z900 or -march=z10
  2156. # (which is the lowest architecture level that Clang supports)
  2157. if have_target s390x-softmmu && probe_target_compiler s390x-softmmu; then
  2158. write_c_skeleton
  2159. do_compiler "$target_cc" $target_cc_cflags -march=z900 -o $TMPO -c $TMPC
  2160. has_z900=$?
  2161. if [ $has_z900 = 0 ] || do_compiler "$target_cc" $target_cc_cflags -march=z10 -msoft-float -Werror -o $TMPO -c $TMPC; then
  2162. if [ $has_z900 != 0 ]; then
  2163. echo "WARNING: Your compiler does not support the z900!"
  2164. echo " The s390-ccw bios will only work with guest CPUs >= z10."
  2165. fi
  2166. roms="$roms pc-bios/s390-ccw"
  2167. config_mak=pc-bios/s390-ccw/config-host.mak
  2168. echo "# Automatically generated by configure - do not modify" > $config_mak
  2169. echo "SRC_PATH=$source_path/pc-bios/s390-ccw" >> $config_mak
  2170. write_target_makefile >> $config_mak
  2171. # SLOF is required for building the s390-ccw firmware on s390x,
  2172. # since it is using the libnet code from SLOF for network booting.
  2173. git_submodules="${git_submodules} roms/SLOF"
  2174. fi
  2175. fi
  2176. #######################################
  2177. # generate config-host.mak
  2178. if ! (GIT="$git" "$source_path/scripts/git-submodule.sh" "$git_submodules_action" "$git_submodules"); then
  2179. exit 1
  2180. fi
  2181. config_host_mak="config-host.mak"
  2182. echo "# Automatically generated by configure - do not modify" > $config_host_mak
  2183. echo >> $config_host_mak
  2184. echo all: >> $config_host_mak
  2185. echo "GIT=$git" >> $config_host_mak
  2186. echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak
  2187. echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak
  2188. if test "$debug_tcg" = "yes" ; then
  2189. echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
  2190. fi
  2191. if test "$mingw32" = "yes" ; then
  2192. echo "CONFIG_WIN32=y" >> $config_host_mak
  2193. echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER-QEMU}" >> $config_host_mak
  2194. echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO-Linux}" >> $config_host_mak
  2195. echo "QEMU_GA_VERSION=${QEMU_GA_VERSION-$(cat "$source_path"/VERSION)}" >> $config_host_mak
  2196. else
  2197. echo "CONFIG_POSIX=y" >> $config_host_mak
  2198. fi
  2199. if test "$linux" = "yes" ; then
  2200. echo "CONFIG_LINUX=y" >> $config_host_mak
  2201. fi
  2202. if test "$darwin" = "yes" ; then
  2203. echo "CONFIG_DARWIN=y" >> $config_host_mak
  2204. fi
  2205. if test "$solaris" = "yes" ; then
  2206. echo "CONFIG_SOLARIS=y" >> $config_host_mak
  2207. fi
  2208. if test "$static" = "yes" ; then
  2209. echo "CONFIG_STATIC=y" >> $config_host_mak
  2210. fi
  2211. echo "SRC_PATH=$source_path" >> $config_host_mak
  2212. echo "TARGET_DIRS=$target_list" >> $config_host_mak
  2213. if test "$modules" = "yes"; then
  2214. echo "CONFIG_MODULES=y" >> $config_host_mak
  2215. fi
  2216. # XXX: suppress that
  2217. if [ "$bsd" = "yes" ] ; then
  2218. echo "CONFIG_BSD=y" >> $config_host_mak
  2219. fi
  2220. echo "CONFIG_COROUTINE_BACKEND=$coroutine_impl" >> $config_host_mak
  2221. if test "$have_asan_iface_fiber" = "yes" ; then
  2222. echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
  2223. fi
  2224. if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
  2225. echo "CONFIG_TSAN=y" >> $config_host_mak
  2226. fi
  2227. if test "$plugins" = "yes" ; then
  2228. echo "CONFIG_PLUGIN=y" >> $config_host_mak
  2229. fi
  2230. if test "$shared_lib" = "yes" ; then
  2231. echo "CONFIG_SHARED_LIBRARY_BUILD=y" >> $config_host_mak
  2232. fi
  2233. if test -n "$gdb_bin"; then
  2234. gdb_version=$($gdb_bin --version | head -n 1)
  2235. if version_ge ${gdb_version##* } 9.1; then
  2236. echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
  2237. gdb_arches=$("$source_path/scripts/probe-gdb-support.py" $gdb_bin)
  2238. else
  2239. gdb_bin=""
  2240. fi
  2241. fi
  2242. if test "$container" != no; then
  2243. echo "ENGINE=$container" >> $config_host_mak
  2244. echo "RUNC=$runc" >> $config_host_mak
  2245. fi
  2246. echo "ROMS=$roms" >> $config_host_mak
  2247. echo "MAKE=$make" >> $config_host_mak
  2248. echo "PYTHON=$python" >> $config_host_mak
  2249. echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
  2250. echo "MESON=$meson" >> $config_host_mak
  2251. echo "NINJA=$ninja" >> $config_host_mak
  2252. echo "CC=$cc" >> $config_host_mak
  2253. echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
  2254. echo "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak
  2255. echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
  2256. echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
  2257. echo "GLIB_BINDIR=$glib_bindir" >> $config_host_mak
  2258. echo "GLIB_VERSION=$($pkg_config --modversion glib-2.0)" >> $config_host_mak
  2259. if test "$glib_has_gslice" = "yes" ; then
  2260. echo "HAVE_GLIB_WITH_SLICE_ALLOCATOR=y" >> $config_host_mak
  2261. fi
  2262. echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
  2263. echo "EXESUF=$EXESUF" >> $config_host_mak
  2264. # use included Linux headers
  2265. if test "$linux" = "yes" ; then
  2266. mkdir -p linux-headers
  2267. case "$cpu" in
  2268. i386|x86_64)
  2269. linux_arch=x86
  2270. ;;
  2271. ppc|ppc64)
  2272. linux_arch=powerpc
  2273. ;;
  2274. s390x)
  2275. linux_arch=s390
  2276. ;;
  2277. aarch64)
  2278. linux_arch=arm64
  2279. ;;
  2280. loongarch*)
  2281. linux_arch=loongarch
  2282. ;;
  2283. mips64)
  2284. linux_arch=mips
  2285. ;;
  2286. *)
  2287. # For most CPUs the kernel architecture name and QEMU CPU name match.
  2288. linux_arch="$cpu"
  2289. ;;
  2290. esac
  2291. # For non-KVM architectures we will not have asm headers
  2292. if [ -e "$source_path/linux-headers/asm-$linux_arch" ]; then
  2293. symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
  2294. fi
  2295. fi
  2296. for target in $target_list; do
  2297. target_dir="$target"
  2298. target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
  2299. mkdir -p "$target_dir"
  2300. case $target in
  2301. *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
  2302. *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
  2303. esac
  2304. done
  2305. if test "$default_targets" = "yes"; then
  2306. echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
  2307. fi
  2308. if test "$ccache_cpp2" = "yes"; then
  2309. echo "export CCACHE_CPP2=y" >> $config_host_mak
  2310. fi
  2311. if test "$safe_stack" = "yes"; then
  2312. echo "CONFIG_SAFESTACK=y" >> $config_host_mak
  2313. fi
  2314. # tests/tcg configuration
  2315. (config_host_mak=tests/tcg/config-host.mak
  2316. mkdir -p tests/tcg
  2317. echo "# Automatically generated by configure - do not modify" > $config_host_mak
  2318. echo "SRC_PATH=$source_path" >> $config_host_mak
  2319. echo "HOST_CC=$host_cc" >> $config_host_mak
  2320. # versioned checked in the main config_host.mak above
  2321. if test -n "$gdb_bin"; then
  2322. echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
  2323. fi
  2324. if test "$plugins" = "yes" ; then
  2325. echo "CONFIG_PLUGIN=y" >> $config_host_mak
  2326. fi
  2327. tcg_tests_targets=
  2328. for target in $target_list; do
  2329. arch=${target%%-*}
  2330. case $target in
  2331. xtensa*-linux-user)
  2332. # the toolchain is not complete with headers, only build softmmu tests
  2333. continue
  2334. ;;
  2335. *-softmmu)
  2336. test -f "$source_path/tests/tcg/$arch/Makefile.softmmu-target" || continue
  2337. qemu="qemu-system-$arch"
  2338. ;;
  2339. *-linux-user|*-bsd-user)
  2340. qemu="qemu-$arch"
  2341. ;;
  2342. esac
  2343. if probe_target_compiler $target || test -n "$container_image"; then
  2344. test -n "$container_image" && build_static=y
  2345. mkdir -p "tests/tcg/$target"
  2346. config_target_mak=tests/tcg/$target/config-target.mak
  2347. ln -sf "$source_path/tests/tcg/Makefile.target" "tests/tcg/$target/Makefile"
  2348. echo "# Automatically generated by configure - do not modify" > "$config_target_mak"
  2349. echo "TARGET_NAME=$arch" >> "$config_target_mak"
  2350. echo "TARGET=$target" >> "$config_target_mak"
  2351. write_target_makefile "build-tcg-tests-$target" >> "$config_target_mak"
  2352. echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
  2353. echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
  2354. # will GDB work with these binaries?
  2355. if test "${gdb_arches#*$arch}" != "$gdb_arches"; then
  2356. echo "HOST_GDB_SUPPORTS_ARCH=y" >> "$config_target_mak"
  2357. fi
  2358. echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs
  2359. tcg_tests_targets="$tcg_tests_targets $target"
  2360. fi
  2361. done
  2362. if test "$tcg" = "enabled"; then
  2363. echo "TCG_TESTS_TARGETS=$tcg_tests_targets" >> config-host.mak
  2364. fi
  2365. )
  2366. if test "$skip_meson" = no; then
  2367. cross="config-meson.cross.new"
  2368. meson_quote() {
  2369. test $# = 0 && return
  2370. echo "'$(echo $* | sed "s/ /','/g")'"
  2371. }
  2372. echo "# Automatically generated by configure - do not modify" > $cross
  2373. echo "[properties]" >> $cross
  2374. # unroll any custom device configs
  2375. for a in $device_archs; do
  2376. eval "c=\$devices_${a}"
  2377. echo "${a}-softmmu = '$c'" >> $cross
  2378. done
  2379. echo "[built-in options]" >> $cross
  2380. echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
  2381. echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
  2382. test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
  2383. echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
  2384. echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
  2385. echo "[binaries]" >> $cross
  2386. echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
  2387. test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
  2388. test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
  2389. echo "ar = [$(meson_quote $ar)]" >> $cross
  2390. echo "nm = [$(meson_quote $nm)]" >> $cross
  2391. echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross
  2392. echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
  2393. if has $sdl2_config; then
  2394. echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
  2395. fi
  2396. if test "$shared_lib" = "yes"; then
  2397. echo "strip = [$(meson_quote $strip), '-x']" >> $cross
  2398. else
  2399. echo "strip = [$(meson_quote $strip)]" >> $cross
  2400. fi
  2401. echo "widl = [$(meson_quote $widl)]" >> $cross
  2402. echo "windres = [$(meson_quote $windres)]" >> $cross
  2403. echo "windmc = [$(meson_quote $windmc)]" >> $cross
  2404. if test "$cross_compile" = "yes"; then
  2405. cross_arg="--cross-file config-meson.cross"
  2406. echo "[host_machine]" >> $cross
  2407. echo "system = '$targetos'" >> $cross
  2408. case "$cpu" in
  2409. i386)
  2410. echo "cpu_family = 'x86'" >> $cross
  2411. ;;
  2412. *)
  2413. echo "cpu_family = '$cpu'" >> $cross
  2414. ;;
  2415. esac
  2416. echo "cpu = '$cpu'" >> $cross
  2417. if test "$bigendian" = "yes" ; then
  2418. echo "endian = 'big'" >> $cross
  2419. else
  2420. echo "endian = 'little'" >> $cross
  2421. fi
  2422. else
  2423. cross_arg="--native-file config-meson.cross"
  2424. fi
  2425. mv $cross config-meson.cross
  2426. rm -rf meson-private meson-info meson-logs
  2427. # Built-in options
  2428. test "$bindir" != "bin" && meson_option_add "-Dbindir=$bindir"
  2429. test "$default_feature" = no && meson_option_add -Dauto_features=disabled
  2430. test "$pie" = no && meson_option_add -Db_pie=false
  2431. test "$werror" = yes && meson_option_add -Dwerror=true
  2432. # QEMU options
  2433. test "$cfi" != false && meson_option_add "-Dcfi=$cfi"
  2434. test "$fdt" != auto && meson_option_add "-Dfdt=$fdt"
  2435. test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
  2436. test "$qemu_suffix" != qemu && meson_option_add "-Dqemu_suffix=$qemu_suffix"
  2437. test "$smbd" != '' && meson_option_add "-Dsmbd=$smbd"
  2438. test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
  2439. test "$vfio_user_server" != auto && meson_option_add "-Dvfio_user_server=$vfio_user_server"
  2440. run_meson() {
  2441. NINJA=$ninja $meson setup --prefix "$prefix" "$@" $cross_arg "$PWD" "$source_path"
  2442. }
  2443. eval run_meson $meson_options
  2444. if test "$?" -ne 0 ; then
  2445. error_exit "meson setup failed"
  2446. fi
  2447. fi
  2448. # Save the configure command line for later reuse.
  2449. cat <<EOD >config.status
  2450. #!/bin/sh
  2451. # Generated by configure.
  2452. # Run this file to recreate the current configuration.
  2453. # Compiler output produced by configure, useful for debugging
  2454. # configure, is in config.log if it exists.
  2455. EOD
  2456. preserve_env() {
  2457. envname=$1
  2458. eval envval=\$$envname
  2459. if test -n "$envval"
  2460. then
  2461. echo "$envname='$envval'" >> config.status
  2462. echo "export $envname" >> config.status
  2463. else
  2464. echo "unset $envname" >> config.status
  2465. fi
  2466. }
  2467. # Preserve various env variables that influence what
  2468. # features/build target configure will detect
  2469. preserve_env AR
  2470. preserve_env AS
  2471. preserve_env CC
  2472. preserve_env CFLAGS
  2473. preserve_env CXX
  2474. preserve_env CXXFLAGS
  2475. preserve_env LD
  2476. preserve_env LDFLAGS
  2477. preserve_env LD_LIBRARY_PATH
  2478. preserve_env MAKE
  2479. preserve_env NM
  2480. preserve_env OBJCFLAGS
  2481. preserve_env OBJCOPY
  2482. preserve_env PATH
  2483. preserve_env PKG_CONFIG
  2484. preserve_env PKG_CONFIG_LIBDIR
  2485. preserve_env PKG_CONFIG_PATH
  2486. preserve_env PYTHON
  2487. preserve_env QEMU_GA_MANUFACTURER
  2488. preserve_env QEMU_GA_DISTRO
  2489. preserve_env QEMU_GA_VERSION
  2490. preserve_env SDL2_CONFIG
  2491. preserve_env SMBD
  2492. preserve_env STRIP
  2493. preserve_env WIDL
  2494. preserve_env WINDRES
  2495. preserve_env WINDMC
  2496. printf "exec" >>config.status
  2497. for i in "$0" "$@"; do
  2498. test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
  2499. done
  2500. echo ' "$@"' >>config.status
  2501. chmod +x config.status
  2502. rm -r "$TMPDIR1"