##
##  ytree.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:         ytree
Summary:      Filesystem Tree Browser
URL:          http://www.han.de/~werner/ytree.html
Vendor:       Werner Bregulla
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Terminal
License:      GPL
Version:      2.10
Release:      20250213

#   list of sources
Source0:      http://www.han.de/~werner/ytree-%{version}.tar.gz
Patch0:       ytree.patch

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

%description
    ytree(1) is a full-screen filesystem tree and archive format manager
    similar to the popular DOS-XTREE(tm). It understands the archive
    formats RAR, SPM, RPM, TAR, ARC, LHA, ZIP, and ZOO.

%track
    prog ytree = {
        version   = %{version}
        url       = http://www.han.de/~werner/ytree.html
        regex     = ytree-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %patch -p0

%build
    #   determine available terminal library
    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

    #   determine standard set of build-time flags
    export CC="%{l_cc}"
    export ADD_CFLAGS="%{l_cflags -O} %{l_cppflags ncurses .} -DNCURSES"
    export LDFLAGS="%{l_ldflags} -lreadline -lncurses $termlib"

    #   determine platform specific build-time flags extensions
    case "%{l_platform -t}" in
        *-freebsd* ) LDFLAGS="$LDFLAGS -lcompat" ;;
        *-sunos*   ) ADD_CFLAGS="$ADD_CFLAGS -DSVR4" ;;
    esac

    #   build program
    %{l_make} %{l_mflags} \
        CC="$CC" ADD_CFLAGS="$ADD_CFLAGS" \
        LDFLAGS="$LDFLAGS"

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1 \
        $RPM_BUILD_ROOT%{l_prefix}/share/ytree
    %{l_shtool} install -c -s -m 755 \
        ytree $RPM_BUILD_ROOT%{l_prefix}/bin/
    %{l_shtool} install -c -m 644 \
        ytree.1 $RPM_BUILD_ROOT%{l_prefix}/man/man1/
    %{l_shtool} install -c -m 644 \
        ytree.conf $RPM_BUILD_ROOT%{l_prefix}/share/ytree/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

