##
##  exim.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:         exim
Summary:      Exim Mail Transfer Agent
URL:          http://www.exim.org/
Vendor:       Philip Hazel
Packager:     The OpenPKG Project
Distribution: OpenPKG [EVAL]
Group:        Mail
License:      GPL
Version:      4.12
Release:      20021219

#   list of sources
Source0:      ftp://ftp.csx.cam.ac.uk/pub/software/email/exim/exim4/exim-%{version}.tar.bz2
Source1:      exim-man.tar.gz
Source2:      rc.exim

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20020206, perl, gzip, openssl, db >= 4.1.24, tar
PreReq:       OpenPKG, openpkg >= 20020206, perl, gzip
AutoReq:      no
AutoReqProv:  no
Provides:     MTA
Conflicts:    sendmail, postfix, ssmtp

%description
    Exim is a message transfer agent (MTA) developed at the University
    of Cambridge for use on Unix systems connected to the Internet.
    In style it is similar to Smail 3, but its facilities are more
    extensive, and in particular it has some defences against mail
    bombs and unsolicited junk mail in the form of options for refusing
    messages from particular hosts, networks, or senders. It can be
    installed in place of sendmail, although the configuration of Exim
    is quite different to that of Sendmail.

%prep
    %setup -q
    %{l_gzip} -d -c %{SOURCE exim-man.tar.gz} | %{l_tar} xvf -

%build
    cp src/EDITME Local/Makefile
    ( echo "CC=%{l_cc}"
      echo "CFLAGS=%{l_cflags -O}"
      echo "EXIM_UID=%{l_muid}"
      echo "EXIM_GID=%{l_mgid}"
      echo "EXIM_USER=%{l_nusr}"
      echo "EXIM_GROUP=%{l_ngrp}"
      echo "LOG_FILE_PATH=%{l_prefix}/var/exim/log/%s.log"
      echo "PID_FILE_PATH=%{l_prefix}/var/exim/run/%s.pid"
      echo "SPOOL_DIRECTORY=%{l_prefix}/var/exim/spool"
      echo "INFO_DIRECTORY=%{l_prefix}/info"
      echo "SUPPORT_MOVE_FROZEN_MESSAGES=yes"
      echo "SUPPORT_TLS=yes"
      echo "TLS_INCLUDE=-I%{l_prefix}/include"
      echo "TLS_LIBS=-L%{l_prefix}/lib -lssl -lcrypto"
      echo "TRANSPORT_LMTP=yes"
      echo "INCLUDE=-I%{l_prefix}/include"
      echo "DBMLIB=-L%{l_prefix}/lib -ldb"
      echo "USE_DB=yes"
      echo "PERL_COMMAND=%{l_prefix}/bin/perl"
      echo "CHOWN_COMMAND=true"
      echo "NO_SYMLINK=yes"
    ) >>Local/Makefile
    %{l_shtool} subst \
        -e 's;^\(BIN_DIRECTORY=\).*;\1%{l_prefix}/bin;' \
        -e 's;^\(COMPRESS_COMMAND=\).*;\1%{l_prefix}/bin/gzip;' \
        -e 's;^\(ZCAT_COMMAND=\).*;\1%{l_prefix}/bin/zcat;' \
        -e 's;^\(CONFIGURE_FILE=\).*;\1%{l_prefix}/etc/exim/exim.conf;' \
        -e 's;^\(EXIM_MONITOR=.*\);#\1;' \
        Local/Makefile
    %{l_shtool} subst \
        -e 's;^\(CHOWN_COMMAND=\).*;\1true;' \
        OS/Makefile-`uname`

    make="%{l_make}"
    mflags="%{l_mflags}"
    case "%{l_target}" in
        *-freebsd* ) make="make"; mflags=""; PATH="/usr/bin:$PATH" ;;
    esac
    $make $mflags makefile
    $make $mflags

%install
    rm -rf $RPM_BUILD_ROOT

    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/exim \
        $RPM_BUILD_ROOT%{l_prefix}/var/exim/run \
        $RPM_BUILD_ROOT%{l_prefix}/var/exim/log \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8

    %{l_shtool} install -c -m 644 \
        exim-man/*.8 $RPM_BUILD_ROOT%{l_prefix}/man/man8/

    INST_CHOWN=true; export INST_CHOWN
    INST_BIN_DIRECTORY=$RPM_BUILD_ROOT%{l_prefix}/bin; export INST_BIN_DIRECTORY
    INST_CONFIGURE_FILE=$RPM_BUILD_ROOT%{l_prefix}/etc/exim/exim.conf; export INST_CONFIGURE_FILE
    INST_INFO_DIRECTORY=$RPM_BUILD_ROOT%{l_prefix}/info; export INST_INFO_DIRECTORY
    make="%{l_make}"
    mflags="%{l_mflags}"
    case "%{l_target}" in
        *-freebsd* ) make="make"; mflags=""; PATH="/usr/bin:$PATH" ;;
    esac
    $make $mflags install

    mv $RPM_BUILD_ROOT%{l_prefix}/bin/exim-%{version}* \
       $RPM_BUILD_ROOT%{l_prefix}/bin/exim
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true

    ( cd $RPM_BUILD_ROOT%{l_prefix}/sbin
      ln -s ../bin/exim sendmail
      ln -s ../bin/exim mailq
      ln -s ../bin/exim rmail
    )

    ( echo "#!/bin/sh"
      echo "%{l_prefix}/sbin/sendmail -bi"
    ) >$RPM_BUILD_ROOT%{l_prefix}/sbin/newaliases
    chmod 755 $RPM_BUILD_ROOT%{l_prefix}/sbin/newaliases

    %{l_shtool} install -c -m 755 \
        -e 's;@l_prefix@;%{l_prefix};g' \
        %{SOURCE rc.exim} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
         %{l_files_std} \
         '%attr(4755,root,%{l_mgrp}) %{l_prefix}/bin/exim'

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

