2
0

configure 77 KB

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