##
##  pine.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_here    4.64L
%define       V_real    4.64

#   package information
Name:         pine
Summary:      Programm for Internet News & Email (PINE)
URL:          http://www.washington.edu/pine/
Vendor:       University of Washington
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Mail
License:      Free but restricted
Version:      %{V_here}
Release:      20080101

#   package options
%option       with_ssl   no
%option       with_ldap  no
%option       with_pico  no

#   list of sources
Source0:      ftp://ftp.cac.washington.edu/pine/pine%{V_real}.tar.bz2
Source1:      pine.conf.fixed
Source2:      pine.conf

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, MTA, make, gcc
PreReq:       OpenPKG, openpkg >= 20160101, MTA
%if "%{with_ssl}" == "yes"
BuildPreReq:  openssl
PreReq:       openssl
%endif
%if "%{with_ldap}" == "yes"
BuildPreReq:  openldap
PreReq:       openldap
%endif

%description
    Pine - a Program for Internet News & Email - is a tool for reading,
    sending, and managing electronic messages. Pine was developed by
    Computing & Communications at the University of Washington. Though
    originally designed for inexperienced email users, Pine has evolved
    to support many advanced features, and an ever-growing number of
    configuration and personal-preference options.

%track
    prog pine = {
        version   = %{V_real}
        url       = ftp://ftp.cac.washington.edu/pine/
        regex     = pine(__VER__)\.tar\.bz2
    }

%prep
    %setup -q -n pine%{V_real}

%build
    #   determine build platform
    OS=""
    OS_DEP_FILE=""
    case "%{l_platform -t}" in
        *-freebsd*   ) OS="bsf"; OS_DEP_FILE="pine/osdep/os-bsf.h" ;;
        *-hpux1[01]* ) OS="ghp"; OS_DEP_FILE="pine/osdep/os-ghp.h" ;;
        *-linux*     ) OS="slx"; OS_DEP_FILE="pine/osdep/os-lnx.h" ;;
        *-netbsd*    ) OS="neb"; OS_DEP_FILE="pine/osdep/os-neb.h" ;;
        *-sunos5.*   ) OS="gs5"; OS_DEP_FILE="pine/osdep/os-sol.h" ;;
        *)
            #   take a look at ./doc/pine-ports of the pine tarball
            echo "Sorry, unsupported architecture '%{l_platform -t}'" |\
                %{l_rpmtool} msg -b -t error 1>&2
            exit 1
            ;;
    esac

    #   adjust paths
    PINE_CONF_FIXED="%{l_prefix}/etc/pine/pine.conf.fixed"
    PINE_CONF="%{l_prefix}/etc/pine/pine.conf"
    SENDMAIL="%{l_prefix}/sbin/sendmail"
    %{l_shtool} subst \
         -e "s;^\(#define SYSTEM_PINERC_FIXED[ 	]\).*$;\1 \"$PINE_CONF_FIXED\";" \
         -e "s;^\(#define SYSTEM_PINERC[ 	]\).*$;\1 \"$PINE_CONF\";" \
         -e "s;^\(#define SENDMAIL[ 	]\).*$;\1 \"$SENDMAIL\";" \
         $OS_DEP_FILE
    case "%{l_platform -t}" in
        *-sunos* )
            %{l_shtool} subst \
                -e "s;^#include <stropts.h>;;" \
                pico/osdep/read.pol
            ;;
    esac

    #   clean up before building Pine
    sh ./build clean

    #   set up LDAP build environment
%if "%{with_ldap}" == "yes"
    mkdir ldap
    ln -s %{l_prefix}/include ldap/include
    ln -s %{l_prefix}/lib     ldap/libraries
%endif

    #   build Pine
    cflags="%{l_cflags -O}"
    ldflags="%{l_ldflags}"
%if "%{with_ldap}" == "yes"
    case "%{l_platform -t}" in
        *-sunos5.* ) ldflags="$ldflags -lresolv" ;;
    esac
%endif
    sh ./build \
        CC="%{l_cc}" \
        EXTRACFLAGS="$cflags" \
        EXTRALDFLAGS="$ldflags" \
%if "%{with_ldap}" != "yes"
        NOLDAP \
%endif
%if "%{with_ssl}" == "yes"
        SSLDIR="%{l_prefix}" \
        SSLTYPE="unix" \
%else
        NOSSL \
%endif
        $OS

%install

    #   create directories and install files
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/pine \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1
    %{l_shtool} install -c -s -m 755 \
        bin/pine \
        $RPM_BUILD_ROOT%{l_prefix}/bin/
%if "%{with_pico}" == "yes"
    %{l_shtool} install -c -s -m 755 \
        bin/pico bin/pilot \
        $RPM_BUILD_ROOT%{l_prefix}/bin/
    %{l_shtool} install -c -m 644 \
        doc/pico.1 doc/pilot.1 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1/
%endif
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE pine.conf.fixed} \
        %{SOURCE pine.conf} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/pine/
    %{l_shtool} install -c -m 644 \
        doc/pine.1 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1/

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

%files -f files

%clean

