###############################################################################
###############################################################################
##
##  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: dlm-kernel
Version: @VERS@
Release: @REL@
License: GPL
Group: System Environment/Kernel
Summary: dlm-kernel - The Distributed Lock Manager kernel modules.
BuildRequires: kernel
BuildRequires: cman-kernheaders >= 2.6.9
%ifarch i686 x86_64 athlon
BuildRequires: kernel-smp
%endif
Conflicts: GFS <= 6.0
Conflicts: GFS-modules GFS-module-smp GFS-module-hugemem
Requires: kernel dlm
Requires: cman-kernel >= 2.6.9
Provides: kernel-modules

Source0: %{name}-%{version}-%{release}.tar.gz

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

%description
dlm-kernel - The Distributed Lock Manager kernel modules.

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

%description -n dlm-kernheaders
The dlm 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`

cp -r `pwd` ../smp

Build_dlm(){
	cpu_type=$1
	flavor=$2
	kernel_src=/lib/modules/${TMP_KVERSION}$flavor/build
	# Kernel tree setup
	if [ -d $kernel_src/. ]; then
		echo "Kernel ${TMP_KVERSION} found."
		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_dlm %{_target_cpu}
%endif

%if %{buildsmp}
cd ../smp
Build_dlm %{_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 dlm-kernheaders
%defattr(-,root,root,-)
%{_includedir}/cluster/dlm.h
%{_includedir}/cluster/dlm_device.h
%doc


%changelog
* Fri Oct 22 2004 Chris Feist <cfeist@redhat.com>
- various bug fixes (new upstream sources)
* Mon Aug 16 2004 Jon Brassow <jbrassow@redhat.com>
- add requires field
* Sat Aug 14 2004 Jon Brassow <jbrassow@redhat.com>
- smp was building but not being packaged
- specify more packages that conflict with this one
* Fri Aug 13 2004 Jon Brassow <jbrassow@redhat.com>
- various bug fixes (new upstream sources)
- no need for make file patch
* Wed Jul 14 2004 Jon Brassow <jbrassow@redhat.com>
- update patch for a Makefile
* Wed Jul 14 2004 Jon Brassow <jbrassow@redhat.com>
- add patch for a Makefile
* Wed Jul 14 2004 Jon Brassow <jbrassow@redhat.com>
- be more explicit in files section
* Wed Jul 14 2004 Jon Brassow <jbrassow@redhat.com>
- bump rev number and fix typo
* Thu Jun 17 2004 Jon Brassow <jbrassow@redhat.com> 
- Initial build.


