##
##  ncurses.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 versions
%define       V_base    6.5
%define       V_patch0  20240504
%define       V_patch1  20240511
%define       V_patch2  20240518
%define       V_patch3  20240519
%define       V_patch4  20240525
%define       V_patch5  20240601
%define       V_patch6  20240608
%define       V_patch7  20240615
%define       V_patch8  20240622
%define       V_patch9  20240629
%define       V_patch10 20240706
%define       V_patch11 20240713
%define       V_patch12 20240720
%define       V_patch13 20240727
%define       V_patch14 20240810
%define       V_patch15 20240817
%define       V_patch16 20240824
%define       V_patch17 20240831
%define       V_patch18 20240914
%define       V_patch19 20240922
%define       V_patch20 20240928
%define       V_patch21 20241006
%define       V_patch22 20241019
%define       V_patch23 20241026
%define       V_patch24 20241102
%define       V_patch25 20241109
%define       V_patch26 20241123
%define       V_patch27 20241130
%define       V_patch28 20241207
%define       V_patch29 20241214
%define       V_patch30 20241221
%define       V_patch31 20241228
%define       V_patch32 20250104
%define       V_patch33 20250111
%define       V_patch34 20250118
%define       V_patch35 20250125
%define       V_patch36 20250201
%define       V_patch37 20250208
%define       V_patch38 20250215
%define       V_patch39 20250216
%define       V_patch40 20250222
%define       V_patch41 20250301
%define       V_patch42 20250308
%define       V_patch43 20250315
%define       V_patch44 20250322
%define       V_patch45 20250329
%define       V_patch46 20250405
%define       V_patch47 20250412
%define       V_patch48 20250419
%define       V_patch49 20250426
%define       V_patch50 20250503
%define       V_patch51 20250510
%define       V_patch52 20250517
%define       V_patch53 20250524
%define       V_patch54 20250531
%define       V_patch55 20250614
%define       V_patch56 20250621
%define       V_patch57 20250628
%define       V_patch58 20250705
%define       V_patch59 20250712
%define       V_patch60 20250720
%define       V_patch61 20250726
%define       V_patch62 20250802
%define       V_patch63 20250816
%define       V_patch64 20250823
%define       V_patch65 20250830
%define       V_patch66 20250913
%define       V_patch67 20250920
%define       V_patch68 20250927
%define       V_patch69 20251004
%define       V_patch70 20251010
%define       V_patchL  %{V_patch70}
%define       V_patches 70

#   package information
Name:         ncurses
Summary:      Terminal Capability and Display Library
URL:          https://invisible-island.net/ncurses/
Vendor:       Free Software Foundation
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        CORE
Group:        Terminal
License:      MIT-style
Version:      %{V_base}.%{V_patchL}
Release:      20251011

#   package options
%option       with_widechar  no

#   list of sources
Source0:      https://invisible-mirror.net/archives/ncurses/ncurses-%{V_base}.tar.gz
Patch0:       https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch0}.patch.gz
Patch1:       https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch1}.patch.gz
Patch2:       https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch2}.patch.gz
Patch3:       https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch3}.patch.gz
Patch4:       https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch4}.patch.gz
Patch5:       https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch5}.patch.gz
Patch6:       https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch6}.patch.gz
Patch7:       https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch7}.patch.gz
Patch8:       https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch8}.patch.gz
Patch9:       https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch9}.patch.gz
Patch10:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch10}.patch.gz
Patch11:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch11}.patch.gz
Patch12:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch12}.patch.gz
Patch13:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch13}.patch.gz
Patch14:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch14}.patch.gz
Patch15:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch15}.patch.gz
Patch16:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch16}.patch.gz
Patch17:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch17}.patch.gz
Patch18:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch18}.patch.gz
Patch19:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch19}.patch.gz
Patch20:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch20}.patch.gz
Patch21:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch21}.patch.gz
Patch22:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch22}.patch.gz
Patch23:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch23}.patch.gz
Patch24:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch24}.patch.gz
Patch25:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch25}.patch.gz
Patch26:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch26}.patch.gz
Patch27:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch27}.patch.gz
Patch28:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch28}.patch.gz
Patch29:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch29}.patch.gz
Patch30:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch30}.patch.gz
Patch31:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch31}.patch.gz
Patch32:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch32}.patch.gz
Patch33:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch33}.patch.gz
Patch34:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch34}.patch.gz
Patch35:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch35}.patch.gz
Patch36:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch36}.patch.gz
Patch37:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch37}.patch.gz
Patch38:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch38}.patch.gz
Patch39:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch39}.patch.gz
Patch40:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch40}.patch.gz
Patch41:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch41}.patch.gz
Patch42:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch42}.patch.gz
Patch43:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch43}.patch.gz
Patch44:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch44}.patch.gz
Patch45:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch45}.patch.gz
Patch46:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch46}.patch.gz
Patch47:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch47}.patch.gz
Patch48:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch48}.patch.gz
Patch49:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch49}.patch.gz
Patch50:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch50}.patch.gz
Patch51:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch51}.patch.gz
Patch52:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch52}.patch.gz
Patch53:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch53}.patch.gz
Patch54:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch54}.patch.gz
Patch55:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch55}.patch.gz
Patch56:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch56}.patch.gz
Patch57:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch57}.patch.gz
Patch58:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch58}.patch.gz
Patch59:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch59}.patch.gz
Patch60:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch60}.patch.gz
Patch61:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch61}.patch.gz
Patch62:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch62}.patch.gz
Patch63:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch63}.patch.gz
Patch64:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch64}.patch.gz
Patch65:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch65}.patch.gz
Patch66:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch66}.patch.gz
Patch67:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch67}.patch.gz
Patch68:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch68}.patch.gz
Patch69:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch69}.patch.gz
Patch70:      https://invisible-mirror.net/archives/ncurses/%{V_base}/ncurses-%{V_base}-%{V_patch70}.patch.gz
Patch100:     ncurses.patch

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

%description
    NCurses is the GNU re-implementation of the popular SVR4 Curses
    terminal screen handling library. Its API is base-level conformant
    with the X/OPEN curses specification XSI Curses. It uses the
    Terminfo database format, supports pads and color and multiple
    highlights and forms characters and function-key mapping, and has
    all the other SVR4-Curses enhancements over original BSD Curses.
    Additionally, it provides full emulations of the SVR4 panels
    (supporting a stack of windows), forms (supporting data collection
    through on-screen forms) and menu (supporting a uniform interface
    for menu programming) companion libraries.

%track
    prog ncurses = {
        version   = %{V_base}
        url       = https://invisible-mirror.net/archives/ncurses/
        regex     = ncurses-(__VER__)\.tar\.gz
    }
    prog ncurses:patchset = {
        version   = %{V_patchL}
        url       = https://invisible-mirror.net/archives/ncurses/%{V_base}/
        regex     = ncurses-%{V_base}-(\d+)\.patch\.gz
    }

%prep
    %setup -q -n ncurses-%{V_base}
    if [ ".`which uudecode 2>/dev/null`" = . ]; then
        echo "prerequisite system command uudecode(1) missing" | %{l_rpmtool} msg -b -t error 1>&2
        exit 1
    fi
    find . -name "*.orig" -print | xargs rm -f
    %patch -p0 -P 100
    for patchfile in \
        %{expand:%(i=0; while [ $i -le %{V_patches} ]; do %{l_shtool} echo -n " %%{PATCH$i}"; i=`expr $i + 1`; done)}
    do
        case "$patchfile" in
            *-patch.sh.bz2 ) %{l_bzip2} -d -c $patchfile | %{l_patch} -p1 -f || true ;;
            *-patch.sh.gz  ) %{l_bzip2} -d -c $patchfile | %{l_patch} -p1 -f || true ;;
            *.sh.bz2       ) %{l_bzip2} -d -c $patchfile | sed -e 's;gzip -dc;%{l_gzip} -dc;' -e 's;patch -p1;%{l_patch} -p1 -f;' | sh - || true ;;
            *.sh.gz        ) %{l_gzip}  -d -c $patchfile | sed -e 's;gzip -dc;%{l_gzip} -dc;' -e 's;patch -p1;%{l_patch} -p1 -f;' | sh - || true ;;
            *.patch.bz2    ) %{l_bzip2} -d -c $patchfile | %{l_patch} -p1 -f || true ;;
            *.patch.gz     ) %{l_gzip}  -d -c $patchfile | %{l_patch} -p1 -f || true ;;
            * )
                echo "Unknown patch format" | %{l_rpmtool} msg -b -t error 1>&2
                exit 1
                ;;
        esac
    done

%build
    %{l_shtool} subst \
        -e 's;SRC_SUBDIRS test;SRC_SUBDIRS;' \
        configure
    CC="%{l_cc}" \
    CPPFLAGS="%{l_cppflags}" \
    CFLAGS="%{l_cflags}" \
    ./configure \
        --prefix=%{l_prefix} \
        --includedir=%{l_prefix}/include/ncurses \
        --datadir=%{l_prefix}/share/ncurses \
        --mandir=%{l_prefix}/man \
%if "%{with_widechar}" == "yes"
        --enable-widec \
%else
        --disable-widec \
%endif
        --enable-hashmap \
        --enable-safe-sprintf \
        --without-debug \
        --with-manpage-format=normal \
        --disable-getcap-cache \
        --without-cxx-binding \
        --without-cxx \
        --without-gpm \
        --without-trace \
        --enable-termcap \
        --disable-overwrite
    %{l_make} %{l_mflags}

%install
    %{l_shtool} subst -e "s;ln -s;ln;g" edit_man.sh
    %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
    ( cd $RPM_BUILD_ROOT%{l_prefix}/man
      for dir in man1 man3; do
          cd $dir
          for file in *.[13][a-z]*; do
              if [ ".$file" = ".*.[13][a-z]*" ]; then
                  break
              fi
              eval `echo "$file" | sed -e 's;^\(.*\.[13]\)[a-z]*$;base=\1;'`
              mv $file ncurses_$base
          done
          cd ..
      done
    ) || exit $?
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* 2>/dev/null || true
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

