add deprecated sys-boot/grub:0
[portage-squeep] / sys-boot / grub / grub-0.97-r18.ebuild
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # XXX: we need to review menu.lst vs grub.conf handling. We've been converting
5 # all systems to grub.conf (and symlinking menu.lst to grub.conf), but
6 # we never updated any of the source code (it still all wants menu.lst),
7 # and there is no indication that upstream is making the transition.
8
9 # If you need to roll a new grub-static distfile, here is how.
10 # - Robin H. Johnson <robbat2@gentoo.org> - 29 Nov 2010
11 # FEATURES='-noauto -noinfo -nodoc -noman -splitdebug nostrip' \
12 # USE='static -ncurses -netboot -custom-cflags' \
13 # PORTAGE_COMPRESS=true GRUB_STATIC_PACKAGE_BUILDING=1 ebuild \
14 # grub-${PVR}.ebuild clean package && \
15 # qtbz2 -s -j ${PKGDIR}/${CAT}/${PF}.tbz2 && \
16 # mv ${PF}.tar.bz2 ${DISTDIR}/grub-static-${PVR}.tar.bz2
17
18 EAPI="6"
19
20 inherit eutils mount-boot toolchain-funcs linux-info flag-o-matic autotools pax-utils
21
22 PATCHVER="1.15" # Should match the revision ideally
23 DESCRIPTION="GNU GRUB Legacy boot loader"
24 HOMEPAGE="https://www.gnu.org/software/grub/"
25 SRC_URI="mirror://gentoo/${P}.tar.gz
26 mirror://gnu-alpha/${PN}/${P}.tar.gz
27 mirror://gentoo/splash.xpm.gz
28 mirror://gentoo/${P}-patches-${PATCHVER}.tar.bz2
29 https://dev.gentoo.org/~whissi/dist/${PN}/${P}-patches-${PATCHVER}.tar.bz2"
30
31 LICENSE="GPL-2"
32 SLOT="0"
33 KEYWORDS="amd64 x86 ~x86-fbsd"
34 IUSE="custom-cflags ncurses netboot static"
35
36 LIB_DEPEND="ncurses? ( >=sys-libs/ncurses-5.9-r3:0[static-libs(+),abi_x86_32(-)] )"
37 RDEPEND="!static? ( ${LIB_DEPEND//[static-libs(+),/=[} )"
38 DEPEND="${RDEPEND}
39 virtual/pkgconfig
40 static? ( ${LIB_DEPEND} )"
41 RDEPEND+=" !sys-boot/grub:2[-multislot]"
42
43 pkg_setup() {
44 case $(tc-arch) in
45 amd64) CONFIG_CHECK='~IA32_EMULATION' check_extra_config ;;
46 esac
47 }
48
49 src_prepare() {
50 # Grub will not handle a kernel larger than EXTENDED_MEMSIZE Mb as
51 # discovered in bug 160801. We can change this, however, using larger values
52 # for this variable means that Grub needs more memory to run and boot. For a
53 # kernel of size N, Grub needs (N+1)*2. Advanced users should set a custom
54 # value in make.conf, it is possible to make kernels ~16Mb in size, but it
55 # needs the kitchen sink built-in.
56 local t="custom"
57 if [[ -z ${GRUB_MAX_KERNEL_SIZE} ]] ; then
58 case $(tc-arch) in
59 amd64) GRUB_MAX_KERNEL_SIZE=9 ;;
60 x86) GRUB_MAX_KERNEL_SIZE=5 ;;
61 esac
62 t="default"
63 fi
64 einfo "Grub will support the ${t} maximum kernel size of ${GRUB_MAX_KERNEL_SIZE} Mb (GRUB_MAX_KERNEL_SIZE)"
65
66 sed -i \
67 -e "/^#define.*EXTENDED_MEMSIZE/s,3,${GRUB_MAX_KERNEL_SIZE},g" \
68 "${S}"/grub/asmstub.c \
69 || die
70
71 # gcc-6 and above doesnt have a '-nopie' option patched in, use upstream's -fno-pie
72 if [[ tc-is-gcc && $(gcc-major-version) -gt 5 ]]; then
73 sed -i 's/-nopie/-fno-pie/' \
74 "${WORKDIR}"/patch/860_all_grub-0.97-pie-r1.patch \
75 || die
76 fi
77
78 EPATCH_SUFFIX="patch" epatch "${WORKDIR}"/patch
79 # bug 564890, 566638
80 epatch "${FILESDIR}"/grub-0.97-Add-esp-to-list-of-clobbered-registers.patch
81 epatch "${FILESDIR}"/grub-0.97-ncurses-pkgconfig.patch
82
83 eapply_user
84
85 rm -f "${S}"/aclocal.m4 # seems to keep bug 418287 away
86 eautoreconf
87 }
88
89 src_configure() {
90 filter-flags -fPIE #168834
91
92 use amd64 && multilib_toolchain_setup x86
93
94 unset BLOCK_SIZE #73499
95
96 ### i686-specific code in the boot loader is a bad idea; disabling to ensure
97 ### at least some compatibility if the hard drive is moved to an older or
98 ### incompatible system.
99
100 # grub-0.95 added -fno-stack-protector detection, to disable ssp for stage2,
101 # but the objcopy's (faulty) test fails if -fstack-protector is default.
102 # create a cache telling configure that objcopy is ok, and add -C to econf
103 # to make use of the cache.
104 #
105 # CFLAGS has to be undefined running econf, else -fno-stack-protector detection fails.
106 # STAGE2_CFLAGS is not allowed to be used on emake command-line, it overwrites
107 # -fno-stack-protector detected by configure, removed from netboot's emake.
108 use custom-cflags || unset CFLAGS
109
110 tc-ld-disable-gold #439082 #466536 #526348
111
112 export grub_cv_prog_objcopy_absolute=yes #79734
113 use static && append-ldflags -static
114
115 if use amd64 && use static ; then
116 if [[ -n ${GRUB_STATIC_PACKAGE_BUILDING} ]] ; then
117 eerror "You have set GRUB_STATIC_PACKAGE_BUILDING. This"
118 eerror "is specifically intended for building the tarballs for the"
119 eerror "grub-static package via USE='static -ncurses'."
120 eerror "All bets are now off."
121 fi
122 fi
123
124 # build the net-bootable grub first, but only if "netboot" is set
125 if use netboot ; then
126 mkdir -p "${WORKDIR}"/netboot
127 pushd "${WORKDIR}"/netboot >/dev/null
128 ECONF_SOURCE=${S} \
129 econf \
130 --libdir=/lib \
131 --datadir=/usr/lib/grub \
132 --exec-prefix=/ \
133 --disable-auto-linux-mem-opt \
134 --enable-diskless \
135 --enable-{3c{5{03,07,09,29,95},90x},cs89x0,davicom,depca,eepro{,100}} \
136 --enable-{epic100,exos205,ni5210,lance,ne2100,ni{50,65}10,natsemi} \
137 --enable-{ne,ns8390,wd,otulip,rtl8139,sis900,sk-g16,smc9000,tiara} \
138 --enable-{tulip,via-rhine,w89c840}
139 popd >/dev/null
140 fi
141
142 # Now build the regular grub
143 # Note that FFS and UFS2 support are broken for now - stage1_5 files too big
144 econf \
145 --libdir=/lib \
146 --datadir=/usr/lib/grub \
147 --exec-prefix=/ \
148 --disable-auto-linux-mem-opt \
149 $(use_with ncurses curses)
150
151 # sanity check due to common failure
152 use ncurses && ! grep -qs "HAVE_LIBCURSES.*1" config.h && die "USE=ncurses but curses not found"
153 }
154
155 src_compile() {
156 use netboot && emake -C "${WORKDIR}"/netboot w89c840_o_CFLAGS="-O"
157 emake
158 }
159
160 src_test() {
161 # non-default block size also give false pass/fails.
162 unset BLOCK_SIZE
163 emake -j1 check
164 }
165
166 src_install() {
167 local _stage2_file="${S}/stage2/stage2"
168 if [[ -f "${_stage2_file}" ]]; then
169 local _stage2_filesize=$(stat -c '%s' "${_stage2_file}" 2>/dev/null)
170 if [[ -z "${_stage2_filesize}" ]]; then
171 ewarn "Sanity check skipped -- 'stat' returned nothing"
172 elif [[ "${_stage2_filesize}" -gt 1000000 ]]; then
173 eerror "Sanity check failed: stage2 (${_stage2_file}) is larger than 1MB (${_stage2_filesize} bytes)!"
174 eerror "Please check your CFLAGS and/or file a bug report at https://bugs.gentoo.org."
175 die "stage2 sanity check failed"
176 else
177 einfo "stage2 sanity check passed"
178 fi
179 else
180 ewarn "Sanity check skipped -- no stage2 found"
181 fi
182
183 default
184 if use netboot ; then
185 exeinto /usr/lib/grub/${CHOST}
186 doexe "${WORKDIR}"/netboot/stage2/{nbgrub,pxegrub}
187 newexe "${WORKDIR}"/netboot/stage2/stage2 stage2.netboot
188 fi
189
190 pax-mark -m "${D}"/sbin/grub #330745
191
192 newdoc docs/menu.lst grub.conf.sample
193 dodoc "${FILESDIR}"/grub.conf.gentoo
194
195 [[ -n ${GRUB_STATIC_PACKAGE_BUILDING} ]] && \
196 mv "${D}"/usr/share/doc/{${PF},grub-static-${PF/grub-}}
197
198 insinto /usr/share/grub
199 doins "${DISTDIR}"/splash.xpm.gz
200 }
201
202 setup_boot_dir() {
203 local boot_dir=$1
204 local dir=${boot_dir}
205
206 mkdir -p "${dir}"
207 [[ ! -L ${dir}/boot ]] && ln -s . "${dir}/boot"
208 dir="${dir}/grub"
209 if [[ ! -e ${dir} ]] ; then
210 mkdir "${dir}" || die
211 fi
212
213 # change menu.lst to grub.conf
214 if [[ ! -e ${dir}/grub.conf ]] && [[ -e ${dir}/menu.lst ]] ; then
215 mv -f "${dir}"/menu.lst "${dir}"/grub.conf
216 ewarn "*** IMPORTANT NOTE: menu.lst has been renamed to grub.conf"
217 echo
218 fi
219
220 if [[ ! -e ${dir}/menu.lst ]]; then
221 einfo "Linking from new grub.conf name to menu.lst"
222 ln -snf grub.conf "${dir}"/menu.lst
223 fi
224
225 if [[ -e ${dir}/stage2 ]] ; then
226 mv "${dir}"/stage2{,.old}
227 ewarn "*** IMPORTANT NOTE: you must run grub and install"
228 ewarn "the new version's stage1 to your MBR. Until you do,"
229 ewarn "stage1 and stage2 will still be the old version, but"
230 ewarn "later stages will be the new version, which could"
231 ewarn "cause problems such as an unbootable system."
232 ewarn
233 ewarn "This means you must use either grub-install or perform"
234 ewarn "root/setup manually."
235 ewarn
236 ewarn "For more help, see the wiki:"
237 ewarn "https://wiki.gentoo.org/wiki/GRUB"
238 echo
239 fi
240
241 einfo "Copying files from /lib/grub and /usr/share/grub to ${dir}"
242 for x in \
243 "${ROOT}"/lib*/grub/*/* \
244 "${ROOT}"/usr/share/grub/* ; do
245 [[ -f ${x} ]] && cp -p "${x}" "${dir}"/
246 done
247
248 if [[ ! -e ${dir}/grub.conf ]] ; then
249 s="${ROOT}/usr/share/doc/${PF}/grub.conf.gentoo"
250 [[ -e "${s}" ]] && cat "${s}" >${dir}/grub.conf
251 [[ -e "${s}.gz" ]] && zcat "${s}.gz" >${dir}/grub.conf
252 [[ -e "${s}.bz2" ]] && bzcat "${s}.bz2" >${dir}/grub.conf
253 fi
254
255 # Per bug 218599, we support grub.conf.install for users that want to run a
256 # specific set of Grub setup commands rather than the default ones.
257 grub_config=${dir}/grub.conf.install
258 [[ -e ${grub_config} ]] || grub_config=${dir}/grub.conf
259 if [[ -e ${grub_config} ]] ; then
260 egrep \
261 -v '^[[:space:]]*(#|$|default|fallback|initrd|password|splashimage|timeout|title)' \
262 "${grub_config}" | \
263 /sbin/grub --batch \
264 --device-map="${dir}"/device.map \
265 > /dev/null
266 fi
267
268 # the grub default commands silently piss themselves if
269 # the default file does not exist ahead of time
270 if [[ ! -e ${dir}/default ]] ; then
271 grub-set-default --root-directory="${boot_dir}" default
272 fi
273 einfo "Grub has been installed to ${boot_dir} successfully."
274 }
275
276 pkg_postinst() {
277 mount-boot_mount_boot_partition
278
279 if [[ -n ${DONT_MOUNT_BOOT} ]]; then
280 elog "WARNING: you have DONT_MOUNT_BOOT in effect, so you must apply"
281 elog "the following instructions for your /boot!"
282 elog "Neglecting to do so may cause your system to fail to boot!"
283 elog
284 else
285 setup_boot_dir "${ROOT}"/boot
286 # Trailing output because if this is run from pkg_postinst, it gets mixed into
287 # the other output.
288 einfo ""
289 fi
290 elog "To interactively install grub files to another device such as a USB"
291 elog "stick, just run the following and specify the directory as prompted:"
292 elog " emerge --config =${PF}"
293 elog "Alternately, you can export GRUB_ALT_INSTALLDIR=/path/to/use to tell"
294 elog "grub where to install in a non-interactive way."
295
296 # needs to be after we call setup_boot_dir
297 mount-boot_pkg_postinst
298 }
299
300 pkg_config() {
301 local dir
302 if [ ! -d "${GRUB_ALT_INSTALLDIR}" ]; then
303 einfo "Enter the directory where you want to setup grub:"
304 read dir
305 else
306 dir="${GRUB_ALT_INSTALLDIR}"
307 fi
308 setup_boot_dir "${dir}"
309 }