9bca6b105ee69b07ac7b521ecd3f26a86dfdc5d7
[gentoo.git] / app-emulation / xen-tools / xen-tools-4.7.3.ebuild
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=5
5
6 PYTHON_COMPAT=( python2_7 )
7 PYTHON_REQ_USE='ncurses,xml,threads'
8
9 inherit eutils bash-completion-r1 flag-o-matic multilib python-single-r1 toolchain-funcs versionator
10
11 MY_PV=${PV/_/-}
12 MAJOR_V="$(get_version_component_range 1-2)"
13
14 if [[ $PV == *9999 ]]; then
15         inherit git-r3
16         KEYWORDS="amd64 ~x86"
17         REPO="xen.git"
18         EGIT_REPO_URI="git://xenbits.xen.org/${REPO}"
19         S="${WORKDIR}/${REPO}"
20 else
21         KEYWORDS="amd64 ~arm ~arm64 ~x86"
22         UPSTREAM_VER=
23         SECURITY_VER=
24         # xen-tools's gentoo patches tarball
25         GENTOO_VER=9
26         # xen-tools's gentoo patches version which apply to this specific ebuild
27         GENTOO_GPV=0
28         # xen-tools ovmf's patches
29         OVMF_VER=2
30
31         SEABIOS_VER=1.8.2
32         # OVMF upstream 52a99493cce88a9d4ec8a02d7f1bd1a1001ce60d
33         OVMF_PV=20151110
34
35         [[ -n ${UPSTREAM_VER} ]] && \
36                 UPSTREAM_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${P/-tools/}-upstream-patches-${UPSTREAM_VER}.tar.xz"
37         [[ -n ${SECURITY_VER} ]] && \
38                 SECURITY_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${PN/-tools}-security-patches-${SECURITY_VER}.tar.xz"
39         [[ -n ${GENTOO_VER} ]] && \
40                 GENTOO_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${PN/-tools}-gentoo-patches-${GENTOO_VER}.tar.xz"
41         [[ -n ${OVMF_VER} ]] && \
42                 OVMF_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${PN/-tools}-ovmf-patches-${OVMF_VER}.tar.xz"
43
44         SRC_URI="https://downloads.xenproject.org/release/xen/${MY_PV}/xen-${MY_PV}.tar.gz
45         http://code.coreboot.org/p/seabios/downloads/get/seabios-${SEABIOS_VER}.tar.gz
46         https://dev.gentoo.org/~dlan/distfiles/seabios-${SEABIOS_VER}.tar.gz
47         ovmf? ( https://dev.gentoo.org/~dlan/distfiles/ovmf-${OVMF_PV}.tar.bz2
48                 ${OVMF_PATCHSET_URI} )
49         ${UPSTREAM_PATCHSET_URI}
50         ${SECURITY_PATCHSET_URI}
51         ${GENTOO_PATCHSET_URI}"
52
53         S="${WORKDIR}/xen-${MY_PV}"
54 fi
55
56 DESCRIPTION="Xen tools including QEMU and xl"
57 HOMEPAGE="http://xen.org/"
58 DOCS=( README docs/README.xen-bugtool )
59
60 LICENSE="GPL-2"
61 SLOT="0/${MAJOR_V}"
62 # Inclusion of IUSE ocaml on stabalizing requires maintainer of ocaml to (get off his hands and) make
63 # >=dev-lang/ocaml-4 stable
64 # Masked in profiles/eapi-5-files instead
65 IUSE="api custom-cflags debug doc flask hvm +qemu ocaml ovmf +qemu-traditional +pam python pygrub screen sdl static-libs system-qemu system-seabios"
66
67 REQUIRED_USE="
68         ${PYTHON_REQUIRED_USE}
69         pygrub? ( python )
70         ovmf? ( hvm )
71         ^^ ( qemu system-qemu )"
72
73 COMMON_DEPEND="
74         dev-libs/lzo:2
75         dev-libs/glib:2
76         dev-libs/yajl
77         dev-libs/libaio
78         dev-libs/libgcrypt:0
79         sys-libs/zlib
80         ${PYTHON_DEPS}
81 "
82
83 DEPEND="${COMMON_DEPEND}
84         dev-python/lxml[${PYTHON_USEDEP}]
85         x86? ( sys-devel/dev86
86                 sys-power/iasl )
87         pam? ( dev-python/pypam[${PYTHON_USEDEP}] )
88         api? ( dev-libs/libxml2
89                 net-misc/curl )
90         ovmf? (
91                 !arm? ( !arm64? ( dev-lang/nasm ) )
92                 $(python_gen_impl_dep sqlite)
93                 )
94         !amd64? ( >=sys-apps/dtc-1.4.0 )
95         amd64? ( sys-devel/bin86
96                 system-seabios? ( sys-firmware/seabios )
97                 sys-firmware/ipxe
98                 sys-devel/dev86
99                 sys-power/iasl )
100         dev-lang/perl
101         app-misc/pax-utils
102         doc? (
103                 app-doc/doxygen
104                 dev-python/markdown[${PYTHON_USEDEP}]
105                 dev-tex/latex2html[png,gif]
106                 media-gfx/graphviz
107                 dev-tex/xcolor
108                 media-gfx/transfig
109                 dev-texlive/texlive-latexextra
110                 virtual/latex-base
111                 dev-tex/latexmk
112                 dev-texlive/texlive-latex
113                 dev-texlive/texlive-pictures
114                 dev-texlive/texlive-latexrecommended
115         )
116         hvm? ( x11-proto/xproto
117                 !net-libs/libiscsi )
118         qemu? (
119                 x11-libs/pixman
120                 sdl? ( media-libs/libsdl[X] )
121         )
122         system-qemu? ( app-emulation/qemu[xen] )
123         ocaml? ( dev-ml/findlib
124                 >=dev-lang/ocaml-4 )"
125
126 RDEPEND="${COMMON_DEPEND}
127         sys-apps/iproute2[-minimal]
128         net-misc/bridge-utils
129         screen? (
130                 app-misc/screen
131                 app-admin/logrotate
132         )"
133
134 # hvmloader is used to bootstrap a fully virtualized kernel
135 # Approved by QA team in bug #144032
136 QA_WX_LOAD="usr/lib/xen/boot/hvmloader
137         usr/share/qemu-xen/qemu/s390-ccw.img"
138
139 RESTRICT="test"
140
141 pkg_setup() {
142         python_setup
143         export "CONFIG_LOMOUNT=y"
144
145         #bug 522642, disable compile tools/tests
146         export "CONFIG_TESTS=n"
147
148         if has_version dev-libs/libgcrypt:0; then
149                 export "CONFIG_GCRYPT=y"
150         fi
151
152         if [[ -z ${XEN_TARGET_ARCH} ]] ; then
153                 if use x86 && use amd64; then
154                         die "Confusion! Both x86 and amd64 are set in your use flags!"
155                 elif use x86; then
156                         export XEN_TARGET_ARCH="x86_32"
157                 elif use amd64 ; then
158                         export XEN_TARGET_ARCH="x86_64"
159                 elif use arm; then
160                         export XEN_TARGET_ARCH="arm32"
161                 elif use arm64; then
162                         export XEN_TARGET_ARCH="arm64"
163                 else
164                         die "Unsupported architecture!"
165                 fi
166         fi
167 }
168
169 src_prepare() {
170         # Upstream's patchset
171         if [[ -n ${UPSTREAM_VER} ]]; then
172                 einfo "Try to apply Xen Upstream patch set"
173                 EPATCH_SUFFIX="patch" \
174                 EPATCH_FORCE="yes" \
175                 EPATCH_OPTS="-p1" \
176                         epatch "${WORKDIR}"/patches-upstream
177         fi
178
179         # Security patchset
180         if [[ -n ${SECURITY_VER} ]]; then
181         einfo "Try to apply Xen Security patch set"
182                 # apply main xen patches
183                 # Two parallel systems, both work side by side
184                 # Over time they may concdense into one. This will suffice for now
185                 EPATCH_SUFFIX="patch"
186                 EPATCH_FORCE="yes"
187
188                 source "${WORKDIR}"/patches-security/${PV}.conf || die
189
190                 for i in ${XEN_SECURITY_MAIN}; do
191                         epatch "${WORKDIR}"/patches-security/xen/$i
192                 done
193
194                 # apply qemu-xen/upstream patches
195                 pushd "${S}"/tools/qemu-xen/ > /dev/null
196                 for i in ${XEN_SECURITY_QEMUU}; do
197                         epatch "${WORKDIR}"/patches-security/qemuu/$i
198                 done
199                 popd > /dev/null
200
201                 # apply qemu-traditional patches
202                 pushd "${S}"/tools/qemu-xen-traditional/ > /dev/null
203                 for i in ${XEN_SECURITY_QEMUT}; do
204                         epatch "${WORKDIR}"/patches-security/qemut/$i
205                 done
206                 popd > /dev/null
207         fi
208
209         # move before Gentoo patch, one patch should apply to seabios, to fix gcc-4.5.x build err
210         mv ../seabios-${SEABIOS_VER} tools/firmware/seabios-dir-remote || die
211         pushd tools/firmware/ > /dev/null
212         ln -s seabios-dir-remote seabios-dir || die
213         popd > /dev/null
214
215         # Gentoo's patchset
216         if [[ -n ${GENTOO_VER} && -n ${GENTOO_GPV} ]]; then
217                 einfo "Try to apply Gentoo specific patch set"
218                 source "${FILESDIR}"/gentoo-patches.conf || die
219                 _gpv=_gpv_${PN/-/_}_${PV//./}_${GENTOO_GPV}
220                 for i in ${!_gpv}; do
221                         EPATCH_SUFFIX="patch" \
222                         EPATCH_FORCE="yes" \
223                                 epatch "${WORKDIR}"/patches-gentoo/$i
224                 done
225         fi
226
227         # Ovmf's patchset
228         if use ovmf; then
229                 if [[ -n ${OVMF_VER} ]];then
230                         einfo "Try to apply Ovmf patch set"
231                         pushd "${WORKDIR}"/ovmf-*/ > /dev/null
232                         EPATCH_SUFFIX="patch" \
233                         EPATCH_FORCE="yes" \
234                         EPATCH_OPTS="-p1" \
235                                 epatch "${WORKDIR}"/patches-ovmf
236                         popd > /dev/null
237                 fi
238                 mv ../ovmf-${OVMF_PV} tools/firmware/ovmf-dir-remote || die
239         fi
240
241         mv tools/qemu-xen/qemu-bridge-helper.c tools/qemu-xen/xen-bridge-helper.c || die
242
243         # Fix texi2html build error with new texi2html, qemu.doc.html
244         sed -i -e "/texi2html -monolithic/s/-number//" tools/qemu-xen-traditional/Makefile || die
245
246         use api   || sed -e "/SUBDIRS-\$(LIBXENAPI_BINDINGS) += libxen/d" -i tools/Makefile || die
247         sed -e 's:$(MAKE) PYTHON=$(PYTHON) subdirs-$@:LC_ALL=C "$(MAKE)" PYTHON=$(PYTHON) subdirs-$@:' \
248                  -i tools/firmware/Makefile || die
249
250         # Drop .config, fixes to gcc-4.6
251         sed -e '/-include $(XEN_ROOT)\/.config/d' -i Config.mk || die "Couldn't drop"
252
253         # if the user *really* wants to use their own custom-cflags, let them
254         if use custom-cflags; then
255                 einfo "User wants their own CFLAGS - removing defaults"
256
257                 # try and remove all the default cflags
258                 find "${S}" \( -name Makefile -o -name Rules.mk -o -name Config.mk \) \
259                         -exec sed \
260                                 -e 's/CFLAGS\(.*\)=\(.*\)-O3\(.*\)/CFLAGS\1=\2\3/' \
261                                 -e 's/CFLAGS\(.*\)=\(.*\)-march=i686\(.*\)/CFLAGS\1=\2\3/' \
262                                 -e 's/CFLAGS\(.*\)=\(.*\)-fomit-frame-pointer\(.*\)/CFLAGS\1=\2\3/' \
263                                 -e 's/CFLAGS\(.*\)=\(.*\)-g3*\s\(.*\)/CFLAGS\1=\2 \3/' \
264                                 -e 's/CFLAGS\(.*\)=\(.*\)-O2\(.*\)/CFLAGS\1=\2\3/' \
265                                 -i {} + || die "failed to re-set custom-cflags"
266         else
267                 unset CFLAGS
268                 unset LDFLAGS
269                 unset ASFLAGS
270                 unset CPPFLAGS
271         fi
272
273         if ! use pygrub; then
274                 sed -e '/^SUBDIRS-y += pygrub/d' -i tools/Makefile || die
275         fi
276
277         if ! use python; then
278                 sed -e '/^SUBDIRS-y += python$/d' -i tools/Makefile || die
279         fi
280
281         if ! use hvm; then
282                 sed -e '/SUBDIRS-$(CONFIG_X86) += firmware/d' -i tools/Makefile || die
283         # Bug 351648
284         elif ! use x86 && ! has x86 $(get_all_abis); then
285                 mkdir -p "${WORKDIR}"/extra-headers/gnu || die
286                 touch "${WORKDIR}"/extra-headers/gnu/stubs-32.h || die
287                 export CPATH="${WORKDIR}"/extra-headers
288         fi
289
290         if use qemu; then
291                 if use sdl; then
292                         sed -i -e "s:\$\$source/configure:\0 --enable-sdl:" \
293                                 tools/Makefile || die
294                 else
295                         sed -i -e "s:\${QEMU_ROOT\:\-\.}/configure:\0 --disable-sdl:" \
296                                 tools/qemu-xen-traditional/xen-setup || die
297                         sed -i -e "s:\$\$source/configure:\0 --disable-sdl:" \
298                                 tools/Makefile || die
299                 fi
300         else
301                 # Don't bother with qemu, only needed for fully virtualised guests
302                 sed -e "s:install-tools\: tools/qemu-xen-traditional-dir:install-tools\: :g" -i Makefile || die
303         fi
304
305         # Reset bash completion dir; Bug 472438
306         sed -e "s:^BASH_COMPLETION_DIR ?= \$(CONFIG_DIR)/bash_completion.d:BASH_COMPLETION_DIR ?= $(get_bashcompdir):" \
307                 -i Config.mk || die
308         sed -i -e "/bash-completion/s/xl\.sh/xl/g" tools/libxl/Makefile || die
309
310         # xencommons, Bug #492332, sed lighter weight than patching
311         sed -e 's:\$QEMU_XEN -xen-domid:test -e "\$QEMU_XEN" \&\& &:' \
312                 -i tools/hotplug/Linux/init.d/xencommons.in || die
313
314         # respect multilib, usr/lib/libcacard.so.0.0.0
315         sed -e "/^libdir=/s/\/lib/\/$(get_libdir)/" \
316                 -i tools/qemu-xen/configure || die
317
318         #bug 518136, don't build 32bit exactuable for nomultilib profile
319         if [[ "${ARCH}" == 'amd64' ]] && ! has_multilib_profile; then
320                 sed -i -e "/x86_emulator/d" tools/tests/Makefile || die
321         fi
322
323         # use /var instead of /var/lib, consistat with previous ebuild
324         sed -i -e   "/XEN_LOCK_DIR=/s/\$localstatedir/\/var/g" \
325                 m4/paths.m4 configure tools/configure || die
326         # use /run instead of /var/run
327         sed -i -e   "/XEN_RUN_DIR=/s/\$localstatedir//g" \
328                 m4/paths.m4 configure tools/configure || die
329
330         # uncomment lines in xl.conf
331         sed -e 's:^#autoballoon=:autoballoon=:' \
332                 -e 's:^#lockfile=:lockfile=:' \
333                 -e 's:^#vif.default.script=:vif.default.script=:' \
334                 -i tools/examples/xl.conf  || die
335
336         # Bug #575868 converted to a sed statement, typo of one char
337         sed -e "s:granter’s:granter's:" -i xen/include/public/grant_table.h || die
338
339         epatch_user
340 }
341
342 src_configure() {
343         local myconf="--prefix=${PREFIX}/usr \
344                 --libdir=${PREFIX}/usr/$(get_libdir) \
345                 --libexecdir=${PREFIX}/usr/libexec \
346                 --disable-werror \
347                 --disable-xen \
348                 --enable-tools \
349                 --enable-docs \
350                 $(use_enable pam) \
351                 $(use_enable api xenapi) \
352                 $(use_enable ovmf) \
353                 $(use_enable ocaml ocamltools) \
354                 --with-xenstored=$(usex ocaml 'oxenstored' 'xenstored') \
355                 "
356
357         use system-seabios && myconf+=" --with-system-seabios=/usr/share/seabios/bios.bin"
358         use system-qemu && myconf+=" --with-system-qemu=/usr/bin/qemu-system-x86_64"
359         use amd64 && myconf+=" $(use_enable qemu-traditional)"
360         econf ${myconf}
361 }
362
363 src_compile() {
364         export VARTEXFONTS="${T}/fonts"
365         local myopt
366         use debug && myopt="${myopt} debug=y"
367
368         if test-flag-CC -fno-strict-overflow; then
369                 append-flags -fno-strict-overflow
370         fi
371
372         emake V=1 CC="$(tc-getCC)" LD="$(tc-getLD)" AR="$(tc-getAR)" RANLIB="$(tc-getRANLIB)" -C tools ${myopt}
373
374         use doc && emake -C docs txt html
375         emake -C docs man-pages
376 }
377
378 src_install() {
379         # Override auto-detection in the build system, bug #382573
380         export INITD_DIR=/tmp/init.d
381         export CONFIG_LEAF_DIR=../tmp/default
382
383         # Let the build system compile installed Python modules.
384         local PYTHONDONTWRITEBYTECODE
385         export PYTHONDONTWRITEBYTECODE
386
387         emake DESTDIR="${ED}" DOCDIR="/usr/share/doc/${PF}" \
388                 XEN_PYTHON_NATIVE_INSTALL=y install-tools
389
390         # Fix the remaining Python shebangs.
391         python_fix_shebang "${D}"
392
393         # Remove RedHat-specific stuff
394         rm -rf "${D}"tmp || die
395
396         if use doc; then
397                 emake DESTDIR="${D}" DOCDIR="/usr/share/doc/${PF}" install-docs
398
399                 dohtml -r docs/
400                 docinto pdf
401                 dodoc ${DOCS[@]}
402                 [ -d "${D}"/usr/share/doc/xen ] && mv "${D}"/usr/share/doc/xen/* "${D}"/usr/share/doc/${PF}/html
403         fi
404
405         rm -rf "${D}"/usr/share/doc/xen/
406         doman docs/man?/*
407
408         newconfd "${FILESDIR}"/xendomains.confd xendomains
409         newconfd "${FILESDIR}"/xenstored.confd xenstored
410         newconfd "${FILESDIR}"/xenconsoled.confd xenconsoled
411         newinitd "${FILESDIR}"/xendomains.initd-r2 xendomains
412         newinitd "${FILESDIR}"/xenstored.initd xenstored
413         newinitd "${FILESDIR}"/xenconsoled.initd xenconsoled
414         newinitd "${FILESDIR}"/xencommons.initd xencommons
415         newconfd "${FILESDIR}"/xencommons.confd xencommons
416         newinitd "${FILESDIR}"/xenqemudev.initd xenqemudev
417         newconfd "${FILESDIR}"/xenqemudev.confd xenqemudev
418
419         if use screen; then
420                 cat "${FILESDIR}"/xendomains-screen.confd >> "${D}"/etc/conf.d/xendomains || die
421                 cp "${FILESDIR}"/xen-consoles.logrotate "${D}"/etc/xen/ || die
422                 keepdir /var/log/xen-consoles
423         fi
424
425         # For -static-libs wrt Bug 384355
426         if ! use static-libs; then
427                 rm -f "${D}"usr/$(get_libdir)/*.a "${D}"usr/$(get_libdir)/ocaml/*/*.a
428         fi
429
430         # for xendomains
431         keepdir /etc/xen/auto
432
433         # Remove files failing QA AFTER emake installs them, avoiding seeking absent files
434         find "${D}" \( -name openbios-sparc32 -o -name openbios-sparc64 \
435                 -o -name openbios-ppc -o -name palcode-clipper \) -delete || die
436 }
437
438 pkg_postinst() {
439         elog "Official Xen Guide and the offical wiki page:"
440         elog "https://wiki.gentoo.org/wiki/Xen"
441         elog "http://wiki.xen.org/wiki/Main_Page"
442         elog ""
443         elog "Recommended to utilise the xencommons script to config sytem At boot"
444         elog "Add by use of rc-update on completion of the install"
445
446         if ! use hvm; then
447                 echo
448                 elog "HVM (VT-x and AMD-V) support has been disabled. If you need hvm"
449                 elog "support enable the hvm use flag."
450                 elog "An x86 or amd64 system is required to build HVM support."
451         fi
452
453         if use qemu; then
454                 elog "The qemu-bridge-helper is renamed to the xen-bridge-helper in the in source"
455                 elog "build of qemu.  This allows for app-emulation/qemu to be emerged concurrently"
456                 elog "with the qemu capable xen.  It is up to the user to distinguish between and utilise"
457                 elog "the qemu-bridge-helper and the xen-bridge-helper.  File bugs of any issues that arise"
458         fi
459 }