91
|
1 # Copyright 1999-2008 Gentoo Foundation
|
|
2 # Distributed under the terms of the GNU General Public License v2
|
|
3 # $Header: /var/cvsroot/gentoo-x86/sys-boot/grub/grub-0.97-r8.ebuild,v 1.1 2008/11/06 01:28:56 robbat2 Exp $
|
|
4
|
|
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.
|
|
9
|
|
10 inherit mount-boot eutils flag-o-matic toolchain-funcs autotools
|
|
11
|
|
12 PATCHVER="1.8" # Should match the revision ideally
|
|
13 DESCRIPTION="GNU GRUB Legacy boot loader"
|
|
14 HOMEPAGE="http://www.gnu.org/software/grub/"
|
|
15 SRC_URI="mirror://gentoo/${P}.tar.gz
|
|
16 ftp://alpha.gnu.org/gnu/${PN}/${P}.tar.gz
|
|
17 mirror://gentoo/splash.xpm.gz
|
|
18 mirror://gentoo/${P}-patches-${PATCHVER}.tar.bz2"
|
|
19
|
|
20 LICENSE="GPL-2"
|
|
21 SLOT="0"
|
|
22 KEYWORDS="~amd64 ~x86 ~x86-fbsd"
|
|
23 IUSE="custom-cflags ncurses netboot static"
|
|
24
|
|
25 DEPEND="ncurses? (
|
|
26 >=sys-libs/ncurses-5.2-r5
|
|
27 amd64? ( app-emulation/emul-linux-x86-baselibs )
|
|
28 )"
|
|
29 PROVIDE="virtual/bootloader"
|
|
30
|
|
31 src_unpack() {
|
|
32 unpack ${A}
|
|
33 cd "${S}"
|
|
34
|
|
35 # patch breaks booting for some people #111885
|
|
36 rm "${WORKDIR}"/patch/400_*
|
|
37
|
|
38 # Grub will not handle a kernel larger than EXTENDED_MEMSIZE Mb as
|
|
39 # discovered in bug 160801. We can change this, however, using larger values
|
|
40 # for this variable means that Grub needs more memory to run and boot. For a
|
|
41 # kernel of size N, Grub needs (N+1)*2. Advanced users should set a custom
|
|
42 # value in make.conf, it is possible to make kernels ~16Mb in size, but it
|
|
43 # needs the kitchen sink built-in.
|
|
44 local t="custom"
|
|
45 if [[ -z ${GRUB_MAX_KERNEL_SIZE} ]] ; then
|
|
46 case $(tc-arch) in
|
|
47 amd64) GRUB_MAX_KERNEL_SIZE=7 ;;
|
|
48 x86) GRUB_MAX_KERNEL_SIZE=3 ;;
|
|
49 esac
|
|
50 t="default"
|
|
51 fi
|
|
52 einfo "Grub will support the ${t} maximum kernel size of ${GRUB_MAX_KERNEL_SIZE} Mb (GRUB_MAX_KERNEL_SIZE)"
|
|
53
|
|
54 sed -i \
|
|
55 -e "/^#define.*EXTENDED_MEMSIZE/s,3,${GRUB_MAX_KERNEL_SIZE},g" \
|
|
56 "${S}"/grub/asmstub.c \
|
|
57 || die "Failed to hack memory size"
|
|
58
|
|
59 if [[ -n ${PATCHVER} ]] ; then
|
|
60 EPATCH_SUFFIX="patch"
|
|
61 epatch "${WORKDIR}"/patch
|
|
62 epatch "${FILESDIR}/grub-0.97-ext4extents.patch"
|
|
63 eautoreconf
|
|
64 fi
|
|
65 }
|
|
66
|
|
67 src_compile() {
|
|
68 filter-flags -fPIE #168834
|
|
69
|
|
70 use amd64 && multilib_toolchain_setup x86
|
|
71
|
|
72 unset BLOCK_SIZE #73499
|
|
73
|
|
74 ### i686-specific code in the boot loader is a bad idea; disabling to ensure
|
|
75 ### at least some compatibility if the hard drive is moved to an older or
|
|
76 ### incompatible system.
|
|
77
|
|
78 # grub-0.95 added -fno-stack-protector detection, to disable ssp for stage2,
|
|
79 # but the objcopy's (faulty) test fails if -fstack-protector is default.
|
|
80 # create a cache telling configure that objcopy is ok, and add -C to econf
|
|
81 # to make use of the cache.
|
|
82 #
|
|
83 # CFLAGS has to be undefined running econf, else -fno-stack-protector detection fails.
|
|
84 # STAGE2_CFLAGS is not allowed to be used on emake command-line, it overwrites
|
|
85 # -fno-stack-protector detected by configure, removed from netboot's emake.
|
|
86 use custom-cflags || unset CFLAGS
|
|
87
|
|
88 export grub_cv_prog_objcopy_absolute=yes #79734
|
|
89 use static && append-ldflags -static
|
|
90
|
|
91 # Per bug 216625, the emul packages do not provide .a libs for performing
|
|
92 # suitable static linking
|
|
93 if use amd64 && use static ; then
|
|
94 if [ -z "${GRUB_STATIC_PACKAGE_BUILDING}" ]; then
|
|
95 die "You must use the grub-static package if you want a static Grub on amd64!"
|
|
96 else
|
|
97 eerror "You have set GRUB_STATIC_PACKAGE_BUILDING. This"
|
|
98 eerror "is specifically intended for building the tarballs for the"
|
|
99 eerror "grub-static package via USE='static -ncurses'."
|
|
100 eerror "All bets are now off."
|
|
101 ebeep 10
|
|
102 fi
|
|
103 fi
|
|
104
|
|
105 # build the net-bootable grub first, but only if "netboot" is set
|
|
106 if use netboot ; then
|
|
107 econf \
|
|
108 --libdir=/lib \
|
|
109 --datadir=/usr/lib/grub \
|
|
110 --exec-prefix=/ \
|
|
111 --disable-auto-linux-mem-opt \
|
|
112 --enable-diskless \
|
|
113 --enable-{3c{5{03,07,09,29,95},90x},cs89x0,davicom,depca,eepro{,100}} \
|
|
114 --enable-{epic100,exos205,ni5210,lance,ne2100,ni{50,65}10,natsemi} \
|
|
115 --enable-{ne,ns8390,wd,otulip,rtl8139,sis900,sk-g16,smc9000,tiara} \
|
|
116 --enable-{tulip,via-rhine,w89c840} || die "netboot econf failed"
|
|
117
|
|
118 emake w89c840_o_CFLAGS="-O" || die "making netboot stuff"
|
|
119
|
|
120 mv -f stage2/{nbgrub,pxegrub} "${S}"/
|
|
121 mv -f stage2/stage2 stage2/stage2.netboot
|
|
122
|
|
123 make clean || die "make clean failed"
|
|
124 fi
|
|
125
|
|
126 # Now build the regular grub
|
|
127 # Note that FFS and UFS2 support are broken for now - stage1_5 files too big
|
|
128 econf \
|
|
129 --libdir=/lib \
|
|
130 --datadir=/usr/lib/grub \
|
|
131 --exec-prefix=/ \
|
|
132 --disable-auto-linux-mem-opt \
|
|
133 $(use_with ncurses curses) \
|
|
134 || die "econf failed"
|
|
135
|
|
136 # sanity check due to common failure
|
|
137 use ncurses && ! grep -qs "HAVE_LIBCURSES.*1" config.h && die "USE=ncurses but curses not found"
|
|
138
|
|
139 emake || die "making regular stuff"
|
|
140 }
|
|
141
|
|
142 src_test() {
|
|
143 # non-default block size also give false pass/fails.
|
|
144 unset BLOCK_SIZE
|
|
145 make check || die "make check failed"
|
|
146 }
|
|
147
|
|
148 src_install() {
|
|
149 emake DESTDIR="${D}" install || die
|
|
150 if use netboot ; then
|
|
151 exeinto /usr/lib/grub/${CHOST}
|
|
152 doexe nbgrub pxegrub stage2/stage2.netboot || die "netboot install"
|
|
153 fi
|
|
154
|
|
155 dodoc AUTHORS BUGS ChangeLog NEWS README THANKS TODO
|
|
156 newdoc docs/menu.lst grub.conf.sample
|
|
157 dodoc "${FILESDIR}"/grub.conf.gentoo
|
|
158 prepalldocs
|
|
159
|
|
160 [ -n "${GRUB_STATIC_PACKAGE_BUILDING}" ] && \
|
|
161 mv \
|
|
162 "${D}"/usr/share/doc/${PF} \
|
|
163 "${D}"/usr/share/doc/grub-static-${PF/grub-}
|
|
164
|
|
165 insinto /usr/share/grub
|
|
166 doins "${DISTDIR}"/splash.xpm.gz
|
|
167 }
|
|
168
|
|
169 setup_boot_dir() {
|
|
170 local boot_dir=$1
|
|
171 local dir=${boot_dir}
|
|
172
|
|
173 [[ ! -e ${dir} ]] && die "${dir} does not exist!"
|
|
174 [[ ! -L ${dir}/boot ]] && ln -s . "${dir}/boot"
|
|
175 dir="${dir}/grub"
|
|
176 if [[ ! -e ${dir} ]] ; then
|
|
177 mkdir "${dir}" || die "${dir} does not exist!"
|
|
178 fi
|
|
179
|
|
180 # change menu.lst to grub.conf
|
|
181 if [[ ! -e ${dir}/grub.conf ]] && [[ -e ${dir}/menu.lst ]] ; then
|
|
182 mv -f "${dir}"/menu.lst "${dir}"/grub.conf
|
|
183 ewarn
|
|
184 ewarn "*** IMPORTANT NOTE: menu.lst has been renamed to grub.conf"
|
|
185 ewarn
|
|
186 fi
|
|
187
|
|
188 if [[ ! -e ${dir}/menu.lst ]]; then
|
|
189 einfo "Linking from new grub.conf name to menu.lst"
|
|
190 ln -snf grub.conf "${dir}"/menu.lst
|
|
191 fi
|
|
192
|
|
193 if [[ -e ${dir}/stage2 ]] ; then
|
|
194 mv "${dir}"/stage2{,.old}
|
|
195 ewarn "*** IMPORTANT NOTE: you must run grub and install"
|
|
196 ewarn "the new version's stage1 to your MBR. Until you do,"
|
|
197 ewarn "stage1 and stage2 will still be the old version, but"
|
|
198 ewarn "later stages will be the new version, which could"
|
|
199 ewarn "cause problems such as an unbootable system."
|
|
200 ewarn "This means you must use either grub-install or perform"
|
|
201 ewarn "root/setup manually! For more help, see the handbook:"
|
|
202 ewarn "http://www.gentoo.org/doc/en/handbook/handbook-${ARCH}.xml?part=1&chap=10#grub-install-auto"
|
|
203 ebeep
|
|
204 fi
|
|
205
|
|
206 einfo "Copying files from /lib/grub, /usr/lib/grub and /usr/share/grub to ${dir}"
|
|
207 for x in \
|
|
208 "${ROOT}"/lib*/grub/*/* \
|
|
209 "${ROOT}"/usr/lib*/grub/*/* \
|
|
210 "${ROOT}"/usr/share/grub/* ; do
|
|
211 [[ -f ${x} ]] && cp -p "${x}" "${dir}"/
|
|
212 done
|
|
213
|
|
214 if [[ ! -e ${dir}/grub.conf ]] ; then
|
|
215 s="${ROOT}/usr/share/doc/${PF}/grub.conf.gentoo"
|
|
216 [[ -e "${s}" ]] && cat "${s}" >${dir}/grub.conf
|
|
217 [[ -e "${s}.gz" ]] && zcat "${s}.gz" >${dir}/grub.conf
|
|
218 [[ -e "${s}.bz2" ]] && bzcat "${s}.bz2" >${dir}/grub.conf
|
|
219 fi
|
|
220
|
|
221 # Per bug 218599, we support grub.conf.install for users that want to run a
|
|
222 # specific set of Grub setup commands rather than the default ones.
|
|
223 grub_config=${dir}/grub.conf.install
|
|
224 [[ -e ${grub_config} ]] || grub_config=${dir}/grub.conf
|
|
225 if [[ -e ${grub_config} ]] ; then
|
|
226 egrep \
|
|
227 -v '^[[:space:]]*(#|$|default|fallback|initrd|password|splashimage|timeout|title)' \
|
|
228 "${grub_config}" | \
|
|
229 /sbin/grub --batch \
|
|
230 --device-map="${dir}"/device.map \
|
|
231 > /dev/null
|
|
232 fi
|
|
233
|
|
234 # the grub default commands silently piss themselves if
|
|
235 # the default file does not exist ahead of time
|
|
236 if [[ ! -e ${dir}/default ]] ; then
|
|
237 grub-set-default --root-directory="${boot_dir}" default
|
|
238 fi
|
|
239 einfo "Grub has been installed to ${boot_dir} successfully."
|
|
240 }
|
|
241
|
|
242 pkg_postinst() {
|
|
243 if [[ -n ${DONT_MOUNT_BOOT} ]]; then
|
|
244 elog "WARNING: you have DONT_MOUNT_BOOT in effect, so you must apply"
|
|
245 elog "the following instructions for your /boot!"
|
|
246 elog "Neglecting to do so may cause your system to fail to boot!"
|
|
247 elog
|
|
248 else
|
|
249 setup_boot_dir "${ROOT}"/boot
|
|
250 # Trailing output because if this is run from pkg_postinst, it gets mixed into
|
|
251 # the other output.
|
|
252 einfo ""
|
|
253 fi
|
|
254 elog "To interactively install grub files to another device such as a USB"
|
|
255 elog "stick, just run the following and specify the directory as prompted:"
|
|
256 elog " emerge --config =${PF}"
|
|
257 elog "Alternately, you can export GRUB_ALT_INSTALLDIR=/path/to/use to tell"
|
|
258 elog "grub where to install in a non-interactive way."
|
|
259
|
|
260 }
|
|
261
|
|
262 pkg_config() {
|
|
263 local dir
|
|
264 if [ ! -d "${GRUB_ALT_INSTALLDIR}" ]; then
|
|
265 einfo "Enter the directory where you want to setup grub:"
|
|
266 read dir
|
|
267 else
|
|
268 dir="${GRUB_ALT_INSTALLDIR}"
|
|
269 fi
|
|
270 setup_boot_dir "${dir}"
|
|
271 }
|