LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File grub2.spec of Package grub2 (Project home:Ledest:bashisms)

#
# spec file for package grub2
#
# Copyright (c) 2014 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 http://bugs.opensuse.org/
#


# needssslcertforbuild

Name:           grub2
%ifarch x86_64 ppc64
BuildRequires:  gcc-32bit
BuildRequires:  glibc-32bit
BuildRequires:  glibc-devel-32bit
%else
BuildRequires:  gcc
BuildRequires:  glibc-devel
%ifarch s390x
BuildRequires:  glibc-static
%endif
%endif
BuildRequires:  automake
BuildRequires:  bison
BuildRequires:  dejavu-fonts
BuildRequires:  device-mapper-devel
BuildRequires:  fdupes
BuildRequires:  flex
BuildRequires:  freetype2-devel
BuildRequires:  fuse-devel
%if 0%{?suse_version} >= 1140
BuildRequires:  gnu-unifont
%endif
BuildRequires:  help2man
BuildRequires:  xz
%if 0%{?suse_version} >= 1210
BuildRequires:  makeinfo
%else
BuildRequires:  texinfo
%endif
BuildRequires:  python
BuildRequires:  xz-devel
%ifarch x86_64
%if 0%{?suse_version} >= 1230 || 0%{?suse_version} == 1110
BuildRequires:  openssl >= 0.9.8
BuildRequires:  pesign-obs-integration
%endif
BuildRequires:  xen-devel
%endif

# Modules code is dynamically loaded and collected from a _fixed_ path.
%define _libdir %{_exec_prefix}/lib

%ifarch ppc ppc64 ppc64le
%define grubcpu powerpc
%define platform ieee1275
%endif

%ifarch %{ix86} x86_64
%define grubcpu i386
%define platform pc
%endif

%ifarch s390x
%define grubcpu s390x
%define platform emu
%endif

%ifarch %{arm}
%define grubcpu arm
%define platform uboot
%endif

%define grubarch %{grubcpu}-%{platform}

# build efi bootloader on some platforms only:
%if ! 0%{?efi:1}
%global efi %{ix86} x86_64 ia64 aarch64 %{arm}
%endif
%ifarch aarch64
%define only_efi 1
%endif

%ifarch %{efi}
%ifarch %{ix86}
%define grubefiarch i386-efi
%else
%ifarch aarch64
%define grubefiarch arm64-efi
%else
%ifarch %{arm}
%define grubefiarch arm-efi
%else
%define grubefiarch %{_target_cpu}-efi
%endif
%endif
%endif
%endif

%if 0%{?suse_version} == 1110
%define only_efi %{nil}
%define only_x86_64 %{nil}
%endif

Version:        2.02~beta2
Release:        0
Summary:        Bootloader with support for Linux, Multiboot and more
License:        GPL-3.0+
Group:          System/Boot
Url:            http://www.gnu.org/software/grub/
%define rev 20120622
Source0:        grub-%{version}.tar.xz
Source1:        90_persistent
Source2:        grub.default
Source3:        README.openSUSE
Source4:        grub2.rpmlintrc
# rsync -Lrtvz  translationproject.org::tp/latest/grub/ po
Source5:        translations-20140921.tar.xz
Source6:        grub2-once
Source7:        20_memtest86+
Source10:       openSUSE-UEFI-CA-Certificate.crt
Source11:       SLES-UEFI-CA-Certificate.crt
Source12:       grub2-snapper-plugin.sh
Source14:       80_suse_btrfs_snapshot
Source1000:     PATCH_POLICY
Patch1:         rename-grub-info-file-to-grub2.patch
Patch2:         grub2-linux.patch
Patch3:         use-grub2-as-a-package-name.patch
Patch6:         grub2-iterate-and-hook-for-extended-partition.patch
Patch8:         grub2-ppc-terminfo.patch
Patch9:         grub2-GRUB_CMDLINE_LINUX_RECOVERY-for-recovery-mode.patch
Patch10:        grub2-fix-error-terminal-gfxterm-isn-t-found.patch
Patch12:        grub2-fix-menu-in-xen-host-server.patch
Patch13:        grub2-enable-theme-for-terminal-window.patch
Patch15:        not-display-menu-when-boot-once.patch
Patch16:        grub2-fix-Grub2-with-SUSE-Xen-package-install.patch
Patch17:        grub2-pass-corret-root-for-nfsroot.patch
Patch18:        grub2-fix-locale-en.mo.gz-not-found-error-message.patch
Patch21:        grub2-secureboot-add-linuxefi.patch
Patch22:        grub2-secureboot-use-linuxefi-on-uefi.patch
Patch23:        grub2-secureboot-no-insmod-on-sb.patch
Patch24:        grub2-secureboot-provide-linuxefi-config.patch
Patch29:        grub2-secureboot-chainloader.patch
Patch34:        grub2-secureboot-use-linuxefi-on-uefi-in-os-prober.patch
Patch35:        grub2-linguas.sh-no-rsync.patch
Patch36:        0001-look-for-DejaVu-also-in-usr-share-fonts-truetype.patch
Patch37:        grub2-use-Unifont-for-starfield-theme-terminal.patch
Patch38:        grub2-s390x-01-Changes-made-and-files-added-in-order-to-allow-s390x.patch
Patch39:        grub2-use-rpmsort-for-version-sorting.patch
Patch40:        aarch64-reloc.patch
Patch41:        grub2-vbe-blacklist-preferred-1440x900x32.patch
Patch42:        grub2-btrfs-fix-incorrect-address-reference.patch
Patch43:        grub2-mkconfig-aarch64.patch
# Fix build with glibc 2.20+
Patch44:        grub2-glibc-2.20.patch
Patch45:        grub2-efinet-reopen-SNP-protocol-for-exclusive-use-by-grub.patch
Patch46:        grub2-xen-legacy-config-device-name.patch
Patch47:        grub2-Initialized-initrd_ctx-so-we-don-t-free-a-random-poi.patch
Patch48:        grub2-btrfs-fix-get_root-key-comparison-failures-due-to-en.patch
Patch49:        grub2-setup-try-fs-embed-if-mbr-gap-too-small.patch
# Btrfs snapshot booting related patches
Patch101:       grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch
Patch102:       grub2-btrfs-02-export-subvolume-envvars.patch
Patch103:       grub2-btrfs-03-follow_default.patch
Patch104:       grub2-btrfs-04-grub2-install.patch
Patch105:       grub2-btrfs-05-grub2-mkconfig.patch
# PowerPC LE support 
Patch201:       grub2-ppc64le-01-Add-Little-Endian-support-for-Power64-to-the-build.patch
Patch202:       grub2-ppc64le-02-Build-grub-as-O1-until-we-add-savegpr-and-restgpr-ro.patch
Patch203:       grub2-ppc64le-03-disable-creation-of-vsx-and-altivec-instructions.patch
Patch204:       grub2-ppc64le-04-powerpc64-LE-s-linker-knows-how-to-handle-the-undefi.patch
Patch205:       grub2-ppc64le-05-grub-install-can-now-recognize-and-install-a-LE-grub.patch
Patch206:       grub2-ppc64le-06-set-the-ABI-version-to-0x02-in-the-e_flag-of-the-PPC.patch
Patch207:       grub2-ppc64le-07-Add-IEEE1275_ADDR-helper.patch
Patch208:       grub2-ppc64le-08-Fix-some-more-warnings-when-casting.patch
Patch209:       grub2-ppc64le-09-Add-powerpc64-types.patch
Patch210:       grub2-ppc64le-10-powerpc64-is-not-necessarily-BigEndian-anymore.patch
Patch211:       grub2-ppc64le-11-Fix-warnings-when-building-powerpc-linux-loader-64bi.patch
Patch212:       grub2-ppc64le-12-GRUB_ELF_R_PPC_-processing-is-applicable-only-for-32.patch
Patch213:       grub2-ppc64le-13-Fix-powerpc-setjmp-longjmp-64bit-issues.patch
Patch214:       grub2-ppc64le-14-Add-powerpc64-ieee1275-trampoline.patch
Patch215:       grub2-ppc64le-15-Add-64bit-support-to-powerpc-startup-code.patch
Patch216:       grub2-ppc64le-16-Add-grub_dl_find_section_addr.patch
Patch217:       grub2-ppc64le-17-Add-ppc64-relocations.patch
Patch218:       grub2-ppc64le-18-ppc64-doesn-t-need-libgcc-routines.patch
Patch219:       grub2-ppc64le-19-Use-FUNC_START-FUNC_END-for-powerpc-function-definit.patch
Patch220:       grub2-ppc64le-20-.TOC.-symbol-is-special-in-ppc64le-.-It-maps-to-the-.patch
Patch221:       grub2-ppc64le-21-the-.toc-section-in-powerpc64le-modules-are-sometime.patch
Patch222:       grub2-ppc64le-22-all-parameter-to-firmware-calls-should-to-be-BigEndi.patch
Patch224:       grub2-ppc64-build-ppc64-32bit.patch
Patch225:       grub2-ppc64-qemu.patch
Patch226:       grub2-ppc64le-timeout.patch
Patch227:       grub2-use-stat-instead-of-udevadm-for-partition-lookup.patch
Patch228:       grub2-xfs-Add-helper-for-inode-size.patch
Patch229:       grub2-xfs-Fix-termination-loop-for-directory-iteration.patch
Patch230:       grub2-xfs-Convert-inode-numbers-to-cpu-endianity-immediate.patch
Patch231:       grub2-xfs-V5-filesystem-format-support.patch
Patch232:       grub2-efi_gop-avoid-low-resolution.patch
Patch233:       grub2-ppc64le-fix-64bit-trampoline-in-dyn-linker.patch
Patch234:       grub2-arm64-Reduce-timer-event-frequency-by-10.patch

Requires:       gettext-runtime
%if 0%{?suse_version} >= 1140
Requires:       os-prober
%endif
Requires(post): /sbin/install-info
Requires(preun):/sbin/install-info
%if ! 0%{?only_efi:1}
Requires:       grub2-%{grubarch} = %{version}-%{release}
%endif

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

%if 0%{?only_x86_64:1}
ExclusiveArch:  x86_64
%else
ExclusiveArch:  %{ix86} x86_64 ppc ppc64 ppc64le s390x aarch64 %{arm}
%endif

%description
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.

This package includes user space utlities to manage GRUB on your system.


Authors:
--------
    Gordon Matzigkeit
    Yoshinori K. Okuji
    Colin Watson
    Colin D. Bennett
    Vesa Jääskeläinen
    Robert Millan
    Carles Pina

%package branding-upstream

Summary:        Upstream branding for GRUB2's graphical console
Group:          System/Fhs
Requires:       %{name} = %{version}-%{release}

%description branding-upstream
Upstream branding for GRUB2's graphical console

%package %{grubarch}

Summary:        Bootloader with support for Linux, Multiboot and more
Group:          System/Boot
Requires:       %{name} = %{version}-%{release}
Requires(post):	%{name} = %{version}-%{release}
Requires:       perl-Bootloader
Requires(post): perl-Bootloader
%ifarch ppc64 ppc64le
Requires:       powerpc-utils
%endif

%description %{grubarch}
The GRand Unified Bootloader (GRUB) is a highly configurable and customizable
bootloader with modular architecture.  It supports rich variety of kernel formats,
file systems, computer architectures and hardware devices.  This subpackage
provides support for %{platform} systems.

%ifarch %{efi}

%package %{grubefiarch}

Summary:        Bootloader with support for Linux, Multiboot and more
Group:          System/Boot
%ifarch ia64 x86_64 aarch64
#Package is available on ia64, x86_64 and aarch64 only and not necessarily needed
Requires:       efibootmgr
Requires(post): efibootmgr
%endif
Requires:       %{name} = %{version}-%{release}
Requires(post):	%{name} = %{version}-%{release}
Requires:       perl-Bootloader >= 0.706
Requires(post): perl-Bootloader >= 0.706
Provides:       %{name}-efi = %{version}-%{release}
Obsoletes:      %{name}-efi < %{version}-%{release}

%description %{grubefiarch}
The GRand Unified Bootloader (GRUB) is a highly configurable and customizable
bootloader with modular architecture.  It supports rich variety of kernel formats,
file systems, computer architectures and hardware devices.  This subpackage
provides support for EFI systems.

%endif

%ifarch x86_64

%package %{_target_cpu}-xen

Summary:        Bootloader with support for Linux, Multiboot and more
Group:          System/Boot
Provides:       %{name}-xen = %{version}-%{release}
Obsoletes:      %{name}-xen < %{version}-%{release}

%description %{_target_cpu}-xen
The GRand Unified Bootloader (GRUB) is a highly configurable and customizable
bootloader with modular architecture.  It supports rich variety of kernel formats,
file systems, computer architectures and hardware devices.  This subpackage
provides support for XEN systems.

%endif

%package snapper-plugin

Summary:        Grub2's snapper plugin
Group:          System/Fhs
Requires:       %{name} = %{version}-%{release}
Requires:       libxml2-tools
Supplements:    packageand(snapper:grub2)
BuildArch:      noarch

%description snapper-plugin
Grub2's snapper plugin for advanced btrfs snapshot boot menu management

%prep
# We create (if we build for efi) two copies of the sources in the Builddir
%setup -q -n grub-%{version} -a 5
(cd po && ls *.po | cut -d. -f1 | xargs) >po/LINGUAS
%patch1 -p1
# This simplifies patch handling without need to use git to create patch
# that renames file
mv docs/grub.texi docs/grub2.texi
# This avoids attempt to rebuild potfiles which fails because necessary
# sources are not included in tarball
mv po/grub.pot po/%{name}.pot
%patch2 -p1
%patch3 -p1
%patch6 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch12 -p1
# disable and back to use black colored terminal window (bnc#776244)
# we could enable it when
# 1 we have background with better contrast to the font's color
# 2 we confirm it's eligible to set the terminal background this way
#%patch13 -p1
%patch15 -p1
%patch16 -p1
%patch17 -p1
%patch18 -p1
%patch21 -p1
%patch22 -p1
%patch23 -p1
%patch24 -p1
%patch29 -p1
%patch34 -p1
%patch35 -p1
%patch36 -p1
%patch37 -p1
%patch38 -p1
%patch39 -p1
%patch40 -p1
%patch41 -p1
%patch42 -p1
%patch43 -p1
%patch44 -p1
%patch45 -p1
%patch46 -p1
%patch47 -p1
%patch48 -p1
%patch49 -p1
%patch101 -p1
%patch102 -p1
%patch103 -p1
%patch104 -p1
%patch105 -p1
%patch201 -p1
%patch202 -p1
%patch203 -p1
%patch204 -p1
%patch205 -p1
%patch206 -p1
%patch207 -p1
%patch208 -p1
%patch209 -p1
%patch210 -p1
%patch211 -p1
%patch212 -p1
%patch213 -p1
%patch214 -p1
%patch215 -p1
%patch216 -p1
%patch217 -p1
%patch218 -p1
%patch219 -p1
%patch220 -p1
%patch221 -p1
%patch222 -p1
%patch224 -p1
%patch225 -p1
%patch226 -p1
%patch227 -p1
%patch228 -p1
%patch229 -p1
%patch230 -p1
%patch231 -p1
%patch232 -p1
%patch233 -p1
%patch234 -p1

# Generate po/LINGUAS for message catalogs ...
./linguas.sh
# ... and make sure new catalogs are actually created
rm -f po/stamp-po

# README.openSUSE
cp %{SOURCE3} .
mkdir build
%ifarch %{efi}
mkdir build-efi
%endif
%ifarch x86_64
mkdir build-xen
%endif

%build
# autogen calls autoreconf -vi
./autogen.sh
# Not yet:
%define common_conf_options TARGET_LDFLAGS=-static --program-transform-name=s,grub,%{name},
# This does NOT work on SLE11:
%define _configure ../configure

# We don't want to let rpm override *FLAGS with default a.k.a bogus values.
CFLAGS="-fno-strict-aliasing -fno-inline-functions-called-once "
CXXFLAGS=" "
FFLAGS=" "
export CFLAGS CXXFLAGS FFLAGS
export HOST_CFLAGS=$RPM_OPT_FLAGS

%ifarch x86_64
cd build-xen
../configure                           \
        TARGET_LDFLAGS=-static         \
        --prefix=%{_prefix}            \
        --sysconfdir=%{_sysconfdir}    \
        --target=%{_target_platform}   \
        --libdir=%{_libdir}            \
        --with-platform=xen            \
        --program-transform-name=s,grub,%{name},
make %{?_smp_mflags}

cat > ./grub.cfg <<EOF
insmod part_msdos
insmod part_gpt
insmod search
insmod configfile
insmod legacy_configfile
if search -s root -f /boot/grub2/grub.cfg ; then
  configfile /boot/grub2/grub.cfg
elif search -s root -f /@/boot/grub2/grub.cfg ; then
  configfile /@/boot/grub2/grub.cfg
elif search -s root -f /boot/grub/menu.lst ; then
  legacy_configfile /boot/grub/menu.lst
fi
EOF
./grub-mkstandalone --grub-mkimage=./grub-mkimage -o grub.xen -O %{_target_cpu}-xen -d grub-core/ "/boot/grub/grub.cfg=./grub.cfg"

cd ..
%endif

%ifarch %{efi}
cd build-efi
../configure   				                \
        TARGET_LDFLAGS=-static                          \
	--prefix=%{_prefix}				\
	--sysconfdir=%{_sysconfdir}			\
        --target=%{_target_platform}                    \
        --libdir=%{_libdir}                          \
        --with-platform=efi                             \
        --program-transform-name=s,grub,%{name},
make %{?_smp_mflags}

#TODO: add efifwsetup module

FS_MODULES="ext2 btrfs ext2 xfs jfs reiserfs"
CD_MODULES=" all_video boot cat chain configfile echo \
		efinet font gfxmenu gfxterm gzio halt iso9660 \
		jpeg minicmd normal part_apple part_msdos part_gpt \
		password_pbkdf2 png reboot search search_fs_uuid \
		search_fs_file search_label sleep test video fat loadenv"
PXE_MODULES="efinet tftp"

%ifarch x86_64
CD_MODULES="${CD_MODULES} linuxefi" 
%else
CD_MODULES="${CD_MODULES} linux" 
%endif

GRUB_MODULES="${CD_MODULES} ${FS_MODULES} ${PXE_MODULES} mdraid09 mdraid1x lvm"
./grub-mkimage -O %{grubefiarch} -o grub.efi --prefix= \
		-d grub-core ${GRUB_MODULES}
#./grub-mkimage -O %{grubefiarch} -o grub.efi -d grub-core part_gpt hfsplus fat \
#        ext2 btrfs normal chain boot configfile linux appleldr minicmd \
#        loadbios reboot halt search font gfxterm

%ifarch x86_64
%if 0%{?suse_version} >= 1230 || 0%{?suse_version} == 1110
if test -e %{_sourcedir}/_projectcert.crt ; then
    prjsubject=$(openssl x509 -in %{_sourcedir}/_projectcert.crt -noout -subject_hash)
    prjissuer=$(openssl x509 -in %{_sourcedir}/_projectcert.crt -noout -issuer_hash)
    opensusesubject=$(openssl x509 -in %{SOURCE10} -noout -subject_hash)
    slessubject=$(openssl x509 -in %{SOURCE11} -noout -subject_hash)
    if test "$prjissuer" = "$opensusesubject" ; then
        cert=%{SOURCE10}
    fi
    if test "$prjissuer" = "$slessubject" ; then
        cert=%{SOURCE11}
    fi
    if test "$prjsubject" = "$prjissuer" ; then
        cert=%{_sourcedir}/_projectcert.crt
    fi
fi
if test -z "$cert" ; then
    echo "cannot identify project, assuming openSUSE signing"
    cert=%{SOURCE10}
fi

openssl x509 -in $cert -outform DER -out grub.der
%endif
%endif

cd ..
%endif

%if ! 0%{?only_efi:1}
cd build

# 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}
%endif

%ifarch s390x
%define _devmapper --disable-device-mapper
%else
%define _devmapper --enable-device-mapper
%endif

# -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     \
	--prefix=%{_prefix}		\
	--sysconfdir=%{_sysconfdir}	\
        --target=%{_target_platform}    \
        --with-platform=%{platform}     \
	%{_devmapper}                   \
        --program-transform-name=s,grub,%{name},
make %{?_smp_mflags}
%endif

%install

%ifarch x86_64
cd build-xen
make DESTDIR=$RPM_BUILD_ROOT install
install -m 644 grub.xen $RPM_BUILD_ROOT%{_libdir}/%{name}/%{_target_cpu}-xen/.
cd ..
%endif

%ifarch %{efi}
cd build-efi
make DESTDIR=$RPM_BUILD_ROOT install

install -m 644 grub.efi $RPM_BUILD_ROOT%{_libdir}/%{name}/%{grubefiarch}/.

# Create grub.efi link to system efi directory
# This is for tools like kiwi not fiddling with the path
%if "%{grubefiarch}" == "x86_64-efi"
%define sysefidir %{_exec_prefix}/lib64/efi
%else
%define sysefidir %{_libdir}/efi
%endif
install -d $RPM_BUILD_ROOT%{sysefidir}
ln -sf ../../../%{_libdir}/%{name}/%{grubefiarch}/grub.efi $RPM_BUILD_ROOT%{sysefidir}/grub.efi

%ifarch x86_64
%if 0%{?suse_version} >= 1230 || 0%{?suse_version} == 1110
export BRP_PESIGN_FILES="%{_libdir}/%{name}/%{grubefiarch}/grub.efi"
install -m 444 grub.der $RPM_BUILD_ROOT%{sysefidir}/
%endif
%endif

cd ..
%endif

%if ! 0%{?only_efi:1}
cd build
make DESTDIR=$RPM_BUILD_ROOT install
%else
cd build-efi
%endif

# *.module files are installed with executable bits due to the way grub2 build
# system works. Clear executable bits to not confuse find-debuginfo.sh
find $RPM_BUILD_ROOT%{_libdir}/%{name} \
       \( -name '*.module' -o -name '*.image' -o -name '*.exec' \) -print0 | \
       xargs --no-run-if-empty -0 chmod a-x

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

# Script to generate memtest86+ menu entry
install -m 755 %{SOURCE7} $RPM_BUILD_ROOT%{_sysconfdir}/grub.d/

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

# Remove devel files
rm $RPM_BUILD_ROOT/%{_libdir}/%{name}/*/*.h
%if 0%{?suse_version} >= 1140
rm $RPM_BUILD_ROOT%{_datadir}/%{name}/*.h
%endif

# Defaults
install -m 644 -D %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/default/grub
install -m 755 -D %{SOURCE6} $RPM_BUILD_ROOT%{_sbindir}/grub2-once
install -m 755 -D %{SOURCE12} $RPM_BUILD_ROOT%{_libdir}/snapper/plugins/grub
install -m 755 -D %{SOURCE14} $RPM_BUILD_ROOT%{_sysconfdir}/grub.d/80_suse_btrfs_snapshot

%ifnarch %{ix86} x86_64
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/grub.d/20_memtest86+
%endif

%ifnarch ppc ppc64 ppc64le
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/grub.d/20_ppc_terminfo
%endif

%ifarch ppc ppc64 ppc64le
# Rename grub2.chrp back to grub.chrp so it is found by tools
mv $RPM_BUILD_ROOT%{_libdir}/%{name}/%{grubarch}/%{name}.chrp \
   $RPM_BUILD_ROOT%{_libdir}/%{name}/%{grubarch}/grub.chrp
%endif

%find_lang %{name}
%fdupes %buildroot%{_bindir}

%post
/sbin/install-info %{_infodir}/grub-dev.info %{_infodir}/dir || :
/sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir || :

%if ! 0%{?only_efi:1}

%post %{grubarch}
# To check by current loader settings
if [ -f %{_sysconfdir}/sysconfig/bootloader ]; then
  . %{_sysconfdir}/sysconfig/bootloader
fi

# If the grub is the current loader, we'll handle the grub2 testing entry
if [ "x${LOADER_TYPE}" = "xgrub" ]; then

  exec >/dev/null 2>&1

  # check if entry for grub2's core.img exists in the config
  # if yes, we will correct obsoleted path and update grub2 stuff and config to make it work
  # if no, do nothing
  if [ -f /boot/grub/menu.lst ]; then

    # If grub config contains obsolete core.img path, remove and use the new one
    if /usr/bin/grep -l "^\s*kernel\s*.*/boot/%{name}/core.img" /boot/grub/menu.lst; then
      /sbin/update-bootloader --remove --image /boot/%{name}/core.img || true
      /sbin/update-bootloader --add --image /boot/%{name}/i386-pc/core.img --name "GNU GRUB 2" || true
    fi

    # Install grub2 stuff and config to make the grub2 testing entry to work with updated version
    if /usr/bin/grep -l "^\s*kernel\s*.*/boot/%{name}/i386-pc/core.img" /boot/grub/menu.lst; then
      # Determine the partition with /boot
      BOOT_PARTITION=$(df -h /boot | sed -n '2s/[[:blank:]].*//p')
      # Generate core.img, but don't let it be installed in boot sector
      %{name}-install --no-bootsector $BOOT_PARTITION || true
      # Create a working grub2 config, otherwise that entry is un-bootable
      /usr/sbin/grub2-mkconfig -o /boot/%{name}/grub.cfg
    fi
  fi

elif [ "x${LOADER_TYPE}" = "xgrub2" ]; then

  # It's enought to call update-bootloader to install grub2 and update it's config
  # Use new --reinit, if not available use --refresh
  # --reinit: install and update bootloader config
  # --refresh: update bootloader config
  /sbin/update-bootloader --reinit 2>&1 | grep -q 'Unknown option: reinit' &&
  /sbin/update-bootloader --refresh || true
fi
%endif

%ifarch %{efi}

%post %{grubefiarch}

# To check by current loader settings
if [ -f %{_sysconfdir}/sysconfig/bootloader ]; then
  . %{_sysconfdir}/sysconfig/bootloader
fi

if [ "x${LOADER_TYPE}" = "xgrub2-efi" ]; then

  if [ -d /boot/%{name}-efi ]; then
    # Migrate settings to standard prefix /boot/grub2
    for i in custom.cfg grubenv; do
      [ -f /boot/%{name}-efi/$i ] && cp -a /boot/%{name}-efi/$i /boot/%{name} || :
    done

  fi

  # It's enough to call update-bootloader to install grub2 and update it's config
  # Use new --reinit, if not available use --refresh
  # --reinit: install and update bootloader config
  # --refresh: update bootloader config
  /sbin/update-bootloader --reinit 2>&1 | grep -q 'Unknown option: reinit' &&
  /sbin/update-bootloader --refresh || true
fi

if [ -d /boot/%{name}-efi ]; then
  mv /boot/%{name}-efi /boot/%{name}-efi.rpmsave
fi

exit 0
%endif

%preun
if [ $1 = 0 ]; then
  /sbin/install-info --delete %{_infodir}/grub-dev.info %{_infodir}/dir || :
  /sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir || :

%if ! 0%{?only_efi:1}
  # To check by current loader settings
  if [ -f %{_sysconfdir}/sysconfig/bootloader ]; then
    . %{_sysconfdir}/sysconfig/bootloader
  fi

  if [ "x${LOADER_TYPE}" = "xgrub" ]; then

    exec >/dev/null 2>&1

    if [ -f /boot/grub/menu.lst ]; then

      # Remove grub2 testing entry in menu.lst if has any
      for i in /boot/%{name}/core.img /boot/%{name}/i386-pc/core.img; do
        if /usr/bin/grep -l "^\s*kernel\s*.*$i" /boot/grub/menu.lst; then
          /sbin/update-bootloader --remove --image "$i" || true
        fi
      done
    fi

    # Cleanup config, to not confuse some tools determining bootloader in use
    rm -f /boot/%{name}/grub.cfg

    # Cleanup installed files
    # Unless grub2 provides grub2-uninstall, we don't remove any file because
    # we have no idea what's been installed. (And a blind remove is dangerous
    # to remove user's or other package's file accidently ..)
  fi
%endif
fi
%if 0%{?only_efi:1}
%define source_dir build-efi
%else
%define source_dir build
%endif

%files -f %{source_dir}/%{name}.lang
%defattr(-,root,root,-)
%doc COPYING NEWS README
%doc THANKS TODO ChangeLog
%doc README.openSUSE
%doc docs/autoiso.cfg docs/osdetect.cfg
%dir /boot/%{name}
%ghost /boot/%{name}/grub.cfg
%{_sysconfdir}/bash_completion.d/grub
%config(noreplace) %{_sysconfdir}/default/grub
%dir %{_sysconfdir}/grub.d
%{_sysconfdir}/grub.d/README
%config %{_sysconfdir}/grub.d/00_header
%config %{_sysconfdir}/grub.d/10_linux
%config %{_sysconfdir}/grub.d/20_linux_xen
%config %{_sysconfdir}/grub.d/30_os-prober
%config %{_sysconfdir}/grub.d/40_custom
%config %{_sysconfdir}/grub.d/41_custom
%config %{_sysconfdir}/grub.d/90_persistent
%{_sbindir}/%{name}-bios-setup
%{_sbindir}/%{name}-macbless
%{_sbindir}/%{name}-mkconfig
%{_sbindir}/%{name}-once
%{_sbindir}/%{name}-ofpathname
%{_sbindir}/%{name}-probe
%{_sbindir}/%{name}-reboot
%{_sbindir}/%{name}-set-default
%{_sbindir}/%{name}-sparc64-setup
%{_bindir}/%{name}-editenv
%{_bindir}/%{name}-file
%{_bindir}/%{name}-fstest
%{_bindir}/%{name}-glue-efi
%{_bindir}/%{name}-kbdcomp
%{_bindir}/%{name}-menulst2cfg
%{_bindir}/%{name}-mkfont
%{_bindir}/%{name}-mkimage
%{_bindir}/%{name}-mklayout
%{_bindir}/%{name}-mknetdir
%{_bindir}/%{name}-mkpasswd-pbkdf2
%{_bindir}/%{name}-mkrelpath
%{_bindir}/%{name}-mkrescue
%{_bindir}/%{name}-mkstandalone
%{_bindir}/%{name}-mount
%{_bindir}/%{name}-render-label
%{_bindir}/%{name}-script-check
%{_bindir}/%{name}-syslinux2cfg
%ifarch s390x
%{_bindir}/%{name}-emu
%{_bindir}/%{name}-emu-lite
%else
%{_sbindir}/%{name}-install
%endif
%dir %{_libdir}/%{name}
%dir %{_datadir}/%{name}
%dir %{_datadir}/%{name}/themes
%if 0%{?suse_version} >= 1140
%{_datadir}/%{name}/*.pf2
%endif
%{_datadir}/%{name}/grub-mkconfig_lib
%{_infodir}/grub-dev.info*
%{_infodir}/%{name}.info*
%{_mandir}/man1/%{name}-editenv.1.*
%{_mandir}/man1/%{name}-file.1.*
%{_mandir}/man1/%{name}-fstest.1.*
%{_mandir}/man1/%{name}-glue-efi.1.*
%{_mandir}/man1/%{name}-kbdcomp.1.*
%{_mandir}/man1/%{name}-macbless.1.*
%{_mandir}/man1/%{name}-menulst2cfg.1.*
%{_mandir}/man1/%{name}-mkfont.1.*
%{_mandir}/man1/%{name}-mkimage.1.*
%{_mandir}/man1/%{name}-mklayout.1.*
%{_mandir}/man1/%{name}-mknetdir.1.*
%{_mandir}/man1/%{name}-mkpasswd-pbkdf2.1.*
%{_mandir}/man1/%{name}-mkrelpath.1.*
%{_mandir}/man1/%{name}-mkrescue.1.*
%{_mandir}/man1/%{name}-mkstandalone.1.*
%{_mandir}/man1/%{name}-mount.1.*
%{_mandir}/man1/%{name}-render-label.1.*
%{_mandir}/man1/%{name}-script-check.1.*
%{_mandir}/man1/%{name}-syslinux2cfg.1.*
%{_mandir}/man8/%{name}-bios-setup.8.*
%{_mandir}/man8/%{name}-mkconfig.8.*
%{_mandir}/man8/%{name}-ofpathname.8.*
%{_mandir}/man8/%{name}-probe.8.*
%{_mandir}/man8/%{name}-reboot.8.*
%{_mandir}/man8/%{name}-set-default.8.*
%{_mandir}/man8/%{name}-sparc64-setup.8.*
%ifarch s390x
%{_mandir}/man1/%{name}-emu.1.*
%else
%{_mandir}/man8/%{name}-install.8.*
%endif

%files branding-upstream
%{_datadir}/%{name}/themes/starfield

%if ! 0%{?only_efi:1}

%files %{grubarch}
%defattr(-,root,root,-)
%ifarch %{ix86} x86_64
%config %{_sysconfdir}/grub.d/20_memtest86+
%endif
%dir %{_libdir}/%{name}/%{grubarch}
%ifarch ppc ppc64 ppc64le
%config %{_sysconfdir}/grub.d/20_ppc_terminfo
# This is intentionally "grub.chrp" and not "%{name}.chrp"
%{_libdir}/%{name}/%{grubarch}/grub.chrp
%{_libdir}/%{name}/%{grubarch}/bootinfo.txt
%endif
%ifnarch ppc ppc64 ppc64le s390x %{arm}
%{_libdir}/%{name}/%{grubarch}/*.image
%endif
%{_libdir}/%{name}/%{grubarch}/*.img
%{_libdir}/%{name}/%{grubarch}/*.lst
%{_libdir}/%{name}/%{grubarch}/*.mod
%{_libdir}/%{name}/%{grubarch}/*.module
%ifarch x86_64
%{_libdir}/%{name}/%{grubarch}/efiemu*.o
%endif
%{_libdir}/%{name}/%{grubarch}/gdb_grub2
%{_libdir}/%{name}/%{grubarch}/gmodule.pl
%{_libdir}/%{name}/%{grubarch}/kernel.exec
%{_libdir}/%{name}/%{grubarch}/modinfo.sh
%endif

%ifarch %{efi}

%files %{grubefiarch}
%defattr(-,root,root,-)
%dir %{_libdir}/%{name}/%{grubefiarch}
%{_libdir}/%{name}/%{grubefiarch}/grub.efi
%{_libdir}/%{name}/%{grubefiarch}/*.img
%{_libdir}/%{name}/%{grubefiarch}/*.lst
%{_libdir}/%{name}/%{grubefiarch}/*.mod
%{_libdir}/%{name}/%{grubefiarch}/*.module
%{_libdir}/%{name}/%{grubefiarch}/gdb_grub2
%{_libdir}/%{name}/%{grubefiarch}/gmodule.pl
%{_libdir}/%{name}/%{grubefiarch}/kernel.exec
%{_libdir}/%{name}/%{grubefiarch}/modinfo.sh
%dir %{sysefidir}
%{sysefidir}/grub.efi

%ifarch x86_64
%if 0%{?suse_version} >= 1230 || 0%{?suse_version} == 1110
%{sysefidir}/grub.der
%endif
%endif
%endif

%files snapper-plugin
%defattr(-,root,root,-)
%dir %{_libdir}/snapper
%dir %{_libdir}/snapper/plugins
%config %{_sysconfdir}/grub.d/80_suse_btrfs_snapshot
%{_libdir}/snapper/plugins/grub

%ifarch x86_64
%files %{_target_cpu}-xen
%dir %{_libdir}/%{name}/%{_target_cpu}-xen
%{_libdir}/%{name}/%{_target_cpu}-xen/*
%endif

%changelog