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

# 64bit intel machines use 32bit 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}
%define _libdir %{_prefix}/lib
%define _lib lib
%endif

%define defshell defaultmenu.sh

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

Source0: ftp://alpha.gnu.org/gnu/grub/grub-%{version}.tar.xz
Source1: 90_persistent
Source2: grub.default

ExclusiveArch: %{ix86} x86_64
BuildRoot: %{_tmppath}/%{name}-%{version}-root
Requires(pre): install-info, sed, grep
Requires: mktemp
BuildRequires: autogen
BuildRequires: ncurses-devel
BuildRequires: bison
BuildRequires: flex
BuildRequires: ruby
BuildRequires: freetype2-devel
%ifarch x86_64
BuildRequires: compat32-glibc-devel
%endif

Vendor: Project Vine
Distribution: Vine Linux

%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 -n grub-%{version}

%build
sh autogen.sh

GCCVERS=$(gcc --version | head -1 | cut -d\  -f3 | cut -d. -f1)
CFLAGS="-Os"
if [ "$GCCVERS" == "4" ]; then
  CFLAGS="$CFLAGS -Wno-pointer-sign"
fi
%ifarch x86_64
CFLAGS="$CFLAGS -static" 
%endif
export CFLAGS
%configure \
	CFLAGS="$(echo $RPM_OPT_FLAGS | sed		\
		-e 's/-fstack-protector//g'		\
		-e 's/--param=ssp-buffer-size=4//g'	\
		-e 's/-mregparm=3/-mregparm=4//g'	\
		-e 's/-fasynchronous-unwind-tables//g' )"\
	TARGET_LDFLAGS=-static				\
%ifarch x86_64
	--host=i686-pc-linux-gnu \
%endif
	--with-platform=pc \
	--program-transform-name=s,grub,%{name}, \
	--disable-efiemu \
	--disable-grub-emu-usb \
	--disable-grub-emu-sdl \
	--disable-grub-emu-pci \
	--enable-grub-fstest \
	--enable-grub-mkfont

make %{?_smp_mflags}

%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT

# 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

rm -rf $RPM_BUILD_ROOT%{_infodir}

rm -rf $RPM_BUILD_ROOT%{_datadir}/locale

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


%clean
rm -rf $RPM_BUILD_ROOT

%post
# 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

%preun
# XXX Ugly
rm -f /boot/%{name}/*.mod
rm -f /boot/%{name}/*.img
rm -f /boot/%{name}/*.lst
rm -f /boot/%{name}/device.map


%files
%defattr(-,root,root)
%doc COPYING INSTALL README AUTHORS ChangeLog NEWS THANKS TODO
%{_bindir}/*
%{_sbindir}/*
%{_prefix}/lib/grub
%{_prefix}/lib/%{name}
%{_sysconfdir}/bash_completion.d/grub
%{_sysconfdir}/default/grub
%{_sysconfdir}/grub.d
%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}

%changelog
* Wed Aug 17 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 1.99-1
- initial build for Vine Linux

