configure 78 KB

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