%define build_kmod 0
%define kversion %(uname -r)
%define kver    %(uname -r | sed -e 's/-/_/g')
%define kflavor %(uname -r | sed -e 's/.*vl.//')
%if "%kflavor" == ""
%undefine kflavor
%endif
%define kmod	kernel-module%{?kflavor:-%{kflavor}}

%define name	pcc-acpi
%define ver	0.9
%define rel	5%{?_dist_release}

Summary:        Hotkey Driver for Panasonic Let's note
Summary(ja):    Panasonic Let's note 用ホットキードライバ
Name:		%{name}
Version:	%{ver}
Release: 	%{rel}

Source0:	%{name}-%{version}.tar.bz2
Patch10:	%{name}-0.9-kernel-2.6.23.patch
Patch11:	%{name}-0.9-kernel-2.6.23_apichange.patch
Patch12:	%{name}-0.9-check_input_register_device.patch
Patch13:	%{name}-0.9-kernel-2.6.26_inputdev_apichange.patch

Source10:	%{name}-kmp.spec

License:	GPL2
Group:		System Environment/Base
URL:            http://www.da-cha.org/letsnote/

BuildRoot:	%{_tmppath}/%{name}-%{version}-root


%description
The Panasonic Hotkey Driver implements hotkey functionality for Panasonic R1(N
variant), R2, R3, T2, W2, and Y2 laptops on linux for machines running a 2.6
kernel.

%description -l ja
Panasonic ホットキードライバは Panasonic の Let's note R1(N以降), R2, R3,
T2, W2, Y2 のホットキー機能を linux-2.6 で利用するためのドライバです。

%package -n dkms-%{name}
Summary:         Panasonic Hotkey Driver
Summary(ja):     Panasonic Let's note 用ホットキードライバ
License:	 GPL2
Group:		 System Environment/Kernel
Requires(pre):   kernel, kernel-devel
Requires(preun): dkms
Requires(post):  dkms

%description -n dkms-%{name}
The Panasonic Hotkey Driver implements hotkey functionality for Panasonic R1(N
variant), R2, R3, T2, W2, and Y2 laptops on linux for machines running a 2.6
kernel.

%description -l ja -n dkms-%{name}
Panasonic ホットキードライバは Panasonic の Let's note R1(N以降), R2, R3,
T2, W2, Y2 のホットキー機能を linux-2.6 で利用するためのドライバです。


%prep
%setup -q
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1


%build


%install
%__rm -rf %{buildroot}

mkdir -p %{buildroot}/usr/src/%{name}-%{version}-%{release}
cp -r *  %{buildroot}/usr/src/%{name}-%{version}-%{release}/

## DKMS.CONF ##
cat > %{buildroot}/usr/src/%{name}-%{version}-%{release}/dkms.conf << EOF

PACKAGE_NAME="pcc-acpi"
PACKAGE_VERSION="%{version}-%{release}"

BUILT_MODULE_NAME[0]="pcc_acpi"
DEST_MODULE_LOCATION[0]="/extra/acpi"
MAKE[0]="make -C \${kernel_source_dir} SUBDIRS=\${dkms_tree}/\${PACKAGE_NAME}/\${PACKAGE_VERSION}/build modules"

AUTOINSTALL="YES"

EOF

## KMP.SPEC ##
sed -e 's|##KMOD_NAME##|%{name}|g' \
    -e 's|##KMOD_VER##|%{version}-%{release}|g' \
    -e 's|##LICENSE##|%{license}|g' \
    %{SOURCE10} > \
    %{buildroot}/usr/src/%{name}-%{version}-%{release}/%{name}-kmp.spec


%clean
%__rm -rf ${RPM_BUILD_ROOT}


%post -n dkms-%{name}
dkms add     -m pcc-acpi -v %{version}-%{release} --rpm_safe_upgrade
dkms mkkmp   -m pcc-acpi -v %{version}-%{release}
dkms build   -m pcc-acpi -v %{version}-%{release} --rpm_safe_upgrade
dkms install -m pcc-acpi -v %{version}-%{release} --rpm_safe_upgrade


%preun -n dkms-%{name}
dkms remove  -m pcc-acpi -v %{version}-%{release} --rpm_safe_upgrade --all || :


%files -n dkms-%{name}
%defattr(-,root,root)
%doc COPYING INSTALL readme.html
%dir /usr/src/%{name}-%{version}-%{release}
/usr/src/%{name}-%{version}-%{release}/*


%changelog
* Sun Apr 26 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 0.9-5
- add Source10 for mkkmp feature

* Thu Apr  9 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 0.9-4
- drop kernel-module-pcc-acpi subpackage; make DKMS-compatible

* Tue Jan 28 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 0.9-3
- add kflavor(pae,smp..) to package name

* Mon Jul 21 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 0.9-2
- add Patch12 to check return value of input_register_device
  and fix minor bug (mdk)
- add Patch13 to build with kernel-2.6.26

* Wed Mar 26 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 0.9-1
- use new versioning policy

* Thu Oct 25 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 0.9-0vl2
- add Patch11 to fix kernel>=2.6.23 apichange (<BTS:0552>)

* Mon Oct 22 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 0.9-0vl1
- new upstream release

* Wed Sep 06 2006 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 0.8.4-0vl2
- fix typo of Group <BTS:VineLinux:148>.

* Wed Aug 02 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 0.8.4-0vl1
- initial build for Vine Linux

