sys-boot/grub: populate MULTIBUILD_VARIANTS in a more PMS-defined way
[gentoo.git] / sys-boot / grub / grub-9999-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=6
6
7 if [[ ${PV} == 9999  ]]; then
8         PYTHON_COMPAT=( python{2_7,3_3,3_4,3_5} )
9         inherit autotools python-any-r1
10 fi
11
12 inherit autotools bash-completion-r1 flag-o-matic multibuild pax-utils toolchain-funcs versionator
13
14 if [[ ${PV} != 9999 ]]; then
15         if [[ ${PV} == *_alpha* || ${PV} == *_beta* || ${PV} == *_rc* ]]; then
16                 # The quote style is to work with <=bash-4.2 and >=bash-4.3 #503860
17                 MY_P=${P/_/'~'}
18                 SRC_URI="mirror://gnu-alpha/${PN}/${MY_P}.tar.xz"
19                 S=${WORKDIR}/${MY_P}
20         else
21                 SRC_URI="mirror://gnu/${PN}/${P}.tar.xz
22                         mirror://gentoo/${P}.tar.xz
23                         https://dev.gentoo.org/~floppym/dist/${P}.tar.xz"
24                 S=${WORKDIR}/${P%_*}
25         fi
26         KEYWORDS="~amd64 ~x86"
27 else
28         inherit git-r3
29         EGIT_REPO_URI="git://git.sv.gnu.org/grub.git
30                 http://git.savannah.gnu.org/r/grub.git"
31 fi
32
33 PATCHES=(
34         "${FILESDIR}"/gfxpayload.patch
35         "${FILESDIR}"/grub-2.02_beta2-KERNEL_GLOBS.patch
36 )
37
38 DEJAVU=dejavu-sans-ttf-2.35
39 UNIFONT=unifont-8.0.01
40 SRC_URI+=" fonts? ( mirror://gnu/unifont/${UNIFONT}/${UNIFONT}.pcf.gz )
41         themes? ( mirror://sourceforge/dejavu/${DEJAVU}.zip )"
42
43 DESCRIPTION="GNU GRUB boot loader"
44 HOMEPAGE="https://www.gnu.org/software/grub/"
45
46 # Includes licenses for dejavu and unifont
47 LICENSE="GPL-3 fonts? ( GPL-2-with-font-exception ) themes? ( BitstreamVera )"
48 SLOT="2/${PVR}"
49 IUSE="debug device-mapper doc efiemu +fonts mount +multislot nls static sdl test +themes truetype libzfs"
50
51 GRUB_ALL_PLATFORMS=( coreboot efi-32 efi-64 emu ieee1275 loongson multiboot qemu qemu-mips pc uboot xen )
52 IUSE+=" ${GRUB_ALL_PLATFORMS[@]/#/grub_platforms_}"
53
54 REQUIRED_USE="
55         grub_platforms_coreboot? ( fonts )
56         grub_platforms_qemu? ( fonts )
57         grub_platforms_ieee1275? ( fonts )
58         grub_platforms_loongson? ( fonts )
59 "
60
61 # os-prober: Used on runtime to detect other OSes
62 # xorriso (dev-libs/libisoburn): Used on runtime for mkrescue
63 RDEPEND="
64         app-arch/xz-utils
65         >=sys-libs/ncurses-5.2-r5:0=
66         debug? (
67                 sdl? ( media-libs/libsdl )
68         )
69         device-mapper? ( >=sys-fs/lvm2-2.02.45 )
70         libzfs? ( sys-fs/zfs )
71         mount? ( sys-fs/fuse )
72         truetype? ( media-libs/freetype:2= )
73         ppc? ( sys-apps/ibm-powerpc-utils sys-apps/powerpc-utils )
74         ppc64? ( sys-apps/ibm-powerpc-utils sys-apps/powerpc-utils )
75 "
76 DEPEND="${RDEPEND}
77         ${PYTHON_DEPS}
78         app-misc/pax-utils
79         sys-devel/flex
80         sys-devel/bison
81         sys-apps/help2man
82         sys-apps/texinfo
83         fonts? ( media-libs/freetype:2 )
84         grub_platforms_xen? ( app-emulation/xen-tools:= )
85         static? (
86                 app-arch/xz-utils[static-libs(+)]
87                 truetype? (
88                         app-arch/bzip2[static-libs(+)]
89                         media-libs/freetype[static-libs(+)]
90                         sys-libs/zlib[static-libs(+)]
91                 )
92         )
93         test? (
94                 dev-libs/libisoburn
95                 app-emulation/qemu
96         )
97         themes? (
98                 app-arch/unzip
99                 media-libs/freetype:2
100         )
101 "
102 RDEPEND+="
103         kernel_linux? (
104                 grub_platforms_efi-32? ( sys-boot/efibootmgr )
105                 grub_platforms_efi-64? ( sys-boot/efibootmgr )
106         )
107         !multislot? ( !sys-boot/grub:0 )
108         nls? ( sys-devel/gettext )
109 "
110
111 DEPEND+=" !!=media-libs/freetype-2.5.4"
112
113 STRIP_MASK="*/grub/*/*.{mod,img}"
114 RESTRICT="test"
115
116 QA_EXECSTACK="
117         usr/bin/grub*-emu*
118         usr/lib*/grub/*/*.mod
119         usr/lib*/grub/*/*.module
120         usr/lib*/grub/*/kernel.exec
121         usr/lib*/grub/*/kernel.img
122 "
123
124 QA_WX_LOAD="
125         usr/lib*/grub/*/kernel.exec
126         usr/lib*/grub/*/kernel.img
127         usr/lib*/grub/*/*.image
128 "
129
130 QA_PRESTRIPPED="
131         usr/lib.*/grub/.*/kernel.img
132 "
133
134 src_unpack() {
135         if [[ ${PV} == 9999 ]]; then
136                 git-r3_src_unpack
137         fi
138         default
139 }
140
141 src_prepare() {
142         default
143
144         sed -i -e /autoreconf/d autogen.sh || die
145
146         if use multislot; then
147                 # fix texinfo file name, bug 416035
148                 sed -i -e 's/^\* GRUB:/* GRUB2:/' -e 's/(grub)/(grub2)/' docs/grub.texi || die
149         fi
150
151         if [[ ${PV} == 9999 ]]; then
152                 python_setup
153                 bash autogen.sh || die
154                 autopoint() { :; }
155                 eautoreconf
156         fi
157 }
158
159 grub_do() {
160         multibuild_foreach_variant run_in_build_dir "$@"
161 }
162
163 grub_do_once() {
164         multibuild_for_best_variant run_in_build_dir "$@"
165 }
166
167 grub_configure() {
168         local platform
169
170         case ${MULTIBUILD_VARIANT} in
171                 efi-32)
172                         platform=efi
173                         if [[ ${CTARGET:-${CHOST}} == x86_64* ]]; then
174                                 local CTARGET=${CTARGET:-i386}
175                         fi ;;
176                 efi-64)
177                         platform=efi
178                         if [[ ${CTARGET:-${CHOST}} == i?86* ]]; then
179                                 local CTARGET=${CTARGET:-x86_64}
180                                 local TARGET_CFLAGS="-Os -march=x86-64 ${TARGET_CFLAGS}"
181                                 local TARGET_CPPFLAGS="-march=x86-64 ${TARGET_CPPFLAGS}"
182                                 export TARGET_CFLAGS TARGET_CPPFLAGS
183                         fi ;;
184                 guessed) ;;
185                 *)      platform=${MULTIBUILD_VARIANT} ;;
186         esac
187
188         local myeconfargs=(
189                 --disable-werror
190                 --program-prefix=
191                 --libdir="${EPREFIX}"/usr/lib
192                 --htmldir="${EPREFIX}"/usr/share/doc/${PF}/html
193                 $(use_enable debug mm-debug)
194                 $(use_enable device-mapper)
195                 $(use_enable mount grub-mount)
196                 $(use_enable nls)
197                 $(use_enable themes grub-themes)
198                 $(use_enable truetype grub-mkfont)
199                 $(use_enable libzfs)
200                 $(use sdl && use_enable debug grub-emu-sdl)
201                 ${platform:+--with-platform=}${platform}
202
203                 # Let configure detect this where supported
204                 $(usex efiemu '' '--disable-efiemu')
205         )
206
207         if use multislot; then
208                 myeconfargs+=( --program-transform-name="s,grub,grub2," )
209         fi
210
211         # Set up font symlinks
212         ln -s "${WORKDIR}/${UNIFONT}.pcf" unifont.pcf || die
213         if use themes; then
214                 ln -s "${WORKDIR}/${DEJAVU}/ttf/DejaVuSans.ttf" DejaVuSans.ttf || die
215         fi
216
217         ECONF_SOURCE="${S}" econf "${myeconfargs[@]}"
218 }
219
220 grub_get_platforms() {
221         MULTIBUILD_VARIANTS=()
222         local platform
223         for platform in "${GRUB_ALL_PLATFORMS[@]}"; do
224                 if use "grub_platforms_${platform}"; then
225                         MULTIBUILD_VARIANTS+=( "${platform}" )
226                 fi
227         done
228         if (( ${#MULTIBUILD_VARIANTS[@]} == 0 )); then
229                 MULTIBUILD_VARIANTS=( guessed )
230         fi
231 }
232
233 src_configure() {
234         # Bug 508758.
235         replace-flags -O3 -O2
236
237         # We don't want to leak flags onto boot code.
238         export HOST_CCASFLAGS=${CCASFLAGS}
239         export HOST_CFLAGS=${CFLAGS}
240         export HOST_CPPFLAGS=${CPPFLAGS}
241         export HOST_LDFLAGS=${LDFLAGS}
242         unset CCASFLAGS CFLAGS CPPFLAGS LDFLAGS
243
244         use static && HOST_LDFLAGS+=" -static"
245
246         tc-ld-disable-gold #439082 #466536 #526348
247         export TARGET_LDFLAGS="${TARGET_LDFLAGS} ${LDFLAGS}"
248         unset LDFLAGS
249
250         tc-export CC NM OBJCOPY RANLIB STRIP
251         tc-export BUILD_CC # Bug 485592
252
253         # Portage will take care of cleaning up GRUB_PLATFORMS
254         grub_get_platforms
255         grub_do grub_configure
256 }
257
258 src_compile() {
259         # Sandbox bug 404013.
260         use libzfs && addpredict /etc/dfs:/dev/zfs
261
262         grub_do emake
263         use doc && grub_do_once emake -C docs html
264 }
265
266 src_test() {
267         # The qemu dependency is a bit complex.
268         # You will need to adjust QEMU_SOFTMMU_TARGETS to match the cpu/platform.
269         grub_do emake check
270 }
271
272 src_install() {
273         grub_do emake install DESTDIR="${D}" bashcompletiondir="$(get_bashcompdir)"
274         use doc && grub_do_once emake -C docs install-html DESTDIR="${D}"
275
276         einstalldocs
277
278         if use multislot; then
279                 mv "${ED%/}"/usr/share/info/grub{,2}.info || die
280         fi
281
282         insinto /etc/default
283         newins "${FILESDIR}"/grub.default-3 grub
284 }
285
286 pkg_postinst() {
287         elog "For information on how to configure GRUB2 please refer to the guide:"
288         elog "    https://wiki.gentoo.org/wiki/GRUB2_Quick_Start"
289
290         if has_version 'sys-boot/grub:0'; then
291                 elog "A migration guide for GRUB Legacy users is available:"
292                 elog "    https://wiki.gentoo.org/wiki/GRUB2_Migration"
293         fi
294
295         if [[ -z ${REPLACING_VERSIONS} ]]; then
296                 elog
297                 elog "You may consider installing the following optional packages:"
298                 optfeature "Detect other operating systems (grub-mkconfig)" sys-boot/os-prober
299                 optfeature "Create rescue media (grub-mkrescue)" dev-libs/libisoburn
300                 optfeature "Enable RAID device detection" sys-fs/mdadm
301         fi
302 }