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