1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # XXX: we need to review menu.lst vs grub.conf handling. We've been converting
6 # all systems to grub.conf (and symlinking menu.lst to grub.conf), but
7 # we never updated any of the source code (it still all wants menu.lst),
8 # and there is no indication that upstream is making the transition.
10 # If you need to roll a new grub-static distfile, here is how.
11 # - Robin H. Johnson <robbat2@gentoo.org> - 29 Nov 2010
12 # FEATURES='-noauto -noinfo -nodoc -noman -splitdebug nostrip' \
13 # USE='static -ncurses -netboot -custom-cflags' \
14 # PORTAGE_COMPRESS=true GRUB_STATIC_PACKAGE_BUILDING=1 ebuild \
15 # grub-${PVR}.ebuild clean package && \
16 # qtbz2 -s -j ${PKGDIR}/${CAT}/${PF}.tbz2 && \
17 # mv ${PF}.tar.bz2 ${DISTDIR}/grub-static-${PVR}.tar.bz2
21 inherit eutils mount-boot toolchain-funcs linux-info flag-o-matic autotools pax-utils multiprocessing
23 PATCHVER="1.14" # Should match the revision ideally
24 DESCRIPTION="GNU GRUB Legacy boot loader"
25 HOMEPAGE="http://www.gnu.org/software/grub/"
26 SRC_URI="mirror://gentoo/${P}.tar.gz
27 mirror://gnu-alpha/${PN}/${P}.tar.gz
28 mirror://gentoo/splash.xpm.gz
29 mirror://gentoo/${P}-patches-${PATCHVER}.tar.bz2"
33 KEYWORDS="amd64 x86 ~x86-fbsd"
34 IUSE="custom-cflags ncurses netboot static"
36 LIB_DEPEND="ncurses? (
37 >=sys-libs/ncurses-5.9-r3[static-libs(+)]
38 amd64? ( >=sys-libs/ncurses-5.9-r3[abi_x86_32(-)] )
40 RDEPEND="!static? ( ${LIB_DEPEND//\[static-libs(+)\]/} )"
42 static? ( ${LIB_DEPEND} )"
46 amd64) CONFIG_CHECK='~IA32_EMULATION' check_extra_config ;;
51 # Grub will not handle a kernel larger than EXTENDED_MEMSIZE Mb as
52 # discovered in bug 160801. We can change this, however, using larger values
53 # for this variable means that Grub needs more memory to run and boot. For a
54 # kernel of size N, Grub needs (N+1)*2. Advanced users should set a custom
55 # value in make.conf, it is possible to make kernels ~16Mb in size, but it
56 # needs the kitchen sink built-in.
58 if [[ -z ${GRUB_MAX_KERNEL_SIZE} ]] ; then
60 amd64) GRUB_MAX_KERNEL_SIZE=9 ;;
61 x86) GRUB_MAX_KERNEL_SIZE=5 ;;
65 einfo "Grub will support the ${t} maximum kernel size of ${GRUB_MAX_KERNEL_SIZE} Mb (GRUB_MAX_KERNEL_SIZE)"
68 -e "/^#define.*EXTENDED_MEMSIZE/s,3,${GRUB_MAX_KERNEL_SIZE},g" \
69 "${S}"/grub/asmstub.c \
72 EPATCH_SUFFIX="patch" epatch "${WORKDIR}"/patch
73 rm -f "${S}"/aclocal.m4 # seems to keep bug 418287 away
78 filter-flags -fPIE #168834
80 use amd64 && multilib_toolchain_setup x86
82 unset BLOCK_SIZE #73499
84 ### i686-specific code in the boot loader is a bad idea; disabling to ensure
85 ### at least some compatibility if the hard drive is moved to an older or
86 ### incompatible system.
88 # grub-0.95 added -fno-stack-protector detection, to disable ssp for stage2,
89 # but the objcopy's (faulty) test fails if -fstack-protector is default.
90 # create a cache telling configure that objcopy is ok, and add -C to econf
91 # to make use of the cache.
93 # CFLAGS has to be undefined running econf, else -fno-stack-protector detection fails.
94 # STAGE2_CFLAGS is not allowed to be used on emake command-line, it overwrites
95 # -fno-stack-protector detected by configure, removed from netboot's emake.
96 use custom-cflags || unset CFLAGS
98 tc-ld-disable-gold #439082 #466536 #526348
100 export grub_cv_prog_objcopy_absolute=yes #79734
101 use static && append-ldflags -static
103 if use amd64 && use static ; then
104 if [[ -n ${GRUB_STATIC_PACKAGE_BUILDING} ]] ; then
105 eerror "You have set GRUB_STATIC_PACKAGE_BUILDING. This"
106 eerror "is specifically intended for building the tarballs for the"
107 eerror "grub-static package via USE='static -ncurses'."
108 eerror "All bets are now off."
114 # build the net-bootable grub first, but only if "netboot" is set
115 if use netboot ; then
118 mkdir -p "${WORKDIR}"/netboot
119 pushd "${WORKDIR}"/netboot >/dev/null
123 --datadir=/usr/lib/grub \
125 --disable-auto-linux-mem-opt \
127 --enable-{3c{5{03,07,09,29,95},90x},cs89x0,davicom,depca,eepro{,100}} \
128 --enable-{epic100,exos205,ni5210,lance,ne2100,ni{50,65}10,natsemi} \
129 --enable-{ne,ns8390,wd,otulip,rtl8139,sis900,sk-g16,smc9000,tiara} \
130 --enable-{tulip,via-rhine,w89c840}
136 # Now build the regular grub
137 # Note that FFS and UFS2 support are broken for now - stage1_5 files too big
140 --datadir=/usr/lib/grub \
142 --disable-auto-linux-mem-opt \
143 $(use_with ncurses curses)
145 # sanity check due to common failure
146 use ncurses && ! grep -qs "HAVE_LIBCURSES.*1" config.h && die "USE=ncurses but curses not found"
152 use netboot && emake -C "${WORKDIR}"/netboot w89c840_o_CFLAGS="-O"
157 # non-default block size also give false pass/fails.
164 if use netboot ; then
165 exeinto /usr/lib/grub/${CHOST}
166 doexe "${WORKDIR}"/netboot/stage2/{nbgrub,pxegrub}
167 newexe "${WORKDIR}"/netboot/stage2/stage2 stage2.netboot
170 pax-mark -m "${D}"/sbin/grub #330745
172 newdoc docs/menu.lst grub.conf.sample
173 dodoc "${FILESDIR}"/grub.conf.gentoo
175 [[ -n ${GRUB_STATIC_PACKAGE_BUILDING} ]] && \
176 mv "${D}"/usr/share/doc/{${PF},grub-static-${PF/grub-}}
178 insinto /usr/share/grub
179 doins "${DISTDIR}"/splash.xpm.gz
184 local dir=${boot_dir}
187 [[ ! -L ${dir}/boot ]] && ln -s . "${dir}/boot"
189 if [[ ! -e ${dir} ]] ; then
190 mkdir "${dir}" || die
193 # change menu.lst to grub.conf
194 if [[ ! -e ${dir}/grub.conf ]] && [[ -e ${dir}/menu.lst ]] ; then
195 mv -f "${dir}"/menu.lst "${dir}"/grub.conf
196 ewarn "*** IMPORTANT NOTE: menu.lst has been renamed to grub.conf"
200 if [[ ! -e ${dir}/menu.lst ]]; then
201 einfo "Linking from new grub.conf name to menu.lst"
202 ln -snf grub.conf "${dir}"/menu.lst
205 if [[ -e ${dir}/stage2 ]] ; then
206 mv "${dir}"/stage2{,.old}
207 ewarn "*** IMPORTANT NOTE: you must run grub and install"
208 ewarn "the new version's stage1 to your MBR. Until you do,"
209 ewarn "stage1 and stage2 will still be the old version, but"
210 ewarn "later stages will be the new version, which could"
211 ewarn "cause problems such as an unbootable system."
213 ewarn "This means you must use either grub-install or perform"
214 ewarn "root/setup manually."
216 ewarn "For more help, see the handbook:"
217 ewarn "https://www.gentoo.org/doc/en/handbook/handbook-${ARCH}.xml?part=1&chap=10#grub-install-auto"
221 einfo "Copying files from /lib/grub and /usr/share/grub to ${dir}"
223 "${ROOT}"/lib*/grub/*/* \
224 "${ROOT}"/usr/share/grub/* ; do
225 [[ -f ${x} ]] && cp -p "${x}" "${dir}"/
228 if [[ ! -e ${dir}/grub.conf ]] ; then
229 s="${ROOT}/usr/share/doc/${PF}/grub.conf.gentoo"
230 [[ -e "${s}" ]] && cat "${s}" >${dir}/grub.conf
231 [[ -e "${s}.gz" ]] && zcat "${s}.gz" >${dir}/grub.conf
232 [[ -e "${s}.bz2" ]] && bzcat "${s}.bz2" >${dir}/grub.conf
235 # Per bug 218599, we support grub.conf.install for users that want to run a
236 # specific set of Grub setup commands rather than the default ones.
237 grub_config=${dir}/grub.conf.install
238 [[ -e ${grub_config} ]] || grub_config=${dir}/grub.conf
239 if [[ -e ${grub_config} ]] ; then
241 -v '^[[:space:]]*(#|$|default|fallback|initrd|password|splashimage|timeout|title)' \
244 --device-map="${dir}"/device.map \
248 # the grub default commands silently piss themselves if
249 # the default file does not exist ahead of time
250 if [[ ! -e ${dir}/default ]] ; then
251 grub-set-default --root-directory="${boot_dir}" default
253 einfo "Grub has been installed to ${boot_dir} successfully."
257 mount-boot_mount_boot_partition
259 if [[ -n ${DONT_MOUNT_BOOT} ]]; then
260 elog "WARNING: you have DONT_MOUNT_BOOT in effect, so you must apply"
261 elog "the following instructions for your /boot!"
262 elog "Neglecting to do so may cause your system to fail to boot!"
265 setup_boot_dir "${ROOT}"/boot
266 # Trailing output because if this is run from pkg_postinst, it gets mixed into
270 elog "To interactively install grub files to another device such as a USB"
271 elog "stick, just run the following and specify the directory as prompted:"
272 elog " emerge --config =${PF}"
273 elog "Alternately, you can export GRUB_ALT_INSTALLDIR=/path/to/use to tell"
274 elog "grub where to install in a non-interactive way."
276 # needs to be after we call setup_boot_dir
277 mount-boot_pkg_postinst
282 if [ ! -d "${GRUB_ALT_INSTALLDIR}" ]; then
283 einfo "Enter the directory where you want to setup grub:"
286 dir="${GRUB_ALT_INSTALLDIR}"
288 setup_boot_dir "${dir}"