###############################################################################
###############################################################################
##
##  Copyright (C) 2004 Red Hat, Inc.  All rights reserved.
##
##  This copyrighted material is made available to anyone wishing to use,
##  modify, copy, or redistribute it subject to the terms and conditions
##  of the GNU General Public License v.2.
##
###############################################################################
###############################################################################
%define vers @VERS@
%define rel @REL@

%define buildup 1
%define buildsmp 1
 
%ifnarch i686 x86_64 athlon
%define buildsmp 0
%endif

# ATTENTION -- do we need to obsolete GFS-[modules-][smp | hugemem]?
# Need to set a kernel version for the Requires
Name: cman-kernel
Version: %vers
Release: %rel
License: GPL
Group: System Environment/Kernel
Summary: cman-kernel - The Cluster Manager kernel modules
BuildRequires: kernel
%ifarch i686 x86_64 athlon
BuildRequires: kernel-smp
%endif
Conflicts: GFS <= 6.0
Conflicts: GFS-modules GFS-modules-smp GFS-modules-hugemem
Requires: kernel cman
Provides: kernel-modules
Source0: %{name}-%{version}-%{release}.tar.gz

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot

%description
cman-kernel - The Cluster Manager kernel modules

%package -n cman-kernheaders
Group: Development/System
Summary: cman kernel header files

%description -n cman-kernheaders
The cman kernel headers are used by various cluster packages.

####################################################################################
##  THE PREP SECTION
####################################################################################
%prep
%setup -q -n %{name}-%{version}-%{release}

####################################################################################
##  THE BUILD SECTION
####################################################################################
%build

# When we go production, we must not use TMP_KVERSION.  Instead, we should
# ensure we are using all the right patches, etc.  Use kernel_version, set
# at top of this file.
TMP_KVERSION=`rpm -q --qf '%%{version}-%%{release}' kernel`

BUILD_DIR=`pwd`
cp -r `pwd` ../smp

Build_cman(){
	cpu_type=$1
	flavor=$2
	kernel_src=/lib/modules/${TMP_KVERSION}$flavor/build
	# Kernel tree setup
	if [ -d $kernel_src/. ]; then
		echo $kernel_src
	else
		echo "Kernel ${TMP_KVERSION} not found."
		echo $kernel_src
		ls /lib/modules/*
		exit 1
	fi

	./configure --kernel_src=$kernel_src --incdir=%{_includedir}
	make
}



%if %{buildup}
Build_cman %{_target_cpu}
%endif

%if %{buildsmp}
cd ../smp
Build_cman %{_target_cpu} smp
%endif

####################################################################################
##  THE INSTALL SECTION
####################################################################################
%install
rm -rf $RPM_BUILD_ROOT

%if %{buildup}
make install DESTDIR=$RPM_BUILD_ROOT
%endif

%if %{buildsmp}
cd ../smp
make install DESTDIR=$RPM_BUILD_ROOT
%endif

####################################################################################
##  THE CLEAN SECTION
####################################################################################
%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
/lib/modules
%doc

%files -n cman-kernheaders
%defattr(-,root,root,-)
%{_includedir}/cluster
%doc


%changelog
* Mon Oct 22 2004 <cfeist@redhat.com>
- Various bug fixes (new upstream sources)
* Mon Aug 16 2004 Jon Brassow <jbrassow@redhat.com>
- New install requirements
* Sat Aug 14 2004 Jon Brassow <jbrassow@redhat.com>
- smp modules were being built, but not packaged
- specify more potential conflicts
* Fri Aug 13 2004 Jon Brassow <jbrassow@redhat.com>
- Various bug fixes (new upstream sources)
* Wed Jul 14 2004 Jon Brassow <jbrassow@redhat.com>
- bump rev # and build for i686 as well
* Mon Jul 13 2004 Jon Brassow <jbrassow@redhat.com> 
- bump rev # and build to proper place
* Mon Jul 13 2004 Jon Brassow <jbrassow@redhat.com> 
- Update for new upstream sources.
* Mon Jul 12 2004 Jon Brassow <jbrassow@redhat.com> 
- Update for new upstream sources.
* Thu Jun 17 2004 Jon Brassow <jbrassow@redhat.com> 
- Initial build.
