#
# Copyright (c) 2001-2002 Conexant Systems, Inc.
# 
# 1.   Permitted use. Redistribution and use in source and binary forms,
# with or without modification, are permitted under the terms set forth
# herein.
# 
# 2.   Disclaimer of Warranties. CONEXANT AND OTHER CONTRIBUTORS MAKE NO
# REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE.
# IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTIES OF ANY KIND.
# CONEXANT AND OTHER CONTRIBUTORS DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE, GOOD TITLE AND AGAINST INFRINGEMENT.
# 
# This software has not been formally tested, and there is no guarantee that
# it is free of errors including, but not limited to, bugs, defects,
# interrupted operation, or unexpected results. Any use of this software is
# at user's own risk.
# 
# 3.   No Liability.
# 
# (a) Conexant or contributors shall not be responsible for any loss or
# damage to Company, its customers, or any third parties for any reason
# whatsoever, and CONEXANT OR CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY
# ACTUAL, DIRECT, INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL, OR CONSEQUENTIAL
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED, WHETHER IN CONTRACT, STRICT OR OTHER LEGAL THEORY OF
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
# 
# (b) User agrees to hold Conexant and contributors harmless from any
# liability, loss, cost, damage or expense, including attorney's fees,
# as a result of any claims which may be made by any person, including
# but not limited to User, its agents and employees, its customers, or
# any third parties that arise out of or result from the manufacture,
# delivery, actual or alleged ownership, performance, use, operation
# or possession of the software furnished hereunder, whether such claims
# are based on negligence, breach of contract, absolute liability or any
# other legal theory.
# 
# 4.   Notices. User hereby agrees not to remove, alter or destroy any
# copyright, trademark, credits, other proprietary notices or confidential
# legends placed upon, contained within or associated with the Software,
# and shall include all such unaltered copyright, trademark, credits,
# other proprietary notices or confidential legends on or in every copy of
# the 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      @HCFLINUXVERSION@
%define rel      @HCFLINUXRPM_REL@
%define automrecomp 1
%else
%define ver      @HCFLINUXVERSION@k%(eval echo %{_target_kernel} | sed 's/-/_/g')
%define rel      @HCFLINUXRPM_REL@%{_target_distro}
%define automrecomp 0
%endif

%define hcftarget   @HCFTARGET@
%define debug_build @DEBUG_BUILD@

# 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 HCF controllerless modem driver for Linux
Name:      %{hcftarget}modem
ExclusiveOS: Linux
%if "%{_target_kernel}" == "generic"
ExclusiveArch: athlon i686 i586 i486 i386
%else
ExclusiveArch: %{_target_cpu}
%endif
Version:   %ver
Release:   %rel
Vendor:	   MBSI (Marc Boucher) & Conexant Systems Inc.
Copyright: Freely redistributable and some GPL
Group:     System Environment/Kernel
Source:    %{hcftarget}modem-@HCFLINUXVERSION@.tar.gz
Source2:   100498D_RM_HxF_Released.pdf
URL:       http://www.mbsi.ca/cnxtlindrv/hcf
BuildRoot: %{_tmppath}/%{hcftarget}modem-%{PACKAGE_VERSION}-root
Packager:  Marc Boucher <marc+hcf@mbsi.ca>
Requires:  pciutils
Conflicts: hcflinmodem
Autoreq:   0

%if "%{_target_kernel}" == "generic"
%package doc
Group:     Documentation
Summary:   Documentation for Conexant HCF controllerless modems
%endif

%description
Conexant HCF controllerless modem driver for Linux

@LICENSE_FILE@

%if "%{_target_kernel}" == "generic"
%description doc
This package contains the documentation for Conexant HCF controllerless
modems.
%endif

%prep
%setup -q -n %{hcftarget}modem-@HCFLINUXVERSION@

%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}/RedHat/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" HCF_MODS_DIR=binaries/%{_target_cpu}/RedHat/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}/Mandrake/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" HCF_MODS_DIR=binaries/%{_target_cpu}/Mandrake/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}/SuSE/linux-%{_target_kernel} HCF_MODS_DIR=binaries/%{_target_cpu}/SuSE/linux-%{_target_kernel} clean all modules_install || exit $?
		ln -s i386 binaries/i486
		ln -s i386 binaries/i586
		ln -s i386 binaries/i686
		ln -s i386 binaries/athlon
	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}/%{hcftarget}config
%{sbindir}/%{hcftarget}stop

%defattr(0444, root, root, 755)
%dir %{etcdir}/%{hcftarget}
%dir %{etcdir}/%{hcftarget}/inf
%config %{etcdir}/%{hcftarget}/inf/*.inf
%config %{etcdir}/%{hcftarget}/inf/*.cty
%dir %{libdir}/%{hcftarget}
%doc %{libdir}/%{hcftarget}/LICENSE
%dir %{libdir}/%{hcftarget}/modules
%doc %{libdir}/%{hcftarget}/modules/COPYING
%{libdir}/%{hcftarget}/modules/binaries

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

%doc BUGS CHANGES CREDITS FAQ INSTALL LICENSE README

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

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

%preun
if [ -z "${HCF_NOAUTOCONFIG}" ]; then
	%{sbindir}/%{hcftarget}config --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

