##
##  ssmtp.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  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:         ssmtp
Summary:      Simple SMTP Send-Only MTA
URL:          http://alioth.debian.org/projects/ssmtp/
Vendor:       Matt Ryan
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Mail
License:      GPL
Version:      2.64
Release:      20110731

#   package options
%option       with_fsl  yes
%option       with_ssl  no

#   list of sources
Source0:      http://ftp.debian.org/debian/pool/main/s/ssmtp/ssmtp_%{version}.orig.tar.bz2
Source1:      ssmtp.conf
Source2:      rc.ssmtp
Source3:      fsl.ssmtp
Patch0:       ssmtp.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, gcc
PreReq:       OpenPKG, openpkg >= 20160101
%if "%{with_fsl}" == "yes"
BuildPreReq:  fsl
PreReq:       fsl
%endif
%if "%{with_ssl}" == "yes"
BuildPreReq:  openssl
PreReq:       openssl
%endif
Provides:     MTA
Conflicts:    exim, postfix, sendmail

%description
    This is sSMTP, a program that replaces sendmail on workstations
    that should send their mail via the departmental mailhub from which
    they pick up their mail (via pop, imap, rsmtp, pop_fetch, NFS... or
    the like). This program accepts mail and sends it to the mailhub,
    optionally replacing the domain in the From: line with a different
    one.

%track
    prog ssmtp = {
        version   = %{version}
        url       = http://ftp.debian.org/debian/pool/main/s/ssmtp/
        regex     = ssmtp_(__VER__)(\.orig)\.tar\.bz2
    }

%prep
    %setup -q
    %patch -p0

%build
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O} %{l_cppflags}" \
    LDFLAGS="%{l_fsl_ldflags}" \
%if "%{with_ssl}" == "yes"
    LIBS="%{l_fsl_ldflags} %{l_fsl_libs} %{l_ldflags} -lssl -lcrypto" \
%else
    LIBS="%{l_fsl_ldflags} %{l_fsl_libs}" \
%endif
    ./configure \
%if "%{with_ssl}" == "yes"
        --enable-ssl \
%endif
        --prefix=%{l_prefix}
    %{l_make} %{l_mflags}

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/var/ssmtp \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/ssmtp \
        $RPM_BUILD_ROOT%{l_prefix}/man/man5 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8 \
        $RPM_BUILD_ROOT%{l_prefix}/var/ssmtp
    %{l_shtool} install -c -s -m 755 \
        ssmtp $RPM_BUILD_ROOT%{l_prefix}/sbin/
    %{l_shtool} install -c -m 644 \
        -e 's;.B ssmtp;.B %{l_prefix}/sbin/ssmtp;' \
        -e 's;.B /usr/lib/sendmail;.B %{l_prefix}/sbin/sendmail;' \
        ssmtp.8 $RPM_BUILD_ROOT%{l_prefix}/man/man8/
    %{l_shtool} install -c -m 644 \
        -e 's;/usr/lib/sendmail;%{l_prefix}/sbin/sendmail;' \
        newaliases.8 $RPM_BUILD_ROOT%{l_prefix}/man/man8/
    %{l_shtool} install -c -m 644 \
        -e 's;/etc/ssmtp/ssmtp\.conf;%{l_prefix}/etc/ssmtp/ssmtp.conf;' \
        ssmtp.conf.5 $RPM_BUILD_ROOT%{l_prefix}/man/man5/
    ln  $RPM_BUILD_ROOT%{l_prefix}/sbin/ssmtp \
        $RPM_BUILD_ROOT%{l_prefix}/sbin/sendmail
    ln  $RPM_BUILD_ROOT%{l_prefix}/sbin/ssmtp \
        $RPM_BUILD_ROOT%{l_prefix}/sbin/newaliases
    ln  $RPM_BUILD_ROOT%{l_prefix}/man/man8/ssmtp.8 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8/sendmail.8
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE ssmtp.conf} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/ssmtp/
    %{l_shtool} install -c -m 644 revaliases \
        $RPM_BUILD_ROOT%{l_prefix}/etc/ssmtp/ssmtp.revaliases

    #   install run-command script
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.ssmtp} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   install OSSP fsl configuration
    %{l_shtool} mkdir -f -p -m 755 $RPM_BUILD_ROOT%{l_prefix}/etc/fsl
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE fsl.ssmtp} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fsl/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/fsl/fsl.ssmtp' \
        '%config %{l_prefix}/etc/ssmtp/ssmtp.*'

%files -f files

%clean

