qemu-2.8.0-r9.ebuild 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI="6"
  4. PYTHON_COMPAT=( python2_7 )
  5. PYTHON_REQ_USE="ncurses,readline"
  6. PLOCALES="bg de_DE fr_FR hu it tr zh_CN"
  7. inherit eutils flag-o-matic linux-info toolchain-funcs multilib python-r1 \
  8. user udev fcaps readme.gentoo-r1 pax-utils l10n
  9. if [[ ${PV} = *9999* ]]; then
  10. EGIT_REPO_URI="git://git.qemu.org/qemu.git"
  11. inherit git-r3
  12. SRC_URI=""
  13. else
  14. SRC_URI="http://wiki.qemu-project.org/download/${P}.tar.bz2"
  15. KEYWORDS="amd64 ~arm64 ~ppc ~ppc64 x86 ~x86-fbsd"
  16. fi
  17. # bug #606088
  18. SRC_URI+="
  19. https://dev.gentoo.org/~tamiko/distfiles/${P}-CVE-2016-9602-patches.tar.xz"
  20. DESCRIPTION="QEMU + Kernel-based Virtual Machine userland tools"
  21. HOMEPAGE="http://www.qemu.org http://www.linux-kvm.org"
  22. LICENSE="GPL-2 LGPL-2 BSD-2"
  23. SLOT="0"
  24. IUSE="accessibility +aio alsa bluetooth bzip2 +caps +curl debug +fdt
  25. glusterfs gnutls gtk gtk2 infiniband iscsi +jpeg kernel_linux
  26. kernel_FreeBSD lzo ncurses nfs nls numa opengl +pin-upstream-blobs +png
  27. pulseaudio python rbd sasl +seccomp sdl sdl2 selinux smartcard snappy
  28. spice ssh static static-user systemtap tci test +threads usb usbredir
  29. vde +vhost-net virgl virtfs +vnc vte xattr xen xfs"
  30. COMMON_TARGETS="aarch64 alpha arm cris i386 m68k microblaze microblazeel
  31. mips mips64 mips64el mipsel or32 ppc ppc64 s390x sh4 sh4eb sparc
  32. sparc64 x86_64"
  33. IUSE_SOFTMMU_TARGETS="${COMMON_TARGETS}
  34. lm32 moxie ppcemb tricore unicore32 xtensa xtensaeb"
  35. IUSE_USER_TARGETS="${COMMON_TARGETS}
  36. armeb mipsn32 mipsn32el ppc64abi32 ppc64le sparc32plus tilegx"
  37. use_softmmu_targets=$(printf ' qemu_softmmu_targets_%s' ${IUSE_SOFTMMU_TARGETS})
  38. use_user_targets=$(printf ' qemu_user_targets_%s' ${IUSE_USER_TARGETS})
  39. IUSE+=" ${use_softmmu_targets} ${use_user_targets}"
  40. # Allow no targets to be built so that people can get a tools-only build.
  41. # Block USE flag configurations known to not work.
  42. REQUIRED_USE="${PYTHON_REQUIRED_USE}
  43. gtk2? ( gtk )
  44. qemu_softmmu_targets_arm? ( fdt )
  45. qemu_softmmu_targets_microblaze? ( fdt )
  46. qemu_softmmu_targets_ppc? ( fdt )
  47. qemu_softmmu_targets_ppc64? ( fdt )
  48. sdl2? ( sdl )
  49. static? ( static-user !alsa !bluetooth !gtk !gtk2 !opengl !pulseaudio )
  50. virtfs? ( xattr )
  51. vte? ( gtk )"
  52. # Dependencies required for qemu tools (qemu-nbd, qemu-img, qemu-io, ...)
  53. # and user/softmmu targets (qemu-*, qemu-system-*).
  54. #
  55. # Yep, you need both libcap and libcap-ng since virtfs only uses libcap.
  56. #
  57. # The attr lib isn't always linked in (although the USE flag is always
  58. # respected). This is because qemu supports using the C library's API
  59. # when available rather than always using the extranl library.
  60. #
  61. # To configure and compile qemu user targets or tools alone the following
  62. # dependencies are not strictly necessary:
  63. # alsa? ( >=media-libs/alsa-lib-1.0.13 )
  64. # fdt? ( >=sys-apps/dtc-1.4.0[static-libs(+)] )
  65. # pulseaudio? ( media-sound/pulseaudio )
  66. # seccomp? ( >=sys-libs/libseccomp-2.1.0[static-libs(+)] )
  67. # but these are so few it is not worth the effort to separate this list.
  68. TARGETS_DEPEND="
  69. >=dev-libs/glib-2.0[static-libs(+)]
  70. >=x11-libs/pixman-0.28.0[static-libs(+)]
  71. sys-libs/zlib[static-libs(+)]
  72. accessibility? (
  73. app-accessibility/brltty[api]
  74. app-accessibility/brltty[static-libs(+)]
  75. )
  76. aio? ( dev-libs/libaio[static-libs(+)] )
  77. alsa? ( >=media-libs/alsa-lib-1.0.13 )
  78. bluetooth? ( net-wireless/bluez )
  79. bzip2? ( app-arch/bzip2[static-libs(+)] )
  80. caps? ( sys-libs/libcap-ng[static-libs(+)] )
  81. curl? ( >=net-misc/curl-7.15.4[static-libs(+)] )
  82. fdt? ( >=sys-apps/dtc-1.4.0[static-libs(+)] )
  83. glusterfs? ( >=sys-cluster/glusterfs-3.4.0[static-libs(+)] )
  84. gnutls? (
  85. dev-libs/nettle:=[static-libs(+)]
  86. >=net-libs/gnutls-3.0:=[static-libs(+)]
  87. )
  88. gtk? (
  89. gtk2? (
  90. x11-libs/gtk+:2
  91. vte? ( x11-libs/vte:0 )
  92. )
  93. !gtk2? (
  94. x11-libs/gtk+:3
  95. vte? ( x11-libs/vte:2.91 )
  96. )
  97. )
  98. infiniband? ( sys-fabric/librdmacm:=[static-libs(+)] )
  99. iscsi? ( net-libs/libiscsi )
  100. jpeg? ( virtual/jpeg:0=[static-libs(+)] )
  101. lzo? ( dev-libs/lzo:2[static-libs(+)] )
  102. ncurses? (
  103. sys-libs/ncurses:0=[unicode]
  104. sys-libs/ncurses:0=[static-libs(+)]
  105. )
  106. nfs? ( >=net-fs/libnfs-1.9.3[static-libs(+)] )
  107. numa? ( sys-process/numactl[static-libs(+)] )
  108. opengl? (
  109. virtual/opengl
  110. media-libs/libepoxy[static-libs(+)]
  111. media-libs/mesa[static-libs(+)]
  112. media-libs/mesa[egl,gbm]
  113. )
  114. png? ( media-libs/libpng:0=[static-libs(+)] )
  115. pulseaudio? ( media-sound/pulseaudio )
  116. python? ( ${PYTHON_DEPS} )
  117. rbd? ( sys-cluster/ceph[static-libs(+)] )
  118. sasl? ( dev-libs/cyrus-sasl[static-libs(+)] )
  119. sdl? (
  120. !sdl2? (
  121. media-libs/libsdl[X]
  122. >=media-libs/libsdl-1.2.11[static-libs(+)]
  123. )
  124. sdl2? (
  125. media-libs/libsdl2[X]
  126. media-libs/libsdl2[static-libs(+)]
  127. )
  128. )
  129. seccomp? ( >=sys-libs/libseccomp-2.1.0[static-libs(+)] )
  130. smartcard? ( >=app-emulation/libcacard-2.5.0[static-libs(+)] )
  131. snappy? ( app-arch/snappy[static-libs(+)] )
  132. spice? (
  133. >=app-emulation/spice-protocol-0.12.3
  134. >=app-emulation/spice-0.12.0[static-libs(+)]
  135. )
  136. ssh? ( >=net-libs/libssh2-1.2.8[static-libs(+)] )
  137. systemtap? ( dev-util/systemtap )
  138. usbredir? ( >=sys-apps/usbredir-0.6[static-libs(+)] )
  139. usb? ( >=virtual/libusb-1-r2[static-libs(+)] )
  140. vde? ( net-misc/vde[static-libs(+)] )
  141. virgl? ( media-libs/virglrenderer[static-libs(+)] )
  142. virtfs? ( sys-libs/libcap )
  143. xattr? ( sys-apps/attr[static-libs(+)] )
  144. xen? ( app-emulation/xen-tools:= )
  145. xfs? ( sys-fs/xfsprogs[static-libs(+)] )"
  146. X86_FIRMWARE_DEPEND="
  147. >=sys-firmware/ipxe-1.0.0_p20130624
  148. pin-upstream-blobs? (
  149. ~sys-firmware/seabios-1.10.1
  150. ~sys-firmware/sgabios-0.1_pre8
  151. ~sys-firmware/vgabios-0.7a
  152. )
  153. !pin-upstream-blobs? (
  154. sys-firmware/seabios
  155. sys-firmware/sgabios
  156. sys-firmware/vgabios
  157. )"
  158. CDEPEND="
  159. !static? ( ${TARGETS_DEPEND//\[static-libs(+)]} )
  160. qemu_softmmu_targets_i386? ( ${X86_FIRMWARE_DEPEND} )
  161. qemu_softmmu_targets_x86_64? ( ${X86_FIRMWARE_DEPEND} )"
  162. DEPEND="${CDEPEND}
  163. dev-lang/perl
  164. =dev-lang/python-2*
  165. sys-apps/texinfo
  166. virtual/pkgconfig
  167. kernel_linux? ( >=sys-kernel/linux-headers-2.6.35 )
  168. gtk? ( nls? ( sys-devel/gettext ) )
  169. static? ( ${TARGETS_DEPEND} )
  170. static-user? ( ${TARGETS_DEPEND} )
  171. test? (
  172. dev-libs/glib[utils]
  173. sys-devel/bc
  174. )"
  175. RDEPEND="${CDEPEND}
  176. selinux? ( sec-policy/selinux-qemu )"
  177. PATCHES=(
  178. "${FILESDIR}"/${PN}-2.5.0-cflags.patch
  179. "${FILESDIR}"/${PN}-2.5.0-sysmacros.patch
  180. "${FILESDIR}"/${PN}-2.7.0-CVE-2016-8669-1.patch #597108
  181. "${FILESDIR}"/${PN}-2.8.0-CVE-2016-9908.patch #601826
  182. "${FILESDIR}"/${PN}-2.8.0-CVE-2016-9912.patch #602630
  183. "${FILESDIR}"/${PN}-2.8.0-CVE-2016-10028.patch #603444
  184. "${FILESDIR}"/${PN}-2.8.0-CVE-2016-10155.patch #606720
  185. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-2615.patch #608034
  186. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-2630.patch #609396
  187. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-5525-1.patch #606264
  188. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-5525-2.patch
  189. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-5552.patch #606722
  190. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-5578.patch #607000
  191. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-5579.patch #607100
  192. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-5667.patch #607766
  193. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-5856.patch #608036
  194. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-5857.patch #608038
  195. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-5898.patch #608520
  196. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-5931.patch #608728
  197. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-5973.patch #609334
  198. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-5987.patch #609398
  199. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-6058.patch #609638
  200. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-2620.patch #609206
  201. "${FILESDIR}"/${PN}-2.8.0-CVE-2017-6505.patch #612220
  202. "${S}-CVE-2016-9602-patches"
  203. )
  204. STRIP_MASK="/usr/share/qemu/palcode-clipper"
  205. QA_PREBUILT="
  206. usr/share/qemu/openbios-ppc
  207. usr/share/qemu/openbios-sparc64
  208. usr/share/qemu/openbios-sparc32
  209. usr/share/qemu/palcode-clipper
  210. usr/share/qemu/s390-ccw.img
  211. usr/share/qemu/u-boot.e500"
  212. QA_WX_LOAD="usr/bin/qemu-i386
  213. usr/bin/qemu-x86_64
  214. usr/bin/qemu-alpha
  215. usr/bin/qemu-arm
  216. usr/bin/qemu-cris
  217. usr/bin/qemu-m68k
  218. usr/bin/qemu-microblaze
  219. usr/bin/qemu-microblazeel
  220. usr/bin/qemu-mips
  221. usr/bin/qemu-mipsel
  222. usr/bin/qemu-or32
  223. usr/bin/qemu-ppc
  224. usr/bin/qemu-ppc64
  225. usr/bin/qemu-ppc64abi32
  226. usr/bin/qemu-sh4
  227. usr/bin/qemu-sh4eb
  228. usr/bin/qemu-sparc
  229. usr/bin/qemu-sparc64
  230. usr/bin/qemu-armeb
  231. usr/bin/qemu-sparc32plus
  232. usr/bin/qemu-s390x
  233. usr/bin/qemu-unicore32"
  234. DOC_CONTENTS="If you don't have kvm compiled into the kernel, make sure you have the
  235. kernel module loaded before running kvm. The easiest way to ensure that the
  236. kernel module is loaded is to load it on boot.
  237. For AMD CPUs the module is called 'kvm-amd'.
  238. For Intel CPUs the module is called 'kvm-intel'.
  239. Please review /etc/conf.d/modules for how to load these.
  240. Make sure your user is in the 'kvm' group. Just run
  241. $ gpasswd -a <USER> kvm
  242. then have <USER> re-login.
  243. For brand new installs, the default permissions on /dev/kvm might not let
  244. you access it. You can tell udev to reset ownership/perms:
  245. $ udevadm trigger -c add /dev/kvm
  246. If you want to register binfmt handlers for qemu user targets:
  247. For openrc:
  248. # rc-update add qemu-binfmt
  249. For systemd:
  250. # ln -s /usr/share/qemu/binfmt.d/qemu.conf /etc/binfmt.d/qemu.conf"
  251. pkg_pretend() {
  252. if use kernel_linux && kernel_is lt 2 6 25; then
  253. eerror "This version of KVM requres a host kernel of 2.6.25 or higher."
  254. elif use kernel_linux; then
  255. if ! linux_config_exists; then
  256. eerror "Unable to check your kernel for KVM support"
  257. else
  258. CONFIG_CHECK="~KVM ~TUN ~BRIDGE"
  259. ERROR_KVM="You must enable KVM in your kernel to continue"
  260. ERROR_KVM_AMD="If you have an AMD CPU, you must enable KVM_AMD in"
  261. ERROR_KVM_AMD+=" your kernel configuration."
  262. ERROR_KVM_INTEL="If you have an Intel CPU, you must enable"
  263. ERROR_KVM_INTEL+=" KVM_INTEL in your kernel configuration."
  264. ERROR_TUN="You will need the Universal TUN/TAP driver compiled"
  265. ERROR_TUN+=" into your kernel or loaded as a module to use the"
  266. ERROR_TUN+=" virtual network device if using -net tap."
  267. ERROR_BRIDGE="You will also need support for 802.1d"
  268. ERROR_BRIDGE+=" Ethernet Bridging for some network configurations."
  269. use vhost-net && CONFIG_CHECK+=" ~VHOST_NET"
  270. ERROR_VHOST_NET="You must enable VHOST_NET to have vhost-net"
  271. ERROR_VHOST_NET+=" support"
  272. if use amd64 || use x86 || use amd64-linux || use x86-linux; then
  273. CONFIG_CHECK+=" ~KVM_AMD ~KVM_INTEL"
  274. fi
  275. use python && CONFIG_CHECK+=" ~DEBUG_FS"
  276. ERROR_DEBUG_FS="debugFS support required for kvm_stat"
  277. # Now do the actual checks setup above
  278. check_extra_config
  279. fi
  280. fi
  281. if grep -qs '/usr/bin/qemu-kvm' "${EROOT}"/etc/libvirt/qemu/*.xml; then
  282. eerror "The kvm/qemu-kvm wrappers no longer exist, but your libvirt"
  283. eerror "instances are still pointing to it. Please update your"
  284. eerror "configs in /etc/libvirt/qemu/ to use the -enable-kvm flag"
  285. eerror "and the right system binary (e.g. qemu-system-x86_64)."
  286. die "update your virt configs to not use qemu-kvm"
  287. fi
  288. }
  289. pkg_setup() {
  290. enewgroup kvm 78
  291. }
  292. # Sanity check to make sure target lists are kept up-to-date.
  293. check_targets() {
  294. local var=$1 mak=$2
  295. local detected sorted
  296. pushd "${S}"/default-configs >/dev/null || die
  297. # Force C locale until glibc is updated. #564936
  298. detected=$(echo $(printf '%s\n' *-${mak}.mak | sed "s:-${mak}.mak::" | LC_COLLATE=C sort -u))
  299. sorted=$(echo $(printf '%s\n' ${!var} | LC_COLLATE=C sort -u))
  300. if [[ ${sorted} != "${detected}" ]] ; then
  301. eerror "The ebuild needs to be kept in sync."
  302. eerror "${var}: ${sorted}"
  303. eerror "$(printf '%-*s' ${#var} configure): ${detected}"
  304. die "sync ${var} to the list of targets"
  305. fi
  306. popd >/dev/null
  307. }
  308. handle_locales() {
  309. # Make sure locale list is kept up-to-date.
  310. local detected sorted
  311. detected=$(echo $(cd po && printf '%s\n' *.po | grep -v messages.po | sed 's:.po$::' | sort -u))
  312. sorted=$(echo $(printf '%s\n' ${PLOCALES} | sort -u))
  313. if [[ ${sorted} != "${detected}" ]] ; then
  314. eerror "The ebuild needs to be kept in sync."
  315. eerror "PLOCALES: ${sorted}"
  316. eerror " po/*.po: ${detected}"
  317. die "sync PLOCALES"
  318. fi
  319. # Deal with selective install of locales.
  320. if use nls ; then
  321. # Delete locales the user does not want. #577814
  322. rm_loc() { rm po/$1.po || die; }
  323. l10n_for_each_disabled_locale_do rm_loc
  324. else
  325. # Cheap hack to disable gettext .mo generation.
  326. rm -f po/*.po
  327. fi
  328. }
  329. src_prepare() {
  330. check_targets IUSE_SOFTMMU_TARGETS softmmu
  331. check_targets IUSE_USER_TARGETS linux-user
  332. # Alter target makefiles to accept CFLAGS set via flag-o
  333. sed -i -r \
  334. -e 's/^(C|OP_C|HELPER_C)FLAGS=/\1FLAGS+=/' \
  335. Makefile Makefile.target || die
  336. default
  337. # Fix ld and objcopy being called directly
  338. tc-export AR LD OBJCOPY
  339. # Verbose builds
  340. MAKEOPTS+=" V=1"
  341. # Run after we've applied all patches.
  342. handle_locales
  343. }
  344. ##
  345. # configures qemu based on the build directory and the build type
  346. # we are using.
  347. #
  348. qemu_src_configure() {
  349. debug-print-function ${FUNCNAME} "$@"
  350. local buildtype=$1
  351. local builddir="${S}/${buildtype}-build"
  352. mkdir "${builddir}"
  353. local conf_opts=(
  354. --prefix=/usr
  355. --sysconfdir=/etc
  356. --libdir=/usr/$(get_libdir)
  357. --docdir=/usr/share/doc/${PF}/html
  358. --disable-bsd-user
  359. --disable-guest-agent
  360. --disable-strip
  361. --disable-werror
  362. # We support gnutls/nettle for crypto operations. It is possible
  363. # to use gcrypt when gnutls/nettle are disabled (but not when they
  364. # are enabled), but it's not really worth the hassle. Disable it
  365. # all the time to avoid automatically detecting it. #568856
  366. --disable-gcrypt
  367. --python="${PYTHON}"
  368. --cc="$(tc-getCC)"
  369. --cxx="$(tc-getCXX)"
  370. --host-cc="$(tc-getBUILD_CC)"
  371. $(use_enable debug debug-info)
  372. $(use_enable debug debug-tcg)
  373. --enable-docs
  374. $(use_enable tci tcg-interpreter)
  375. $(use_enable xattr attr)
  376. )
  377. # Disable options not used by user targets. This simplifies building
  378. # static user targets (USE=static-user) considerably.
  379. conf_notuser() {
  380. if [[ ${buildtype} == "user" ]] ; then
  381. echo "--disable-${2:-$1}"
  382. else
  383. use_enable "$@"
  384. fi
  385. }
  386. conf_opts+=(
  387. $(conf_notuser accessibility brlapi)
  388. $(conf_notuser aio linux-aio)
  389. $(conf_notuser bzip2)
  390. $(conf_notuser bluetooth bluez)
  391. $(conf_notuser caps cap-ng)
  392. $(conf_notuser curl)
  393. $(conf_notuser fdt)
  394. $(conf_notuser glusterfs)
  395. $(conf_notuser gnutls)
  396. $(conf_notuser gnutls nettle)
  397. $(conf_notuser gtk)
  398. $(conf_notuser infiniband rdma)
  399. $(conf_notuser iscsi libiscsi)
  400. $(conf_notuser jpeg vnc-jpeg)
  401. $(conf_notuser kernel_linux kvm)
  402. $(conf_notuser lzo)
  403. $(conf_notuser ncurses curses)
  404. $(conf_notuser nfs libnfs)
  405. $(conf_notuser numa)
  406. $(conf_notuser opengl)
  407. $(conf_notuser png vnc-png)
  408. $(conf_notuser rbd)
  409. $(conf_notuser sasl vnc-sasl)
  410. $(conf_notuser sdl)
  411. $(conf_notuser seccomp)
  412. $(conf_notuser smartcard)
  413. $(conf_notuser snappy)
  414. $(conf_notuser spice)
  415. $(conf_notuser ssh libssh2)
  416. $(conf_notuser usb libusb)
  417. $(conf_notuser usbredir usb-redir)
  418. $(conf_notuser vde)
  419. $(conf_notuser vhost-net)
  420. $(conf_notuser virgl virglrenderer)
  421. $(conf_notuser virtfs)
  422. $(conf_notuser vnc)
  423. $(conf_notuser vte)
  424. $(conf_notuser xen)
  425. $(conf_notuser xen xen-pci-passthrough)
  426. $(conf_notuser xfs xfsctl)
  427. )
  428. if [[ ! ${buildtype} == "user" ]] ; then
  429. # audio options
  430. local audio_opts="oss"
  431. use alsa && audio_opts="alsa,${audio_opts}"
  432. use sdl && audio_opts="sdl,${audio_opts}"
  433. use pulseaudio && audio_opts="pa,${audio_opts}"
  434. conf_opts+=(
  435. --audio-drv-list="${audio_opts}"
  436. )
  437. use gtk && conf_opts+=( --with-gtkabi=$(usex gtk2 2.0 3.0) )
  438. use sdl && conf_opts+=( --with-sdlabi=$(usex sdl2 2.0 1.2) )
  439. fi
  440. case ${buildtype} in
  441. user)
  442. conf_opts+=(
  443. --enable-linux-user
  444. --disable-system
  445. --disable-blobs
  446. --disable-tools
  447. )
  448. local static_flag="static-user"
  449. ;;
  450. softmmu)
  451. conf_opts+=(
  452. --disable-linux-user
  453. --enable-system
  454. --disable-tools
  455. --with-system-pixman
  456. )
  457. local static_flag="static"
  458. ;;
  459. tools)
  460. conf_opts+=(
  461. --disable-linux-user
  462. --disable-system
  463. --disable-blobs
  464. --enable-tools
  465. )
  466. local static_flag="static"
  467. ;;
  468. esac
  469. local targets="${buildtype}_targets"
  470. [[ -n ${targets} ]] && conf_opts+=( --target-list="${!targets}" )
  471. # Add support for SystemTAP
  472. use systemtap && conf_opts+=( --enable-trace-backend=dtrace )
  473. # We always want to attempt to build with PIE support as it results
  474. # in a more secure binary. But it doesn't work with static or if
  475. # the current GCC doesn't have PIE support.
  476. if use ${static_flag}; then
  477. conf_opts+=( --static --disable-pie )
  478. else
  479. gcc-specs-pie && conf_opts+=( --enable-pie )
  480. fi
  481. echo "../configure ${conf_opts[*]}"
  482. cd "${builddir}"
  483. ../configure "${conf_opts[@]}" || die "configure failed"
  484. # FreeBSD's kernel does not support QEMU assigning/grabbing
  485. # host USB devices yet
  486. use kernel_FreeBSD && \
  487. sed -i -E -e "s|^(HOST_USB=)bsd|\1stub|" "${S}"/config-host.mak
  488. }
  489. src_configure() {
  490. local target
  491. python_setup
  492. softmmu_targets= softmmu_bins=()
  493. user_targets= user_bins=()
  494. for target in ${IUSE_SOFTMMU_TARGETS} ; do
  495. if use "qemu_softmmu_targets_${target}"; then
  496. softmmu_targets+=",${target}-softmmu"
  497. softmmu_bins+=( "qemu-system-${target}" )
  498. fi
  499. done
  500. for target in ${IUSE_USER_TARGETS} ; do
  501. if use "qemu_user_targets_${target}"; then
  502. user_targets+=",${target}-linux-user"
  503. user_bins+=( "qemu-${target}" )
  504. fi
  505. done
  506. softmmu_targets=${softmmu_targets#,}
  507. user_targets=${user_targets#,}
  508. [[ -n ${softmmu_targets} ]] && qemu_src_configure "softmmu"
  509. [[ -n ${user_targets} ]] && qemu_src_configure "user"
  510. qemu_src_configure "tools"
  511. }
  512. src_compile() {
  513. if [[ -n ${user_targets} ]]; then
  514. cd "${S}/user-build"
  515. default
  516. fi
  517. if [[ -n ${softmmu_targets} ]]; then
  518. cd "${S}/softmmu-build"
  519. default
  520. fi
  521. cd "${S}/tools-build"
  522. default
  523. }
  524. src_test() {
  525. if [[ -n ${softmmu_targets} ]]; then
  526. cd "${S}/softmmu-build"
  527. pax-mark m */qemu-system-* #515550
  528. emake -j1 check
  529. emake -j1 check-report.html
  530. fi
  531. }
  532. qemu_python_install() {
  533. python_domodule "${S}/scripts/qmp/qmp.py"
  534. python_doscript "${S}/scripts/kvm/vmxcap"
  535. python_doscript "${S}/scripts/qmp/qmp-shell"
  536. python_doscript "${S}/scripts/qmp/qemu-ga-client"
  537. }
  538. # Generate binfmt support files.
  539. # - /etc/init.d/qemu-binfmt script which registers the user handlers (openrc)
  540. # - /usr/share/qemu/binfmt.d/qemu.conf (for use with systemd-binfmt)
  541. generate_initd() {
  542. local out="${T}/qemu-binfmt"
  543. local out_systemd="${T}/qemu.conf"
  544. local d="${T}/binfmt.d"
  545. einfo "Generating qemu binfmt scripts and configuration files"
  546. # Generate the debian fragments first.
  547. mkdir -p "${d}"
  548. "${S}"/scripts/qemu-binfmt-conf.sh \
  549. --debian \
  550. --exportdir "${d}" \
  551. --qemu-path "${EPREFIX}/usr/bin" \
  552. || die
  553. # Then turn the fragments into a shell script we can source.
  554. sed -E -i \
  555. -e 's:^([^ ]+) (.*)$:\1="\2":' \
  556. "${d}"/* || die
  557. # Generate the init.d script by assembling the fragments from above.
  558. local f qcpu package interpreter magic mask
  559. cat "${FILESDIR}"/qemu-binfmt.initd.head >"${out}" || die
  560. for f in "${d}"/qemu-* ; do
  561. source "${f}"
  562. # Normalize the cpu logic like we do in the init.d for the native cpu.
  563. qcpu=${package#qemu-}
  564. case ${qcpu} in
  565. arm*) qcpu="arm";;
  566. mips*) qcpu="mips";;
  567. ppc*) qcpu="ppc";;
  568. s390*) qcpu="s390";;
  569. sh*) qcpu="sh";;
  570. sparc*) qcpu="sparc";;
  571. esac
  572. cat <<EOF >>"${out}"
  573. if [ "\${cpu}" != "${qcpu}" -a -x "${interpreter}" ] ; then
  574. echo ':${package}:M::${magic}:${mask}:${interpreter}:'"\${QEMU_BINFMT_FLAGS}" >/proc/sys/fs/binfmt_misc/register
  575. fi
  576. EOF
  577. echo ":${package}:M::${magic}:${mask}:${interpreter}:OC" >>"${out_systemd}"
  578. done
  579. cat "${FILESDIR}"/qemu-binfmt.initd.tail >>"${out}" || die
  580. }
  581. src_install() {
  582. if [[ -n ${user_targets} ]]; then
  583. cd "${S}/user-build"
  584. emake DESTDIR="${ED}" install
  585. # Install binfmt handler init script for user targets.
  586. generate_initd
  587. doinitd "${T}/qemu-binfmt"
  588. # Install binfmt/qemu.conf.
  589. insinto "/usr/share/qemu/binfmt.d"
  590. doins "${T}/qemu.conf"
  591. fi
  592. if [[ -n ${softmmu_targets} ]]; then
  593. cd "${S}/softmmu-build"
  594. emake DESTDIR="${ED}" install
  595. # This might not exist if the test failed. #512010
  596. [[ -e check-report.html ]] && dohtml check-report.html
  597. if use kernel_linux; then
  598. udev_newrules "${FILESDIR}"/65-kvm.rules-r1 65-kvm.rules
  599. fi
  600. if use python; then
  601. python_foreach_impl qemu_python_install
  602. fi
  603. fi
  604. cd "${S}/tools-build"
  605. emake DESTDIR="${ED}" install
  606. # Disable mprotect on the qemu binaries as they use JITs to be fast #459348
  607. pushd "${ED}"/usr/bin >/dev/null
  608. pax-mark mr "${softmmu_bins[@]}" "${user_bins[@]}" # bug 575594
  609. popd >/dev/null
  610. # Install config file example for qemu-bridge-helper
  611. insinto "/etc/qemu"
  612. doins "${FILESDIR}/bridge.conf"
  613. # Remove the docdir placed qmp-commands.txt
  614. mv "${ED}/usr/share/doc/${PF}/html/qmp-commands.txt" "${S}/docs/" || die
  615. cd "${S}"
  616. dodoc Changelog MAINTAINERS docs/specs/pci-ids.txt
  617. newdoc pc-bios/README README.pc-bios
  618. dodoc docs/qmp-*.txt
  619. if [[ -n ${softmmu_targets} ]]; then
  620. # Remove SeaBIOS since we're using the SeaBIOS packaged one
  621. rm "${ED}/usr/share/qemu/bios.bin"
  622. if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
  623. dosym ../seabios/bios.bin /usr/share/qemu/bios.bin
  624. fi
  625. # Remove vgabios since we're using the vgabios packaged one
  626. rm "${ED}/usr/share/qemu/vgabios.bin"
  627. rm "${ED}/usr/share/qemu/vgabios-cirrus.bin"
  628. rm "${ED}/usr/share/qemu/vgabios-qxl.bin"
  629. rm "${ED}/usr/share/qemu/vgabios-stdvga.bin"
  630. rm "${ED}/usr/share/qemu/vgabios-vmware.bin"
  631. if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
  632. dosym ../vgabios/vgabios.bin /usr/share/qemu/vgabios.bin
  633. dosym ../vgabios/vgabios-cirrus.bin /usr/share/qemu/vgabios-cirrus.bin
  634. dosym ../vgabios/vgabios-qxl.bin /usr/share/qemu/vgabios-qxl.bin
  635. dosym ../vgabios/vgabios-stdvga.bin /usr/share/qemu/vgabios-stdvga.bin
  636. dosym ../vgabios/vgabios-vmware.bin /usr/share/qemu/vgabios-vmware.bin
  637. fi
  638. # Remove sgabios since we're using the sgabios packaged one
  639. rm "${ED}/usr/share/qemu/sgabios.bin"
  640. if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
  641. dosym ../sgabios/sgabios.bin /usr/share/qemu/sgabios.bin
  642. fi
  643. # Remove iPXE since we're using the iPXE packaged one
  644. rm "${ED}"/usr/share/qemu/pxe-*.rom
  645. if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
  646. dosym ../ipxe/8086100e.rom /usr/share/qemu/pxe-e1000.rom
  647. dosym ../ipxe/80861209.rom /usr/share/qemu/pxe-eepro100.rom
  648. dosym ../ipxe/10500940.rom /usr/share/qemu/pxe-ne2k_pci.rom
  649. dosym ../ipxe/10222000.rom /usr/share/qemu/pxe-pcnet.rom
  650. dosym ../ipxe/10ec8139.rom /usr/share/qemu/pxe-rtl8139.rom
  651. dosym ../ipxe/1af41000.rom /usr/share/qemu/pxe-virtio.rom
  652. fi
  653. fi
  654. DISABLE_AUTOFORMATTING=true
  655. readme.gentoo_create_doc
  656. }
  657. pkg_postinst() {
  658. DISABLE_AUTOFORMATTING=true
  659. FORCE_PRINT_ELOG=1 # remove for next version bump
  660. readme.gentoo_print_elog
  661. if [[ -n ${softmmu_targets} ]] && use kernel_linux; then
  662. udev_reload
  663. fi
  664. fcaps cap_net_admin /usr/libexec/qemu-bridge-helper
  665. }
  666. pkg_info() {
  667. echo "Using:"
  668. echo " $(best_version app-emulation/spice-protocol)"
  669. echo " $(best_version sys-firmware/ipxe)"
  670. echo " $(best_version sys-firmware/seabios)"
  671. if has_version 'sys-firmware/seabios[binary]'; then
  672. echo " USE=binary"
  673. else
  674. echo " USE=''"
  675. fi
  676. echo " $(best_version sys-firmware/vgabios)"
  677. }