##
##  qpopper.spec -- OpenPKG RPM Specification
##  Copyright (c) 2000-2003 Cable & Wireless Deutschland GmbH
##  Copyright (c) 2000-2003 The OpenPKG Project <http://www.openpkg.org/>
##  Copyright (c) 2000-2003 Ralf S. Engelschall <rse@engelschall.com>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 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.
##

#   package information
Name:         qpopper
Summary:      POP3 Daemon
URL:          http://www.eudora.com/qpopper/
Vendor:       Qualcom
Packager:     The OpenPKG Project
Distribution: OpenPKG [BASE]
Group:        Mail
License:      GPL
Version:      4.0.4
Release:      20030103

#   package options
%option       with_pam  no

#   list of sources
Source0:      ftp://ftp.qualcomm.com/eudora/servers/unix/popper/qpopper%{version}.tar.gz
Source1:      rc.qpopper
Source2:      fsl.qpopper
Patch0:       qpopper.patch

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20030103, MTA, openssl, fsl
PreReq:       OpenPKG, openpkg >= 20030103, MTA, openssl, fsl
%if "%{with_pam}" == "yes"
BuildPreReq:  PAM
PreReq:       PAM
%endif
AutoReq:      no
AutoReqProv:  no
Provides:     POP

%description
    Qualcom Popper is a full-featured POP3 daemon.

%prep
    %setup -q -n qpopper%{version}
    %patch -p0

%build
    #   build qpopper
    CC="%{l_cc}" \
    CFLAGS="`%{l_prefix}/bin/fsl-config --all --cflags`" \
    CPPFLAGS="`%{l_prefix}/bin/fsl-config --all --cflags`" \
    LDFLAGS="`%{l_prefix}/bin/fsl-config --all --ldflags`" \
    LIBS="`%{l_prefix}/bin/fsl-config --all --libs`" \
%if "%{with_pam}" == "yes"
    CFLAGS="$CFLAGS -I`%{l_prefix}/etc/rc --query pam_incdir`" \
    CPPFLAGS="$CPPFLAGS -I`%{l_prefix}/etc/rc --query pam_incdir`" \
    LDFLAGS="$LDFLAGS -L`%{l_prefix}/etc/rc --query pam_libdir`" \
%endif
    OS_DEFS="-DPIDFILE=\\\"%{l_prefix}/var/qpopper/qpopper.pid\\\"" \
    ./configure \
        --prefix=%{l_prefix} \
        --sbindir=%{l_prefix}/sbin \
        --disable-bulldb \
        --enable-servermode \
        --enable-standalone \
        --enable-log-login \
%if "%{with_pam}" == "yes"
        --with-pam=qpopper \
%endif
        --enable-home-dir-mail=.mail/inbox \
        --with-log-facility=LOG_MAIL \
        --enable-nonauth-file=%{l_prefix}/etc/qpopper/users.deny \
        --with-openssl=%{l_prefix} \
        --disable-nls
    %{l_shtool} subst \
        -e 's;\(MAIL_COMMAND[^"]*"\)[^"]*;\1%{l_prefix}/sbin/sendmail;' \
        config.h
    %{l_make} %{l_mflags -O}

%install
    rm -rf $RPM_BUILD_ROOT

    #   create installation area
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8 \
        $RPM_BUILD_ROOT%{l_prefix}/var/qpopper \
        $RPM_BUILD_ROOT%{l_prefix}/etc/qpopper \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fsl

    #   install qpopper
    %{l_shtool} install -c -m 644 \
        samples/qpopper.config $RPM_BUILD_ROOT%{l_prefix}/etc/qpopper/
    %{l_shtool} install -c -s -m 755 \
        popper/popper $RPM_BUILD_ROOT%{l_prefix}/sbin/qpopper
    %{l_shtool} install -c -m 644 \
        man/popper.8 $RPM_BUILD_ROOT%{l_prefix}/man/man8/qpopper.8

    #   add more stuff
    %{l_shtool} install -c -m 644 \
        /dev/null $RPM_BUILD_ROOT%{l_prefix}/etc/qpopper/users.deny
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
    %{l_shtool} install -c -m 755 \
        -e 's;@l_prefix@;%{l_prefix};g' \
        -e 's;@l_musr@;%{l_musr};g' \
        -e 's;@l_mgrp@;%{l_mgrp};g' \
        %{SOURCE rc.qpopper} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_shtool} install -c -m 644 -e 's;@l_prefix@;%{l_prefix};g' \
        %{SOURCE fsl.qpopper} $RPM_BUILD_ROOT%{l_prefix}/etc/fsl/

    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std} \
        '%config %{l_prefix}/etc/qpopper/qpopper.config' \
        '%config %{l_prefix}/etc/fsl/fsl.qpopper' \
        '%not %dir %{l_prefix}/etc/fsl'

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

%post
%if "%{with_pam}" == "yes"
    #   add PAM configuration entry
    if [ $1 -eq 1 ]; then
        $RPM_INSTALL_PREFIX/sbin/pamtool --add --smart --name=qpopper
    fi
%endif

%preun
%if "%{with_pam}" == "yes"
    #   remove PAM configuration entry
    if [ $1 -eq 0 ]; then
        $RPM_INSTALL_PREFIX/sbin/pamtool --remove --smart --name=qpopper
    fi
%endif

