%define kernelversion %(uname -r)
%define zaptelmoduledir /lib/modules/%{kernelversion}/misc
%define major 10
%define minor 229
%define modconf /etc/modules.conf
%define modules tor2 torisa wcfxo wcfxs wct1xxp wct4xxp wcte11xp wcusb %name ztd-eth ztdummy ztdynamic

%define kernelrel %(uname -r | sed -e s/-/_/g)
%define real_release 1

Name: zaptel
Version: 1.0.9.2
Release: kernel_%{kernelrel}_%{real_release}
Summary: Zapata Telephony Interface Driver
Source: %{name}-%{version}.tar.gz
Copyright: GPL
Group: Kernel
URL: http://digium.com
Buildroot: %{_tmppath}/%{name}-root
Prefix: /usr
Packager: Evgenii Terechkov <evg_krsk@inbox.ru>
BuildRequires: libnewt-devel
%description
ZAPTEL - Zapata Telephony Interface Driver

%package        devel
Summary:        Header files for building third patry software
Group:          Kernel
Requires:       %{name} = %{version}

%description devel
This package contains the development  header files that are needed
to compile 3rd party modules.

%clean

%prep

%setup

%build

%install

for dir in /lib/modules/%{kernelversion}/build   \
        /usr/src/linux-%{kernelversion}         \
        /usr/local/src/linux-%{kernelversion}   ; do 
        if [ -d "$dir" ]; then
                break
        fi
done

%__mkdir_p `dirname $RPM_BUILD_ROOT/%modconf` $RPM_BUILD_ROOT/%{_sysconfdir}/modutils.d
touch $RPM_BUILD_ROOT/%modconf

%__mkdir_p $RPM_BUILD_ROOT/%zaptelmoduledir
%__mkdir_p $RPM_BUILD_ROOT%_initdir
%__mkdir_p $RPM_BUILD_ROOT%_sysconfdir/sysconfig

%__make install KERNEL_SOURCE=$dir INSTALL_PREFIX=$RPM_BUILD_ROOT DYNFS=yes ROOT_PREFIX=$RPM_BUILD_ROOT
%__mv -ff $RPM_BUILD_ROOT/%modconf $RPM_BUILD_ROOT/%{_sysconfdir}/modutils.d/%name
%__make config CHKCONFIG=: INSTALL_PREFIX=$RPM_BUILD_ROOT

%post
mkdir -p /dev/zap
rm -rf /dev/zap/* ||:
mknod /dev/zap/ctl c 196 0 ||:
mknod /dev/zap/timer c 196 253 ||:
mknod /dev/zap/channel c 196 254 ||:
mknod /dev/zap/pseudo c 196 255 ||:
N=1
while [ $N -lt 250 ];
do
        mknod /dev/zap/$N c 196 $N ||:
        N=$[$N+1];
done
/sbin/depmod -aq

%preun
for i in %modules;
do
        /sbin/modprobe -r %{name} ||:
done

%postun
/sbin/depmod -aq

%files
%config
%_initdir/*
%_sysconfdir/%{name}*
#.conf
%_sysconfdir/sysconfig/%name
%_sysconfdir/sysconfig/network-scripts/*
%{_sysconfdir}/modutils.d/%name
%{zaptelmoduledir}
%{_libdir}/*
/sbin/*

%doc ChangeLog LICENSE README*

%files devel
%{_includedir}/*.h
%{_includedir}/linux/*
