File grub2.spec of Package grub2

# spec file for package grub2 (Version 1.98)
# Copyright (c) 2010 SUSE LINUX Products GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

Name:           grub2
%ifarch x86_64
BuildRequires:  freetype2-devel-32bit gcc-32bit glibc-devel-32bit libncurses5-32bit libusb-1_0-devel-32bit ncurses-devel-32bit
BuildRequires:  freetype2-devel gcc glibc-devel libncurses5 libusb-1_0-devel ncurses-devel
BuildRequires:  bison flex ruby

# Modules always contain just 32-bit code
%define _libdir %{_exec_prefix}/lib

# 64-bit x86-64 machines use 32-bit boot loader
# (We cannot just redefine _target_cpu, as we'd get i386.rpm packages then)
%ifarch x86_64
%define _target_platform i386-%{_vendor}-%{_target_os}%{?_gnu}
Version:        1.98
Release:        9
Summary:        Bootloader with support for Linux, Multiboot and more
Group:          System/Boot
License:        GPLv3+
Source1:        90_persistent
Source2:        grub.default
Source3:        README.openSUSE
Source4:        grub2.rpmlintrc
Patch0:         grub-1.95-grubdir.patch
Patch2:         grub2-linux.patch
Patch3:         gccwarn.patch
Patch4:         grub-1.98-follow-dev-mapper-symlinks.patch
PreReq:         perl-Bootloader
Requires:       gettext-runtime

BuildRoot:      %{_tmppath}/%{name}-%{version}-build

# TODO: ppc
ExclusiveArch:  %{ix86} x86_64

This is the second version of the GRUB (Grand Unified Bootloader),
a highly configurable and customizable bootloader with modular
architecture.  It support rich scale of kernel formats, file systems,
computer architectures and hardware devices.

PLEASE NOTE: This is a development snapshot, and as such will not
replace grub if you install it, but will be merely added as another
kernel to your existing GRUB menu. Do not replace GRUB (grub package)
with it unless you know what are you doing. Refer to README.openSUSE
file that is part of this package's documentation for more information.

%setup -q -n grub-%{version}
%patch0 -p0 -b .grubdir
%patch2 -p0 -b .linux
%patch3 -p0 -b .gccwarn
%patch4 -p1 -b .dev-mapper

cp %{SOURCE3} .

# -static is needed so that autoconf script is able to link
# test that looks for _start symbol on 64 bit platforms
%configure TARGET_LDFLAGS=-static       \
        --with-platform=pc              \
        --enable-grub-emu-usb           \



# Script that makes part of grub.cfg persist across updates
install -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/grub.d/

# Ghost config file
install -d $RPM_BUILD_ROOT/boot/%{name}
touch $RPM_BUILD_ROOT/boot/%{name}/grub.cfg
ln -s ../boot/%{name}/grub.cfg $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.cfg

# XXX: Remove for now, should be renamed to
rm $RPM_BUILD_ROOT/%{_infodir}/*
# Remove devel files
rm $RPM_BUILD_ROOT/%{_libdir}/%{name}/*/*.h

# Defaults
install -m 644 -D %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/default/grub
%find_lang grub

mkdir -p /boot/%{name}/ 2>/dev/null || true
# Create or reuse one from GRUB Legacy
if [ ! -e /boot/%{name}/ ] ; then
  cp -u /boot/grub/ /boot/%{name}/ 2>/dev/null ||
if [ -e /boot/%{name}/ ]; then
  # Determine the partition with /boot
  BOOT_PARTITION=$(df -h /boot |(read; awk '{print $1; exit}'))
  # Generate core.img, but don't let it be installed in boot sector
  %{name}-install --grub-setup=/bin/true $BOOT_PARTITION || true
  exec >/dev/null 2>&1
  # Remove stale menu.lst entries
  /sbin/update-bootloader --remove --image /boot/%{name}/core.img --name="GNU GRUB 2" || true
  # Add core.img as multiboot kernel to GRUB Legacy menu
  /sbin/update-bootloader --add --image /boot/%{name}/core.img --name="GNU GRUB 2" || true
  /sbin/update-bootloader --refresh || true

exec >/dev/null
if [ -e /boot/%{name}/core.img ] ; then
  /sbin/update-bootloader --remove --image /boot/%{name}/core.img --name="GNU GRUB 2"
  /sbin/update-bootloader --refresh
  ## XXX Ugly
  rm -f /boot/%{name}/*.mod
  rm -f /boot/%{name}/*.img
  rm -f /boot/%{name}/*.lst
  rm -f /boot/%{name}/

#%triggerin -- kernel, kernel-PAE
#exec >/dev/null 2>&1
## Generate grub.cfg
#%triggerun -- kernel, kernel-PAE
#exec >/dev/null 2>&1
## Generate grub.cfg

%files -f grub.lang
%dir %{_sysconfdir}/grub.d
%config %{_sysconfdir}/grub.d/??_*
%config %{_sysconfdir}/default/grub
%dir /boot/%{name}
# Actually, this is replaced by update-grub from scriptlets,
# but it takes care of modified persistent part
%config(noreplace) /boot/%{name}/grub.cfg
#%exclude %{_mandir}