##
##  newt.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 0.52.12
%define       V_minor 2
%define       V_tag   fc15

#   package information
Name:         newt
Summary:      S-Lang based Text Terminal Widget Toolkit
URL:          ftp://download.fedora.redhat.com/pub/fedora/linux/development/source/SRPMS/
Vendor:       Eric Troan
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Terminal
License:      LGPL
Version:      %{V_major}.%{V_minor}
Release:      20101112

#   list of sources
Source0:      ftp://download.fedora.redhat.com/pub/fedora/linux/development/source/SRPMS/newt-%{V_major}-%{V_minor}.%{V_tag}.src.rpm
Source1:      newt.pc
Patch0:       newt.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  slang, gettext, libiconv, popt
PreReq:       slang, gettext, libiconv, popt

%description
    Newt is a S-Lang based text terminal Widget toolkit. It was
    originally designed for use in the installer program for Red Hat
    Linux. Newt is not event driven but easy to use. Windows must be
    created and destroyed as a stack (in other words, all Newt windows
    behave as modal dialogs).

%track
    prog newt = {
        version   = %{V_major}-%{V_minor}.%{V_tag}
        url       = ftp://download.fedora.redhat.com/pub/fedora/linux/development/source/SRPMS/
        regex     = newt-(__VER__(\.fc\d+)?)\.src\.rpm
    }

%prep
    #   unpack and patch distribution
    %setup -q -c -T
    %{l_rpm2cpio} %{SOURCE0} | cpio -idvmu
    %{l_gzip} -d -c newt-%{V_major}.tar.gz | %{l_tar} xf -
    %patch -p0 -d newt-%{V_major}
    chmod u+r newt-%{V_major}/*.orig

%build
    #   determine available terminal library
    #   kludge: determine whether vendor termcap, termlib or curses library exists
    #   reason: some brain-dead platforms (like SuSE, etc) have no termcap library installed.
    termlib=""
    echo "int main(int argc, char *argv[]) { return 0; }" >dummy.c
    for lib in termcap termlib curses ncurses; do
        rc=0; %{l_cc} -o dummy dummy.c -l$lib >/dev/null 2>&1 || rc=1
        if [ $rc -eq 0 ]; then termlib="-l$lib"; break; fi
    done
    [ ".$termlib" = . ] && exit 1
    %{l_shtool} install -c \
        -e 's;@version@;%{version};g' \
        -e "s;@libs@;-lslang $termlib;g" \
        %{SOURCE newt.pc} .

    #   build package
    ( cd newt-%{V_major}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      CPPFLAGS="%{l_cppflags}" \
      LDFLAGS="%{l_ldflags}" \
      LIBS="$termlib" \
      ./configure \
          --prefix=%{l_prefix} \
          --mandir=%{l_prefix}/man
      %{l_make} %{l_mflags -O}
    ) || exit $?

%install
    #   install package
    ( cd newt-%{V_major}
      %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
    ) || exit $?

    #   install tutorial as manual page
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/man/cat3
    %{l_shtool} install -c -m 644 \
        newt-%{V_major}/tutorial.txt \
        $RPM_BUILD_ROOT%{l_prefix}/man/cat3/newt.3

    #   install pkgconfig(1) file
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/lib/pkgconfig
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        newt.pc $RPM_BUILD_ROOT%{l_prefix}/lib/pkgconfig/

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

%files -f files

%clean

