##
##  nn.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_major 6.7
%define       V_minor 3

#   package information
Name:         nn
Summary:      No News Is Good News
URL:          http://www.nndev.org/
Vendor:       Kim Fabricius Storm
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        News
License:      BSD-style
Version:      %{V_major}.%{V_minor}
Release:      20080101

#   list of sources
Source0:      ftp://ftp.nndev.org/pub/nn-%{V_major}/nn-%{version}.tar.Z
Patch0:       nn.patch

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

%description
    NN ("No News is Good News") is one of the oldest and most popular
    Usenet News clients.

%track
    prog nn = {
        version   = %{version}
        url       = http://www.nndev.org/
        regex     = nn-(__VER__)\.tar\.Z
    }

%prep
    %setup -q
    %patch -p0

%build
    S="template"; M="template"
    case "%{l_platform -t}" in
        i?86-freebsd*     ) S="freebsd"; M="i80386" ;;
        amd64-freebsd*    ) S="freebsd"; M="i80386" ;;
        sparc64*-freebsd* ) S="freebsd"; M="sparc"  ;;
        *alpha-freebsd*   ) S="freebsd"; M="alpha"  ;;
        ia64-freebsd*     ) S="freebsd"; M="alpha"  ;;
        i?86-netbsd*      ) S="netbsd";  M="i80386" ;;
        i?86-linux*       ) S="linux";   M="i80386" ;;
        sun4*-sunos5*     ) S="sunos5";  M="sparc"  ;;
        i?86*-sunos5*     ) S="sunos5";  M="i80386" ;;
        amd64-sunos5*     ) S="sunos5";  M="i80386" ;;
        * ) echo "Platform \"%{l_platform -t}\" not supported" 1>&2; exit 1 ;;
    esac
    %{l_shtool} install -c -m 644 \
        -e "s;s-sunos5.h;s-${S}.h;" \
        -e "s;m-sparc.h;m-${M}.h;" \
        -e 's;/usr/local/bin;%{l_prefix}/bin;' \
        -e 's;/usr/local/lib/nn;%{l_prefix}/libexec/nn;' \
        -e 's;/usr/local/man/man1;%{l_prefix}/man/man1;' \
        -e 's;/usr/local/man/man8;%{l_prefix}/man/man8;' \
        -e 's;/usr/local/lib/nntp_server;%{l_prefix}/etc/nn/nntp_server;' \
        -e 's;/usr/lib/sendmail;%{l_prefix}/sbin/sendmail;' \
        -e 's;\(OWNER[^"]*"\)news\("\);\1%{l_rusr}\2;' \
        -e 's;\(GROUP[^"]*"\)news\("\);\1%{l_rgrp}\2;' \
        config.h-dist config.h
    %{l_make} %{l_mflags} \
        CC="%{l_cc}" all

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/nn \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/nn \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8
    %{l_shtool} subst \
        -e 's;%{l_prefix}/sbin/sendmail -t;/bin/sh;' \
        -e "s;=\"%{l_prefix};=\"$RPM_BUILD_ROOT%{l_prefix};g" \
        -e "s;=%{l_prefix};=$RPM_BUILD_ROOT%{l_prefix};g" \
        -e "s;) *&;);" \
        inst
    echo "n" | sh ./inst
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

