configure 77 KB

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