# 
# Options to rpmbuild
#		--with kernel26
#			Build kernel requires 2.6.x kernel support
#		--without gcc32
#			Use default GCC to build kernel module instead of GCC 3.2
# 

%define k_ver    %(echo ${KVER:-`uname -r`})
%define k_src    %(echo ${KSRC:-/lib/modules/%{k_ver}/build})
%define k_cc     %{?_without_gcc32:gcc}%{!?_without_gcc32:gcc32}
%define k_mod    %{?_with_kernel26:nvidia.ko}%{!?_with_kernel26:nvidia.o}

%define nv_ver   1.0
%define nv_rel   4496
%define nv_url0  http://download.nvidia.com/XFree86/Linux-x86/%{nv_ver}-%{nv_rel}
%define nv_base  NVIDIA-Linux-x86-%{nv_ver}-%{nv_rel}-pkg2
%define nv_src0  %{nv_base}.run
%define nv_url1  http://www.minion.de/files/
%define nv_src1  NVIDIA_kernel-%{nv_ver}-%{nv_rel}-2.6.diff

Name:      nvidia-kernel-%{k_ver}
Version:   %{nv_ver}.%{nv_rel}
Release:   ljb.0
Summary:   NVIDIA Linux Display Driver

Group:     System Environment/Kernel
License:   Proprietary
URL:       http://www.nvidia.com/linux
Source0:   %{nv_url}/%{nv_src0}
Source1:   %{nv_url1}/%{nv_src1}

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: i386

BuildRequires: patch, make, %{!?_without_gcc32:gcc32}%{?_without_gcc32:gcc}

%description
NVIDIA's Linux Display Driver. This package contains the kernel module component 
for kernel %{k_ver}.

%prep
rm -rf %{nv_base}
sh %{_sourcedir}/%{nv_src0} --extract-only
%if %{?_with_kernel26:1}%{!?_with_kernel26:0}
cd %{nv_base}/usr/src/nv
%{__patch} -p1 < %{_sourcedir}/%{nv_src1}
%{__ln_s} Makefile.kbuild Makefile
%endif

%build
if [ ! -f %{k_src}/Makefile -a ! -f %{k_src}/include/linux/uts.h ]; then
	echo Missing %{k_src}/Makefile and/or other files,  bailing out.
	exit 1
fi
cd %{nv_base}/usr/src/nv
%if %{?_with_kernel26:1}%{!?_with_kernel26:0}
%{__make} KERNDIR=%{k_src} CC=%{k_cc} HOSTCC=%{k_cc} module
%else
%{__make} SYSINCLUDE=%{k_src}/include CC=%{k_cc} nvidia.o
%endif

%install
mkdir -p %{buildroot}/usr/share/doc/%{name} \
         %{buildroot}/lib/modules/%{k_ver}/kernel/drivers/video
cd %{_builddir}/%{nv_base}
cp -f LICENSE %{buildroot}/usr/share/doc/%{name}
cp -f usr/src/nv/%{k_mod} %{buildroot}/lib/modules/%{k_ver}/kernel/drivers/video/%{k_mod}

%clean
rm -rf %{buildroot}
rm -rf %{_builddir}/%{nv_base}

%files
%defattr(0644,root,root,0755)
%doc /usr/share/doc/%{name}/LICENSE
%attr(0744,root,root) /lib/modules/%{k_ver}/kernel/drivers/video/*

%changelog
* Mon Nov 10 2003 Leon Breedt <ljb at rpm.bitserf.org> - %{nv_ver}.%{nv_rel}-%{release}
- Initial version
