#
# Copyright (c) 2003 Linuxant inc.
# Copyright (c) 2001-2003 Conexant Systems, Inc.
#
# NOTE: The use and distribution of this software is governed by the terms in
# the file LICENSE, which is included in the package. You must read this and
# agree to these terms before using or distributing this software.
#

# set _target_kernel to generic if it wasn't defined on the command-line
%if %{expand:%{?_target_kernel:0}%{!?_target_kernel:1}}
%define _target_kernel generic
%endif

%if "%{_target_kernel}" == "generic"
%define ver      @HSFLINUXVERSION@
%define rel      @HSFLINUXRPM_REL@
%define automrecomp 1
%else
%define ver      @HSFLINUXVERSION@k%(eval echo %{_target_kernel} | sed 's/-/_/g')
%define rel      @HSFLINUXRPM_REL@%{_target_distro}
%define automrecomp 0
%endif

%define scr_support @SCR_SUPPORT@
%define dmp_support @DMP_SUPPORT@

# Note that this is NOT a relocatable package

# Even though newer versions of RPM provide definitions for these,
# we must still accomodate the older ones
%define prefix   /usr
%define etcdir   /etc
%define libdir   %{prefix}/lib
%define sbindir  %{prefix}/sbin
%define bindir   %{prefix}/bin

Summary:   Conexant HSF softmodem driver for Linux
Name:      hsflinmodem
ExclusiveOS: Linux
%if "%{_target_kernel}" == "generic"
ExclusiveArch: athlon i686 i586 i386
%else
ExclusiveArch: %{_target_cpu}
%endif
Version:   %ver
Release:   %rel
Vendor:	   Linuxant
Copyright: Copyright (c) 2003 Linuxant inc. All rights reserved.
Group:     System Environment/Kernel
Source:    hsflinmodem-@HSFLINUXVERSION@.tar.gz
Source2:   100498D_RM_HxF_Released.pdf
URL:       http://www.linuxant.com/drivers/hsf
BuildRoot: %{_tmppath}/hsflinmodem-%{PACKAGE_VERSION}-root
Packager:  Linuxant
Requires:  pciutils
Autoreq:   0

%if "%{_target_kernel}" == "generic"
%package doc
Group:     Documentation
Summary:   Documentation for Conexant HSF softmodems
%endif

%description
Conexant HSF softmodem driver for Linux

@LICENSE_FILE@

%if "%{_target_kernel}" == "generic"
%description doc
This package contains the documentation for Conexant HSF softmodems.
%endif

%prep
%setup -q -n hsflinmodem-@HSFLINUXVERSION@

%build
make --quiet --no-print-directory all
%if "%{_target_kernel}" == "generic"

cp %{SOURCE2} .

%else

%if "%{_target_distro}" == "rh"
(
	if cd modules; then
		make --quiet --no-print-directory KERNELSRC=%{_distro_kernels}/%{_target_distro}/linux-%{_target_kernel} DISTRO_CFLAGS="-D__BOOT_KERNEL_H_ -D__BOOT_KERNEL_ENTERPRISE=0 -D__BOOT_KERNEL_SMP=0 -D__BOOT_KERNEL_UP=1 -D__MODULE_KERNEL_%{_target_cpu}=1" HSF_MODS_DIR=binaries/%{_target_cpu}/%{_target_distro}/linux-%{_target_kernel} clean all modules_install || exit $?
	fi
) || exit $?
%endif

%if "%{_target_distro}" == "mdk"
(
	if cd modules; then
		make --quiet --no-print-directory KERNELSRC=%{_distro_kernels}/%{_target_distro}/linux-%{_target_kernel} DISTRO_CFLAGS="-D__BOOT_KERNEL_H_ -D__BOOT_KERNEL_ENTERPRISE=0 -D__BOOT_KERNEL_SMP=0 -D__BOOT_KERNEL_UP=1 -D__MODULE_KERNEL_%{_target_cpu}=1" HSF_MODS_DIR=binaries/%{_target_cpu}/%{_target_distro}/linux-%{_target_kernel} clean all modules_install || exit $?
		ln -s i586 binaries/i686
		ln -s i586 binaries/athlon
	fi
) || exit $?
%endif

%if "%{_target_distro}" == "suse"
(
	if cd modules; then
		make --quiet --no-print-directory KERNELSRC=%{_distro_kernels}/%{_target_distro}/linux-%{_target_kernel} HSF_MODS_DIR=binaries/%{_target_cpu}/%{_target_distro}/linux-%{_target_kernel} clean all modules_install || exit $?
%if "%{_target_cpu}" == "i586"
		for a in i686 athlon; do
%else
		for a in i386 i486 i586 i686 athlon; do
%endif
			[ -e binaries/$a ] || ln -s %{_target_cpu} binaries/$a
		done
	fi
) || exit $?
%endif

%endif

%install
rm -rf $RPM_BUILD_ROOT

make --quiet --no-print-directory ROOT=$RPM_BUILD_ROOT install

%clean
rm -rf $RPM_BUILD_ROOT

%files

%defattr(0555, root, root, 755)

%{sbindir}/hsfconfig
%{sbindir}/hsfinf2bin
%{sbindir}/hsffirm2bin
%{sbindir}/hsfstop

%if %{scr_support}
%{sbindir}/hsfdbgsrv
%{bindir}/qtmodemon
%endif
%if %{dmp_support}
%{sbindir}/hsfdmpsrv
%endif

%defattr(0444, root, root, 755)
%dir %{etcdir}/hsf
%{etcdir}/hsf/*.hex
%dir %{etcdir}/hsf/inf
#%config(missingok) %{etcdir}/hsf/config
%config %{etcdir}/hsf/inf/*.inf
%dir %{libdir}/hsf
%doc %{libdir}/hsf/LICENSE
%dir %{libdir}/hsf/modules
%doc %{libdir}/hsf/modules/COPYING
%{libdir}/hsf/modules/binaries

%if %{automrecomp}
%config %{libdir}/hsf/config.mak
%{libdir}/hsf/imported
%attr(755, root, root) %{libdir}/hsf/modules/*.sh
%{libdir}/hsf/modules/[mM]akefile
%{libdir}/hsf/modules/common.mak
%{libdir}/hsf/modules/*.c
%{libdir}/hsf/modules/*.h
%dir %{libdir}/hsf/modules/osspec
%{libdir}/hsf/modules/osspec/[mM]akefile
%{libdir}/hsf/modules/osspec/*.c
%dir %{libdir}/hsf/modules/osspec/include
%{libdir}/hsf/modules/osspec/include/*.h
%endif

%doc BUGS CHANGES CREDITS FAQ INSTALL LICENSE README

%pre
if [ -e "%{libdir}/hsf" ]; then
	echo "Removing old %{libdir}/hsf"
	rm -rf "%{libdir}/hsf"
else
	exit 0
fi

%post
%if ! %{automrecomp}
HSF_AUTOCONFIG=true
%endif
if [ -n "${HSF_AUTOCONFIG}" -a -z "${HSF_NOAUTOCONFIG}" ]; then
	%{sbindir}/hsfconfig --auto
	exit $?
else
	echo "To complete the installation and configuration of your HSF modem,"
	echo "please run \"hsfconfig\" (or \"%{sbindir}/hsfconfig\")"
	exit 0
fi

%preun
if [ -z "${HSF_NOAUTOCONFIG}" ]; then
	%{sbindir}/hsfconfig --remove
else
	exit 0
fi

%if "%{_target_kernel}" == "generic"
%files doc
%doc *.pdf
%endif

# This must be last since the file CHANGES is automatically appended
%changelog

