qemu-9999.ebuild 21 KB

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