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