%define efi_support 1

%ifarch %{ix86}
%define _host_cpu i386
%else
%define _host_cpu %{_arch}
%endif

%define defshell defaultmenu.sh

Summary: grub - a Multiboot boot loader. 
Summary(ja): grub - マルチブートローダ
Name: grub
Version: 0.97
Release: 6%{?_dist_release}
License: GPL
Group: System Environment/Base
URL: http://www.gnu.org/software/grub/

Source0: ftp://alpha.gnu.org/gnu/grub/%{name}-%{version}.tar.gz
Source1: %{defshell}

# This is from
# http://git.kernel.org/?p=boot/grub-fedora/grub-fedora.git;a=summary
Patch0: grub-fedora-18.patch
Patch1: 0001-Fix-strange-compilation-problem.patch
Patch2: 0003-Move_network-disable-earlier.patch
Patch3: 0005-Fix-Apple-CD-fixup.patch
Patch4: 0006-Avoid-broken-uefi-fs.patch
Patch5: 0007-fix-uefi-stride.patch
Patch6: 0008-fix-gop.patch

# for Vine
Patch1000: grub-fedora-18-uninitialized.patch
Patch1001: grub-fedora-18-static-efi.patch
Patch1002: grub-0.97-grub-install-vine.patch

ExclusiveArch: %{ix86} x86_64
BuildRoot: %{_tmppath}/%{name}-%{version}-root
Requires(post): install-info, sed, grep, coreutils
Requires(preun): install-info
Requires: mktemp
Requires: util-linux
BuildRequires: ncurses-devel >= 5.6
BuildRequires: glibc-static
%ifarch x86_64
BuildRequires: compat32-glibc-devel
BuildRequires: compat32-glibc-static
%endif
%if %{efi_support}
BuildRequires: gnu-efi >= 3.0e-9
%endif
BuildRequires: texinfo

%description
GNU GRUB is a Multiboot boot loader. 
It was derived from GRUB, GRand Unified Bootloader, which was 
originally designed and implemented by Erich Stefan Boleyn. 

Briefly, bootloader is the first software program that runs when
a computer starts. It is responsible for loading and transferring
control to the operating system kernel software (such as the Hurd
or the Linux). The kernel, in turn, initializes the rest of the 
operating system (usually GNU). 

%description -l ja
GNU GRUB はマルチブートローダです。
この名前は GRand Unified Bootloader (壮大な 統一されたブート
ローダ) に由来し、元来は Erich Stefan Boleyn によって、設計・
実装されたものです。

手短に言えば、ブートローダとはコンピュータが起動する際に最初
に実行されるプログラムで、(Hurd や Linux のような) オペレー
ティングシステムのカーネルをディスクから読み込んで制御を渡す
作業を担当します。カーネルは、それを受けて、オペレーティング
システムの他の部分 (通常は GNU) を初期化します。


%prep
%setup -q
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch1000 -p1
%patch1001 -p1
%patch1002 -p1

# Modify grub to show the full version number
sed -i 's/0\.97/%{version}-%{release}/' configure.ac

%build
autoreconf -if
GCCVERS=$(gcc --version | head -1 | cut -d\  -f3 | cut -d. -f1)
# add "-fno-reorder-functions"
# https://bugzilla.redhat.com/show_bug.cgi?id=718722
# https://bugs.launchpad.net/ubuntu/+source/grub/+bug/837815
CFLAGS="-Os -g -fno-strict-aliasing -Wall -Werror -Wno-shadow -Wno-unused -fno-reorder-functions"
if [ "$GCCVERS" == "4" ]; then
  CFLAGS="$CFLAGS -Wno-pointer-sign"
fi
export CFLAGS

%if %{efi_support}
%configure --sbindir=/sbin \
  --disable-auto-linux-mem-opt \
  --datarootdir=%{_datadir} \
  --with-platform=efi
%__make
mv efi/grub.efi .
make clean
%endif
autoreconf -if
CFLAGS="$CFLAGS -static" 
export CFLAGS
%configure --sbindir=/sbin \
  --datarootdir=%{_datadir} \
  --disable-auto-linux-mem-opt
%__make


%install
rm -rf $RPM_BUILD_ROOT
%makeinstall sbindir=${RPM_BUILD_ROOT}/sbin
mkdir -p ${RPM_BUILD_ROOT}/boot/grub
%if %{efi_support}
mkdir -m 0755 -p ${RPM_BUILD_ROOT}/boot/efi/EFI/vine/
install -m 755 grub.efi ${RPM_BUILD_ROOT}/boot/efi/EFI/vine/grub.efi
%endif
%{__install} -p -m 644 docs/menu.lst %{buildroot}%{_datadir}/grub/%{_host_cpu}-%{_target_vendor}
%{__install} -p -m 744 %{SOURCE1} %{buildroot}%{_datadir}/grub/%{_host_cpu}-%{_target_vendor}

# create compat links
mkdir -p ${RPM_BUILD_ROOT}/%{_sbindir}
for i in grub grub-install grub-set-default grub-md5-crypt grub-terminfo ;do
  ln -sf ../../sbin/$i ${RPM_BUILD_ROOT}/%{_sbindir}/$i
done
mkdir -p ${RPM_BUILD_ROOT}/%{_libdir}
mv ${RPM_BUILD_ROOT}/%{_datadir}/grub ${RPM_BUILD_ROOT}/%{_libdir}/grub
ln -sf ../%{_lib}/grub ${RPM_BUILD_ROOT}/%{_datadir}/grub

rm -f ${RPM_BUILD_ROOT}/%{_infodir}/dir

%clean
rm -rf $RPM_BUILD_ROOT

%post
/sbin/install-info %{_infodir}/grub.info.gz %{_infodir}/dir
/sbin/install-info %{_infodir}/multiboot.info.gz %{_infodir}/dir
%{_datadir}/grub/%{_host_cpu}-%{_target_vendor}/%{defshell}

%preun
if [ $1 = 0 ]; then
	/sbin/install-info --delete %{_infodir}/grub.info.gz %{_infodir}/dir
	/sbin/install-info --delete %{_infodir}/multiboot.info.gz %{_infodir}/dir
fi

%files
%defattr(-,root,root)
%doc COPYING INSTALL README AUTHORS BUGS ChangeLog NEWS THANKS TODO MAINTENANCE
/boot/grub
%if %{efi_support}
%attr(0755,root,root) /boot/efi/EFI/vine
%endif
%{_syssbindir}/*
%{_sbindir}/*
%{_bindir}/*
%{_datadir}/grub
%{_libdir}/grub
%{_infodir}/*.info*
%{_mandir}/man*/*

%changelog
* Sun Aug 16 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 0.97-6
- add Patch 2,3,4,5,6 from fedora
- add Requires: util-linux
- update Patch1002 (grub-0.97-grub-install-vine.patch)

* Sun Jun 14 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 0.97-5
- add BuildRequires: texinfo,gnu-efi
- update Patch0 from fedora
- add Patch1 from fedora
- add Patch1000,1001,1002

* Fri May 27 2011 Daisuke SUZUKI <daisuke@linux.or.jp> 0.97-4
- switch to grub-fedora.git to support new features (ext4/efi/...)

* Wed Mar 23 2011 Daisuke SUZUKI <daisuke@linux.or.jp> 0.97-3
- add Patch110 to support ext4 filesystem
- add Patch120 to build with current binutils
- add Patch130 to build with ncurses-5.6
- add R(post): install-info, grep, sed, coreutils
- add R(preun): install-info
- add BR: compat32-glibc-{devel,static} for x86_64
- add BR: glibc-static

* Wed Jan 21 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 0.97-2
- add patch100 to support newer e2fsprogs

* Fri Aug 15 2008 Shu KONNO <owa@bg.wakwak.com> 0.97-1vl5
- applied new versioning policy, spec in utf-8

* Tue May 22 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 0.97-0vl8
- fix _host_cpu trick

* Tue May 22 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 0.97-0vl7
- add x86_64 to ExclusiveArch:
- add BuildRequires: compat32-glibc-devel for x86_64
- add "-static" to CFLAGS for x86_64
- use special CFLAGS
- add Patch10 to run configure with new binutils

* Thu Sep 07 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 0.97-0vl6
- add PreReq: grep, sed for defaultmenu.sh

* Tue Sep 5 2006 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 0.97-0vl5
- add initrd in menu.lst file created by defaultmenu.sh

* Mon Jun 26 2006 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 0.97-0vl4
- fix date of previous changelog entry
- escape macro of past changelog entries
- change Source1: menu.lst.vine to defautmenu.sh
- invoke defaultmenu.sh on %%post scriptlet

* Wed Jun 21 2006 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 0.97-0vl3
- remove Requires: ncurses, gpm, bash

* Thu May 12 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 0.97-0vl2
- upstream release
- add MAINTENANCE to %%doc
- drop Patch0 (merged in upstream source)

* Sun Mar 20 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 0.96-0vl3
- savedefault patch from upstream CVS: http://savannah.gnu.org/cgi-bin/viewcvs/grub/grub/stage2/stage2.c.diff?r1=1.45&r2=1.46&diff_format=u
  stage2/stage2.c (cmain): Initialize DEFAULT_FILE to an empty
  string. Reported by NATORI Shin <natori@adm.s.u-tokyo.ac.jp>.

* Sun Feb 20 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 0.96-0vl2
- upstream release
- drop Patch0 (merged)
- added sample file /usr/lib/grub/i386-pc/menu.lst.vine
- change installation destination of menu.lst from %%datadir to %%libdir

* Wed Jan 19 2005 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 0.95-0vl3
- applied Patch0 from upstream CVS:
  http://savannah.gnu.org/cgi-bin/viewcvs/grub/grub/util/grub-install.in.diff?r1=1.46&r2=1.47&diff_format=u
  util/grub-install.in (convert): Fix the sed statement for
  Linux. The expression was ambigious in some cases.

* Wed Aug 18 2004 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 0.95-0vl2
- catch up to upstream release
- delete %%_target_platform macro
- delete gzip info files from %%install macro
- add BuildRequires: ncurses-devel
- add Requires: ncurses, gpm, mktemp, bash
- add PreReq: install-info
- %%configure with --disable-auto-linux-mem-opt option

* Thu Jul 12 2001 <sagami@vinelinux.org>
- 0.90-0vl1: %%configure with a trick for _host_cpu, %%makeinstall

* Tue Apr 24 2001 <sagami@vinelinux.org>
- 0.5.96-0vl1: use some macros

* Wed Oct 11 2000 Yoshihiro Kajiki <kajiki@ylug.org> [0vl2]
- build for Vine 2.1beta

* Tue Oct 10 2000 Yoshihiro Kajiki <kajiki@ylug.org> [0vl1]
- update to 0.5.95 and build for Vine 2.0
- add Japanese summary and description
- based on grub-0.5.94-2, Kondara Zoo

* Sun Jun  4 2000 AYUHANA Tomonori <l@kondara.org>
* /usr/doc/grub-*/menu.lst -> /usr/share/grub/i386-pc/menu.lst

* Thu May 18 2000 AYUHANA Tomonori <l@kondara.org>
- upgrade to 0.5.93.1 to 0.5.94
