##
##  elm.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 version
%define       V_base 2.4
%define       V_me   127
%define       V_pl   %nil

#   package information
Name:         elm
Summary:      Electronic Mail
URL:          http://www.elmme-mailer.org/
Vendor:       Dave Taylor et al.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Mail
License:      ELM License
Version:      %{V_base}.%{V_me}%{V_pl}
Release:      20150501

#   list of sources
Source0:      http://www.elmme-mailer.org/elm-%{V_base}ME+%{V_me}.tar.gz
Patch0:       elm.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, ncurses, gcc, make
PreReq:       OpenPKG, openpkg >= 20160101

%description
    Elm (Electronic Mail) is the most popular Mail User Agent (MUA) from
    the good USENET days. It contains enhanced MIME and character set
    support, can read mail from POP or IMAP folders and can pass mail
    to the PGP or GPG programs. It also includes modules for TLS/SSL,
    iconv, and SMTP.

%track
    prog elm = {
        version   = %{V_base}ME+%{V_me}
        url       = http://www.elmme-mailer.org/elm-2.4ME+.html
        regex     = elm-(2.4ME\+1\d+)\.tar\.gz
    }
    prog elm:patches = {
        version   = %{V_base}ME+PL%{V_me}%{V_pl}
        url       = http://www.elmme-mailer.org/elm-2.4ME+.html
        regex     = elm-(2.4ME\+PL1\d+[a-z]?)\.patch\.gz
    }

%prep
    %setup -q -n elm%{V_base}.ME+.%{V_me}
    %patch -p0
    rm -f *.orig

%build
    #   configure program
    %{l_shtool} subst \
        -e 's;d_shared="$define";d_shared="$undef";g' \
        -e 's;install_prefix/var/stage-$package;install_prefix/var/elm;g' \
        -e 's;install_prefix/lib;install_prefix/lib/elm;g' \
        -e 's;shlib="$install_prefix/$libdirname";shlib="$install_prefix/lib/elm";g' \
        -e 's;#! */bin/sh;#!%{l_bash} --noprofile;' \
        -e 's;^(alias);(false);' \
        -e 's;^\(cc=.\)\(.\)$;\1%{l_cc}\2;' \
        -e 's;^\(optimize=.\)\(.\)$;\1%{l_cflags -O}\2;' \
        -e 's;^\(ldflags=.\)\(.\)$;\1%{l_ldflags}\2;' \
        -e 's;\(for A in ..\) \(.-ltermlib.\);\1 -lncurses \2;' \
        -e 's;\(if $cc $ccflags\) \(-o try_term\);\1 $ldflags \2;' \
        -e 's;\(  dflt=\)t$;\1c;' \
        Configure
    expr -P >/dev/null 2>&1 || %{l_shtool} subst -e 's;expr ;expr -- ;g' Configure
    ./Configure -b -P%{l_prefix}

    #   build program
    %{l_make} %{l_mflags -O}

%install
    #   install program
    %{l_shtool} mkdir -f -p -m 755 \
         $RPM_BUILD_ROOT%{l_prefix}/lib/elm
    %{l_shtool} subst \
        -e "s;\\(bin/elmregister master\\);\1 -F %{l_prefix}/lib/elm.filelist -R $RPM_BUILD_ROOT;" \
        -e 's;\(bin/elmregister replay\);#\1;' \
        -e 's;\(bin/elmregister unstage\);#\1;' \
        Makefile
    %{l_make} %{l_mflags} install

    #   strip down installation
    chmod 775 $RPM_BUILD_ROOT%{l_prefix}/bin/*
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/elm.filelist
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/man/cat1
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    strip $RPM_BUILD_ROOT%{l_prefix}/lib/elm/* >/dev/null 2>&1 || true

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

