File grub2.spec of Package grub2.4793

# spec file for package grub2
# Copyright (c) 2017 SUSE LINUX 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
# needssslcertforbuild

Name:           grub2
%ifarch x86_64 ppc64
BuildRequires:  gcc-32bit
BuildRequires:  glibc-32bit
BuildRequires:  glibc-devel-32bit
BuildRequires:  gcc
BuildRequires:  glibc-devel
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
BuildRequires:  help2man
BuildRequires:  xz
%if 0%{?suse_version} >= 1210
BuildRequires:  makeinfo
BuildRequires:  texinfo
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
%if 0%{?suse_version} >= 1210
BuildRequires:  systemd
%define has_systemd 1

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

# Build grub2-emu everywhere (it may be "required" by 'grub2-once')
%define emu 1

%ifarch ppc ppc64 ppc64le
%define grubcpu powerpc
%define platform ieee1275
# emu does not build here yet... :-(
%define emu 0

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

%ifarch s390x
%define grubcpu s390x
%define platform emu

%ifarch aarch64
%define grubcpu arm64
%define platform efi
%define only_efi 1

%ifarch %{arm}
%define grubcpu arm
%define platform efi
%define only_efi 1

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

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

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

%if %{platform} == emu
# force %{emu} to 1, e.g. for s390
%define emu 1

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

Version:        2.02~beta2
Release:        0
Summary:        Bootloader with support for Linux, Multiboot and more
License:        GPL-3.0+
Group:          System/Boot
%define rev 20120622
Source0:        grub-%{version}.tar.xz
Source1:        90_persistent
Source2:        grub.default
Source3:        README.openSUSE
Source4:        grub2.rpmlintrc
# rsync -Lrtvz po
Source5:        translations-20130626.tar.xz
Source6:        grub2-once
Source7:        20_memtest86+
Source8:        README.ibm3215
Source10:       openSUSE-UEFI-CA-Certificate.crt
Source11:       SLES-UEFI-CA-Certificate.crt
Source14:       80_suse_btrfs_snapshot
Source15:       grub2-once.service
Source16:       grub2-xen-pv-firmware.cfg
# required hook for systemd-sleep (bsc#941758)
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
Patch17:        grub2-pass-corret-root-for-nfsroot.patch
Patch19:        grub2-efi-HP-workaround.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
Patch36:        0001-look-for-DejaVu-also-in-usr-share-fonts-truetype.patch
Patch37:        grub2-use-DejaVuSansMono-for-starfield-theme.patch
Patch38:        grub2-s390x-01-Changes-made-and-files-added-in-order-to-allow-s390x.patch
Patch39:        grub2-s390x-02-kexec-module-added-to-emu.patch
Patch40:        grub2-s390x-03-output-7-bit-ascii.patch
Patch41:        grub2-s390x-04-grub2-install.patch
Patch42:        grub2-s390x-05-grub2-mkconfig.patch
Patch43:        grub2-s390x-06-loadparm.patch
Patch44:        0001-efidisk-move-device-path-helpers-in-core-for-efinet.patch
Patch45:        0002-efinet-skip-virtual-IPv4-and-IPv6-devices-when-enume.patch
Patch46:        0003-efinet-open-Simple-Network-Protocol-exclusively.patch
Patch47:        0001-efinet-Check-for-immediate-completition.patch
Patch48:        0001-efinet-enable-hardware-filters-when-opening-interfac.patch
Patch49:        grub2-commands-introduce-read_file-subcommand.patch
Patch50:        grub2-mkconfig-aarch64.patch
Patch51:        grub2-xen-legacy-config-device-name.patch
Patch52:        grub2-getroot-support-NVMe-device-names.patch
Patch53:        grub2-getroot-treat-mdadm-ddf-as-simple-device.patch
Patch56:        grub2-setup-try-fs-embed-if-mbr-gap-too-small.patch
Patch57:        grub2-netboot-hang.patch
Patch58:        grub2-xen-linux16.patch
Patch59:        grub2-efi-disable-video-cirrus-and-bochus.patch
Patch60:        grub2-editenv-add-warning-message.patch
Patch61:        grub2-efi-chainload-harder.patch
Patch62:        grub2-vbe-blacklist-preferred-1440x900x32.patch
Patch63:        grub2-btrfs-fix-incorrect-address-reference.patch
Patch64:        aarch64-reloc.patch
Patch65:        grub2-btrfs-workaround-grub2-once.patch
Patch66:        grub2-menu-unrestricted.patch
Patch67:        grub2-default-distributor.patch
Patch68:        fix-overflows-in-grub_password_get-and-grub_user_get.patch
Patch70:        grub2-xen-fix-bzImage-payload-length.patch
Patch71:        0001-increase-network-try-interval-gradually.patch
Patch72:        grub2-s390x-07-add-image-param-for-zipl-setup.patch
Patch73:        grub2-s390x-08-workaround-part-to-disk.patch
Patch74:        0001-grub-core-kern-efi-efi.c-Ensure-that-the-result-star.patch
Patch75:        grub2-lvm-allocate-metadata-buffer-from-raw-contents.patch
Patch76:        grub2-diskfilter-support-pv-without-metadatacopies.patch
Patch77:        grub2-efi-uga-64bit-fb.patch
Patch78:        0001-support-modules-without-symbol-table.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
Patch106:       grub2-btrfs-06-subvol-mount.patch
Patch107:       grub2-btrfs-07-subvol-fallback.patch
Patch108:       grub2-btrfs-08-workaround-snapshot-menu-default-entry.patch
Patch109:       grub2-btrfs-09-get-default-subvolume.patch
Patch110:       0001-script-provide-overridable-root-by-subvol.patch
Patch111:       0002-script-create-menus-for-btrfs-snapshot.patch
# Support EFI xen loader (efistub)
Patch120:       grub2-efi-xen-chainload.patch
Patch121:       grub2-efi-chainloader-root.patch
Patch122:       grub2-efi-xen-cmdline.patch
# Linux Root device related fixes
Patch130:       grub2-10_linux-avoid-multi-device-root-kernel-argument.patch
Patch131:       0001-10_linux-Fix-grouping-of-tests-for-GRUB_DEVICE.patch
Patch132:       0002-20_linux_xen-fix-test-for-GRUB_DEVICE.patch
Patch134:       grub2-zipl-setup-fix-btrfs-multipledev.patch
Patch135:       grub2-suse-remove-linux-root-param.patch
# POWER patches
Patch201:       ppc64le.patch
Patch202:       libgcc-prereq.patch
Patch203:       libgcc.patch
Patch204:       grub2-ppc64-qemu.patch
Patch205:       grub2-ppc64le-disable-video.patch
Patch206:       grub2-ppc64le-memory-map.patch
Patch207:       biendian.patch
Patch208:       ppc64_opt.patch
Patch209:       grub2-ppc64-cas-reboot-support.patch
Patch210:       btrfs-fix_get_root_key_comparison_failures_due_to_endianness.patch
Patch211:       grub2-getroot-fix-get-btrfs-fs-prefix-big-endian.patch

Patch229:       grub2-xfs-Add-helper-for-inode-size.patch
Patch230:       grub2-xfs-Fix-termination-loop-for-directory-iteration.patch
Patch231:       grub2-xfs-Convert-inode-numbers-to-cpu-endianity-immediate.patch
Patch232:       grub2-xfs-V5-filesystem-format-support.patch
Patch233:       grub2-use-stat-instead-of-udevadm-for-partition-lookup.patch
Patch234:       0001-Add-bootargs-parser-for-open-firmware.patch 
Patch235:       0002-Add-Virtual-LAN-support.patch 
Patch236:       grub2-efi_gop-avoid-low-resolution.patch
Patch239:       grub2-arm64-Reduce-timer-event-frequency-by-10.patch
Patch240:       grub2-arm64-set-correct-length.patch
Patch241:       grub2-arm64-setjmp-Add-missing-license-macro.patch
Patch242:       grub2-arm64-efinet-handle-get_status-on-buggy-firmware-properly.patch
# Upstream patches to fix name to bootaa64.efi
Patch243:       grub2-arm64-bootaa64-fix-1.patch
Patch244:       grub2-arm64-bootaa64-fix-2.patch
# Support for "t" hotkey to switch to text mode (bsc#976836)
Patch245:       grub2-Add-hidden-menu-entries.patch
Patch246:       grub2-SUSE-Add-the-t-hotkey.patch
# Upstream patch to fix GRUB2 clock too slow on RPI3 (bsc#990604)
Patch247:       grub2-arm64-Use-cpu-timer-for-timekeeping.patch
Patch248:       grub2-arm64-mknetdir-add-suport-for-arm64-efi.patch
# UEFI IPv6 PXE booting support
Patch250:       grub2-net-icmp6-fix-no-respond-to-neighbor-solicit-message.patch
Patch251:       grub2-net-send-router-solicitation-for-ipv6-address-autoconf.patch
Patch252:       grub2-efinet-ipv6-dhcpv6.patch
Patch253:       grub2-efinet-ipv6-dhcpv6-use-mac-device.patch
Patch254:       grub2-bootp6-dns.patch
Patch255:       grub2-efinet-httpboot.patch
# Upstream patches for fixing file descriptor leakage (bsc#943784)
Patch260:       0001-unix-password-Fix-file-descriptor-leak.patch
Patch261:       0002-linux-getroot-fix-descriptor-leak.patch
Patch262:       0003-util-grub-mount-fix-descriptor-leak.patch
Patch263:       0004-linux-ofpath-fix-descriptor-leak.patch
Patch264:       0005-grub-fstest-fix-descriptor-leak.patch
# Upstream patch to fix patch 0001-unix-password-Fix-file-descriptor-leak.patch
Patch265:       0001-unix-do-not-close-stdin-in-grub_passwd_get.patch
# Backport upstream patches for HyperV gen2 TSC timer calbration without RTC (bsc#904647)
Patch270:       0001-grub-core-kern-i386-tsc.c-calibrate_tsc-Ensure-that.patch
Patch271:       0002-i386-tsc-Fix-unused-function-warning-on-xen.patch
Patch272:       0003-acpi-do-not-skip-BIOS-scan-if-EBDA-length-is-zero.patch
Patch273:       0004-tsc-Use-alternative-delay-sources-whenever-appropria.patch
Patch274:       0005-i386-fix-TSC-calibration-using-PIT.patch
# FATE#319861: install + boot support for libnvdimm storage devices
Patch280:       0001-efi-really-mark-memory-of-unknown-type-as-reserved.patch
Patch281:       0002-Translate-UEFI-persistent-memory-type.patch
Patch282:       0003-lsefimmap-support-persistent-memory-and-other-UEFI-2.patch
# EFI free memory on exit fix (bsc#980739)
Patch283:       grub2-efi-Move-grub_reboot-into-kernel.patch
Patch284:       grub2-efi-Free-malloc-regions-on-exit.patch
Patch285:       grub2-emu-4-all.patch
Patch286:       grub2-emu-hostfs-Drop-unnecessary-feature-test-macros.patch
# Backported upstream patches to fix error on encrypted lvm installation (bsc#981621) 
Patch290:       0001-Fix-partmap-cryptodisk-and-abstraction-handling-in-g.patch
Patch291:       0002-disk-cryptodisk-Add-missing-error-check.patch
Patch292:       0003-crypto-restrict-cipher-block-size-to-power-of-2.patch
Patch293:       0004-cryptodisk-strip-parenthesis-from-backing-device-nam.patch
Patch294:       0005-cryptodisk-teach-grub_cryptodisk_insert-about-partit.patch
Patch295:       0006-do-not-emit-cryptomount-without-crypto-UUID.patch
# Backported upstream patches to fix crash on EFI systems
Patch296:       grub2-efi-check-path-non-null-before-grub_strrchr.patch
Patch297:       grub2-mkstandalone-out-of-bound-access-to-tar-header-.patch
Patch298:       grub2-efidisk-Respect-block_io_protocol-buffer-alignment.patch
# Cherrypick upstream patches for bug fixes (bsc#990086)
Patch300:       0001-Initialized-initrd_ctx-so-we-don-t-free-a-random-poi.patch
Patch301:       0002-grub-core-disk-lzopio.c-fix-double-free-in-error-pat.patch
Patch302:       0003-fix-double-free-in-grub_net_recv_tcp_packet.patch
Patch303:       0004-arm64-setjmp-Add-missing-move-for-arg1-0-case.patch
Patch304:       0005-tftp-fix-memory-leaks-in-open.patch
Patch305:       0006-Remove-the-variable-oldname-which-is-attempting-to-f.patch
# SLES12SP2:grub times out loading kernel during install (bsc#994497)
Patch306:       0007-arp-icmp-Fix-handling-in-case-of-oversized-or-invali.patch
# Fix build arm-efi and arm64-efi for openSUSE (bsc#1004959) 
Patch307:       grub2-arm64-Add-support-for-relocations-needed-for-linaro-.patch
Patch308:       grub2-XFS-Fix-wrong-alignment-treatment.patch
# PATCH-FIX-OPENSUSE 0001-arm64-Move-firmware-fdt-search-into-global-function.patch bnc#1008545
Patch309:       0001-arm64-Move-firmware-fdt-search-into-global-function.patch
# PATCH-FIX-OPENSUSE 0002-arm-efi-Use-fdt-from-firmware-when-available.patch bnc#1008545
Patch310:       0002-arm-efi-Use-fdt-from-firmware-when-available.patch
# PATCH-FIX-OPENSUSE grub2-mkconfig-arm.patch bnc#1008568
Patch311:       grub2-mkconfig-arm.patch
# Support booting huge xen pv-domains (bsc#1004398) (bsc#899465)
Patch400:       0001-Import-xen-headers-directly-into-GRUB.patch
Patch401:       0002-Adapt-build-system-to-use-imported-xen-headers.patch
Patch402:       0003-xen-relocator-Use-local-symbol-to-ensure-that-code-i.patch
Patch403:       0001-xen-make-xen-loader-callable-multiple-times.patch
Patch404:       0002-xen-avoid-memleaks-on-error.patch
Patch405:       0003-xen-reduce-number-of-global-variables-in-xen-loader.patch
Patch406:       0004-xen-add-elfnote.h-to-avoid-using-numbers-instead-of-.patch
Patch407:       0005-xen-synchronize-xen-header.patch
Patch408:       0006-xen-factor-out-p2m-list-allocation-into-separate-fun.patch
Patch409:       0007-xen-factor-out-allocation-of-special-pages-into-sepa.patch
Patch410:       0008-xen-factor-out-allocation-of-page-tables-into-separa.patch
Patch411:       0009-xen-add-capability-to-load-initrd-outside-of-initial.patch
Patch412:       0010-xen-modify-page-table-construction.patch
Patch413:       0011-xen-add-capability-to-load-p2m-list-outside-of-kerne.patch

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

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

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

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.

    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

%if ! 0%{?only_efi:1}
%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 s390x
Requires:       /sbin/showconsole
Requires:       kexec-tools
Requires:       s390-tools
%ifarch ppc64 ppc64le
Requires:       powerpc-utils

%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 aarch64 ia64 x86_64
#Package is available on ia64 and x86_64 only and not necessarily needed
Requires:       efibootmgr
Requires(post): efibootmgr
%ifarch ppc ppc64 ppc64le
Requires:       powerpc-utils
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.


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


%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

%if 0%{?has_systemd:1}
%package systemd-sleep-plugin

Summary:        Grub2's systemd-sleep plugin
Group:          System/Fhs
Requires:       grub2
Requires:       util-linux
Supplements:    packageand(systemd:grub2)
BuildArch:      noarch

%description systemd-sleep-plugin
Grub2's systemd-sleep plugin for directly booting hibernated kernel image in
swap partition while in resuming

# 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
%patch17 -p1
%patch18 -p1
%patch19 -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
# The follow patch is needed for bnc#891946/892852 exclusively on s390x
# It doesn't help to add this to common code just now.
%ifarch s390x
%patch49 -p1
%patch50 -p1
%patch51 -p1
%patch52 -p1
%patch53 -p1
%patch56 -p1
%patch57 -p1
%patch58 -p1
%patch59 -p1
%patch60 -p1
%patch61 -p1
%patch62 -p1
%patch63 -p1
%patch64 -p1
%patch65 -p1
%patch66 -p1
%patch67 -p1
%patch68 -p1
%patch70 -p1
%patch71 -p1
%patch72 -p1
%patch73 -p1
%patch74 -p1
%patch75 -p1
%patch76 -p1
%patch77 -p1
%patch78 -p1
%patch101 -p1
%patch102 -p1
%patch103 -p1
%patch104 -p1
%patch105 -p1
%patch106 -p1
%patch107 -p1
%patch108 -p1
%patch109 -p1
#patch110 -p1
#patch111 -p1
%patch120 -p1
%patch121 -p1
%patch122 -p1
%patch130 -p1
%patch131 -p1
%patch132 -p1
%patch134 -p1
%patch135 -p1
%patch201 -p1
%patch202 -p1
%patch203 -p1
%patch204 -p1
%patch205 -p1
%patch206 -p1
%patch207 -p1
%patch208 -p1
%patch209 -p1
%patch210 -p1
%patch211 -p1

%patch229 -p1
%patch230 -p1
%patch231 -p1
%patch232 -p1
%patch233 -p1
%patch234 -p1
%patch235 -p1
%patch236 -p1
%patch239 -p1
%patch240 -p1
%patch241 -p1
%patch242 -p1
%patch243 -p1
%patch244 -p1
%patch245 -p1
%patch246 -p1
%patch247 -p1
%patch248 -p1
%patch250 -p1
%patch251 -p1
%patch252 -p1
%patch253 -p1
%patch254 -p1
%patch255 -p1
%patch260 -p1
%patch261 -p1
%patch262 -p1
%patch263 -p1
%patch264 -p1
%patch265 -p1
%patch270 -p1
%patch271 -p1
%patch272 -p1
%patch273 -p1
%patch274 -p1
%patch280 -p1
%patch281 -p1
%patch282 -p1
%patch283 -p1
%patch284 -p1
%patch285 -p1
%patch286 -p1
%patch290 -p1
%patch291 -p1
%patch292 -p1
%patch293 -p1
%patch294 -p1
%patch295 -p1
%patch296 -p1
%patch297 -p1
%patch298 -p1
%patch300 -p1
%patch301 -p1
%patch302 -p1
%patch303 -p1
%patch304 -p1
%patch305 -p1
%patch306 -p1
%patch307 -p1
%patch308 -p1
%patch309 -p1
%patch310 -p1
%patch311 -p1
%patch400 -p1
%patch401 -p1
%patch402 -p1
%patch403 -p1
%patch404 -p1
%patch405 -p1
%patch406 -p1
%patch407 -p1
%patch408 -p1
%patch409 -p1
%patch410 -p1
%patch411 -p1
%patch412 -p1
%patch413 -p1

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

cp --preserve=timestamps %{SOURCE3} .
cp --preserve=timestamps %{SOURCE8} .
mkdir build
%ifarch %{efi}
mkdir build-efi
%ifarch x86_64
mkdir build-xen
%if %{emu}
mkdir build-emu

# autogen calls autoreconf -vi
# 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 "

%if %{emu}
cd build-emu
%define arch_specific --enable-device-mapper --disable-grub-mount

# -static is needed so that autoconf script is able to link
# test that looks for _start symbol on 64 bit platforms
../configure TARGET_LDFLAGS=$TFLAGS     \
	--prefix=%{_prefix}		\
	--sysconfdir=%{_sysconfdir}	\
        --target=%{_target_platform}    \
        --with-platform=emu     \
	%{arch_specific}                \
make %{?_smp_mflags}
cd ..
if [ "%{platform}" = "emu" ]; then
  rmdir build
  mv build-emu build

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

./grub-mkstandalone --grub-mkimage=./grub-mkimage -o grub.xen -O %{_target_cpu}-xen -d grub-core/ "/boot/grub/grub.cfg=%{SOURCE16}"

cd ..

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

#TODO: add efifwsetup module

FS_MODULES="ext2 btrfs ext2 xfs jfs reiserfs"
CD_MODULES=" all_video boot cat chain configfile echo true \
		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 http"
CRYPTO_MODULES="luks gcry_rijndael gcry_sha1"

%ifarch x86_64
CD_MODULES="${CD_MODULES} linuxefi" 

./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
    if test "$prjissuer" = "$slessubject" ; then
    if test "$prjsubject" = "$prjissuer" ; then
if test -z "$cert" ; then
    echo "cannot identify project, assuming openSUSE signing"

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

cd ..

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

%if %{platform} != "emu"
%define arch_specific --enable-device-mapper

# -static is needed so that autoconf script is able to link
# test that looks for _start symbol on 64 bit platforms
../configure TARGET_LDFLAGS=$TFLAGS     \
	--prefix=%{_prefix}		\
	--sysconfdir=%{_sysconfdir}	\
        --target=%{_target_platform}    \
        --with-platform=%{platform}     \
	%{arch_specific}                \
make %{?_smp_mflags}
cd ..


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

%ifarch %{efi}
cd build-efi

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
%define sysefidir %{_libdir}/efi
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}/

cd ..

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

if [ -d build-emu/grub-core ]; then
  cd build-emu/grub-core
  install -m 755 grub-emu $RPM_BUILD_ROOT%{_bindir}/%{name}-emu
  install -m 755 grub-emu-lite $RPM_BUILD_ROOT%{_bindir}/%{name}-emu-lite
  install -m 644 grub-emu.1 $RPM_BUILD_ROOT%{_mandir}/man1/%{name}-emu.1
  cd ../..

# *.module files are installed with executable bits due to the way grub2 build
# system works. Clear executable bits to not confuse
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

# 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
%if 0%{?has_systemd:1}
install -m 644 -D %{SOURCE15} $RPM_BUILD_ROOT%{_unitdir}/grub2-once.service
install -m 755 -D %{SOURCE17} $RPM_BUILD_ROOT%{_libdir}/systemd/system-sleep/grub2.sleep

%ifarch %{ix86} x86_64
rm -f $R%{_sysconfdir}/grub.d/20_memtest86+

%ifarch ppc ppc64 ppc64le
rm -f $R%{_sysconfdir}/grub.d/20_ppc_terminfo

%ifarch s390x
mv $R%{_sysconfdir}/{grub.d,default}/
chmod 600 $R%{_sysconfdir}/default/

%define dracutlibdir %{_prefix}/lib/dracut
%define dracutgrubmoddir %{dracutlibdir}/modules.d/99grub2
install -m 755 -d $R%{dracutgrubmoddir}
for f in; do
  mv $R%{_libdir}/%{name}/%{grubarch}/dracut-$f $R%{dracutgrubmoddir}/$f
rm -f $R%{_sysconfdir}/grub.d/30_os-prober

perl -ni -e '
  sub END() {
    print "\n# on s390x always:\nGRUB_DISABLE_OS_PROBER=true\n";
  if ( s{^#(GRUB_DISABLE_LINUX_RECOVERY)=\"?(true)\"?}{$1=$2} ) {
    $_ .= "GRUB_DISABLE_RECOVERY=true\n";
  if ( s{^#?(GRUB_TERMINAL)=(console|gfxterm)}{$1=console} ) {
    $_ .= "GRUB_GFXPAYLOAD_LINUX=text\n";
  if (	m{^# The resolution used on graphical} ||
	m{^# # note that you can use only modes} ||
	m{^# you can see them in real GRUB} ||
	m{^#?GRUB_GFXMODE=} ) {
  s{openSUSE}{SUSE Linux Enterprise Server} if (m{^GRUB_DISTRIBUTOR});
'  $RPM_BUILD_ROOT%{_sysconfdir}/default/grub

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

/sbin/install-info %{_infodir}/ %{_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

# 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

    # 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 |(read; awk '{print $1; exit}'))
      # 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

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

%ifarch %{efi}

%post %{grubefiarch}

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

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} || :


  # 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

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

exit 0

if [ $1 = 0 ]; then
  /sbin/install-info --delete %{_infodir}/ %{_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

  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

    # 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 ..)

%files -f %{name}.lang
%doc THANKS TODO ChangeLog
%doc README.openSUSE
%doc docs/autoiso.cfg docs/osdetect.cfg
%ifarch s390x
%doc README.ibm3215
%dir /boot/%{name}
%ghost /boot/%{name}/grub.cfg
%config(noreplace) %{_sysconfdir}/default/grub
%dir %{_sysconfdir}/grub.d
%config %{_sysconfdir}/grub.d/00_header
%config %{_sysconfdir}/grub.d/10_linux
%config %{_sysconfdir}/grub.d/20_linux_xen
%config %{_sysconfdir}/grub.d/40_custom
%config %{_sysconfdir}/grub.d/41_custom
%config %{_sysconfdir}/grub.d/90_persistent
%config %{_sysconfdir}/grub.d/95_textmode
%if 0%{?has_systemd:1}
%dir %{_libdir}/%{name}
%dir %{_datadir}/%{name}
%dir %{_datadir}/%{name}/themes
%if 0%{?suse_version} >= 1140
%if %{emu}
%ifnarch s390x
%config %{_sysconfdir}/grub.d/30_os-prober

%files branding-upstream

%if ! 0%{?only_efi:1}

%files %{grubarch}
%ifarch %{ix86} x86_64
%config %{_sysconfdir}/grub.d/20_memtest86+
%dir %{_libdir}/%{name}/%{grubarch}
%ifarch ppc ppc64 ppc64le
%config %{_sysconfdir}/grub.d/20_ppc_terminfo
%ifnarch ppc ppc64 ppc64le s390x
%ifarch x86_64
%ifarch s390x
%config(noreplace) %{_sysconfdir}/default/

%ifarch %{efi}

%files %{grubefiarch}
%dir %{_libdir}/%{name}/%{grubefiarch}
%dir %{sysefidir}

%ifarch x86_64
%if 0%{?suse_version} >= 1230 || 0%{?suse_version} == 1110

%files snapper-plugin
%dir %{_libdir}/snapper
%dir %{_libdir}/snapper/plugins
%config %{_sysconfdir}/grub.d/80_suse_btrfs_snapshot

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

%if 0%{?has_systemd:1}
%files systemd-sleep-plugin
%dir %{_libdir}/systemd/system-sleep

openSUSE Build Service is sponsored by