6577d28a58ec140f3e589f7a1a37ae102b09fa16
[gentoo.git] / app-emulation / xen / xen-4.6.3-r1.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 PYTHON_COMPAT=( python2_7 )
8
9 inherit eutils multilib mount-boot flag-o-matic python-any-r1 toolchain-funcs
10
11 MY_PV=${PV/_/-}
12 MY_P=${PN}-${PV/_/-}
13
14 if [[ $PV == *9999 ]]; then
15         inherit git-r3
16         KEYWORDS=""
17         EGIT_REPO_URI="git://xenbits.xen.org/xen.git"
18         SRC_URI=""
19 else
20         KEYWORDS="~amd64 ~arm -x86"
21         UPSTREAM_VER=
22         SECURITY_VER=13
23         GENTOO_VER=
24
25         [[ -n ${UPSTREAM_VER} ]] && \
26                 UPSTREAM_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${P}-upstream-patches-${UPSTREAM_VER}.tar.xz"
27         [[ -n ${SECURITY_VER} ]] && \
28                 SECURITY_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${PN}-security-patches-${SECURITY_VER}.tar.xz"
29         [[ -n ${GENTOO_VER} ]] && \
30                 GENTOO_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${PN}-gentoo-patches-${GENTOO_VER}.tar.xz"
31         SRC_URI="http://bits.xensource.com/oss-xen/release/${MY_PV}/${MY_P}.tar.gz
32                 ${UPSTREAM_PATCHSET_URI}
33                 ${SECURITY_PATCHSET_URI}
34                 ${GENTOO_PATCHSET_URI}"
35 fi
36
37 DESCRIPTION="The Xen virtual machine monitor"
38 HOMEPAGE="http://xen.org/"
39 LICENSE="GPL-2"
40 SLOT="0"
41 IUSE="custom-cflags debug efi flask"
42
43 DEPEND="${PYTHON_DEPS}
44         efi? ( >=sys-devel/binutils-2.22[multitarget] )
45         !efi? ( >=sys-devel/binutils-2.22 )"
46 RDEPEND=""
47 PDEPEND="~app-emulation/xen-tools-${PV}"
48
49 # no tests are available for the hypervisor
50 # prevent the silliness of /usr/lib/debug/usr/lib/debug files
51 # prevent stripping of the debug info from the /usr/lib/debug/xen-syms
52 RESTRICT="test splitdebug strip"
53
54 # Approved by QA team in bug #144032
55 QA_WX_LOAD="boot/xen-syms-${PV}"
56
57 REQUIRED_USE="arm? ( debug )"
58
59 S="${WORKDIR}/${MY_P}"
60
61 pkg_setup() {
62         python-any-r1_pkg_setup
63         if [[ -z ${XEN_TARGET_ARCH} ]]; then
64                 if use amd64; then
65                         export XEN_TARGET_ARCH="x86_64"
66                 elif use arm; then
67                         export XEN_TARGET_ARCH="arm32"
68                 elif use arm64; then
69                         export XEN_TARGET_ARCH="arm64"
70                 else
71                         die "Unsupported architecture!"
72                 fi
73         fi
74
75         if use flask ; then
76                 export "XSM_ENABLE=y"
77                 export "FLASK_ENABLE=y"
78         fi
79 }
80
81 src_prepare() {
82         # Upstream's patchset
83         if [[ -n ${UPSTREAM_VER} ]]; then
84                 EPATCH_SUFFIX="patch" \
85                 EPATCH_FORCE="yes" \
86                 EPATCH_OPTS="-p1" \
87                         epatch "${WORKDIR}"/patches-upstream
88         fi
89
90         # Security patchset
91         if [[ -n ${SECURITY_VER} ]]; then
92         einfo "Try to apply Xen Security patch set"
93                 # apply main xen patches
94                 # Two parallel systems, both work side by side
95                 # Over time they may concdense into one. This will suffice for now
96                 EPATCH_SUFFIX="patch"
97                 EPATCH_FORCE="yes"
98
99                 source "${WORKDIR}"/patches-security/${PV}.conf
100
101                 for i in ${XEN_SECURITY_MAIN}; do
102                         epatch "${WORKDIR}"/patches-security/xen/$i
103                 done
104         fi
105
106         # Gentoo's patchset
107         if [[ -n ${GENTOO_VER} ]]; then
108                 EPATCH_SUFFIX="patch" \
109                 EPATCH_FORCE="yes" \
110                         epatch "${WORKDIR}"/patches-gentoo
111         fi
112
113         epatch "${FILESDIR}"/${PN}-4.6-efi.patch
114
115         # Drop .config
116         sed -e '/-include $(XEN_ROOT)\/.config/d' -i Config.mk || die "Couldn't drop"
117
118         if use efi; then
119                 export EFI_VENDOR="gentoo"
120                 export EFI_MOUNTPOINT="boot"
121         fi
122
123         # if the user *really* wants to use their own custom-cflags, let them
124         if use custom-cflags; then
125                 einfo "User wants their own CFLAGS - removing defaults"
126                 # try and remove all the default custom-cflags
127                 find "${S}" -name Makefile -o -name Rules.mk -o -name Config.mk -exec sed \
128                         -e 's/CFLAGS\(.*\)=\(.*\)-O3\(.*\)/CFLAGS\1=\2\3/' \
129                         -e 's/CFLAGS\(.*\)=\(.*\)-march=i686\(.*\)/CFLAGS\1=\2\3/' \
130                         -e 's/CFLAGS\(.*\)=\(.*\)-fomit-frame-pointer\(.*\)/CFLAGS\1=\2\3/' \
131                         -e 's/CFLAGS\(.*\)=\(.*\)-g3*\s\(.*\)/CFLAGS\1=\2 \3/' \
132                         -e 's/CFLAGS\(.*\)=\(.*\)-O2\(.*\)/CFLAGS\1=\2\3/' \
133                         -i {} \; || die "failed to re-set custom-cflags"
134         fi
135
136         # remove -Werror for gcc-4.6's sake
137         find "${S}" -name 'Makefile*' -o -name '*.mk' -o -name 'common.make' | \
138                 xargs sed -i 's/ *-Werror */ /'
139         # not strictly necessary to fix this
140         sed -i 's/, "-Werror"//' "${S}/tools/python/setup.py" || die "failed to re-set setup.py"
141
142         # Bug #575868 converted to a sed statement, typo of one char
143         sed -e "s:granter’s:granter's:" -i xen/include/public/grant_table.h || die
144
145         epatch_user
146 }
147
148 src_configure() {
149         use arm && myopt="${myopt} CONFIG_EARLY_PRINTK=sun7i"
150
151         use debug && myopt="${myopt} debug=y"
152
153         if use custom-cflags; then
154                 filter-flags -fPIE -fstack-protector
155                 replace-flags -O3 -O2
156         else
157                 unset CFLAGS
158                 unset LDFLAGS
159                 unset ASFLAGS
160         fi
161 }
162
163 src_compile() {
164         # Send raw LDFLAGS so that --as-needed works
165         emake V=1 CC="$(tc-getCC)" LDFLAGS="$(raw-ldflags)" LD="$(tc-getLD)" -C xen ${myopt}
166 }
167
168 src_install() {
169         local myopt
170         use debug && myopt="${myopt} debug=y"
171
172         # The 'make install' doesn't 'mkdir -p' the subdirs
173         if use efi; then
174                 mkdir -p "${D}"${EFI_MOUNTPOINT}/efi/${EFI_VENDOR} || die
175         fi
176
177         emake LDFLAGS="$(raw-ldflags)" DESTDIR="${D}" -C xen ${myopt} install
178
179         # make install likes to throw in some extra EFI bits if it built
180         use efi || rm -rf "${D}/usr/$(get_libdir)/efi"
181 }
182
183 pkg_postinst() {
184         elog "Official Xen Guide and the unoffical wiki page:"
185         elog " https://wiki.gentoo.org/wiki/Xen"
186         elog " http://en.gentoo-wiki.com/wiki/Xen/"
187
188         use efi && einfo "The efi executable is installed in boot/efi/gentoo"
189
190         elog "You can optionally block the installation of /boot/xen-syms by an entry"
191         elog "in folder /etc/portage/env using the portage's feature INSTALL_MASK"
192         elog "e.g. echo ${msg} > /etc/portage/env/xen.conf"
193 }