configure 76 KB

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