File ncurses.spec of Package ncurses.32650

#
# spec file for package ncurses
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


Name:           ncurses
#!BuildIgnore: terminfo
BuildRequires:  gcc-c++
BuildRequires:  pkg-config
BuildRequires:  screen
%if 0%{?suse_version} > 1130
BuildRequires:  gpm-devel
%else
BuildRequires:  gpm
%endif
%define terminfo() %{_datadir}/%{0}/%{1}
%define tabset()   %{_datadir}/%{0}/%{1}
# bug437293
%ifarch ppc64
Obsoletes:      ncurses-64bit
%endif
#
Version:        5.9
Release:        0
Summary:        New curses Libraries
#Git:           http://ncurses.scripts.mit.edu
License:        MIT
Group:          System/Base
URL:            http://invisible-island.net/ncurses/ncurses.html
Source0:        ncurses-%{version}.tar.bz2
Source1:        ncurses-%{version}-patches.tar.bz2
Source2:        handle.linux
Source3:        README.devel
Source4:        ncurses-rpmlintrc
Source5:        tack-1.07-20120916.tar.bz2
Source6:        edit.sed
Source7:        baselibs.conf
Patch0:         ncurses-%{version}.dif
Patch1:         ncurses-5.9-ibm327x.dif
Patch3:         ncurses-5.9-overwrite.dif
Patch4:         ncurses-5.7-tack.dif
# PATCH-FIX-UPSTREAM for bsc#1046853 and bsc#1046858
Patch5:         ncurses-5.9-bsc1046853_1046858.dif
# PATCH-FIX-UPSTREAM for bsc#1056127, bsc#1056128, bsc#1056129, bsc#1056131, bsc#1056132, and bsc#1056136
Patch6:         ncurses-5.9-bsc10561xxx.patch
# PATCH-FIX-UPSTREAM for bsc#1115929
Patch7:         ncurses-5.9-bsc1115929.patch
# PATCH-FIX-BACKPORT for bsc#1131830
Patch8:         ncurses-5.9-bsc1131830.patch
# PATCH-FIX-UPSTREAM for bsc#1154036, CVE-2019-17594
Patch9:         CVE-2019-17594.patch
# PATCH-FIX-UPSTREAM for bsc#1154037, CVE-2019-17595
Patch10:        CVE-2019-17595.patch
# PATCH-FIX-UPSTREAM for bsc#1198627, CVE-2022-29458
Patch11:        ncurses-bnc1198627.patch
# PATCH-FIX-UPSTREAM for bsc#1190793, CVE-2021-39537
Patch20:        bsc1190793-63ca9e06.patch
# PATCH-FIX-UPSTREAM for bsc#1218014 -- Fix for CVE-2023-50495
Patch22:        bsc1218014-cve-2023-50495.patch
# PATCH-FIX-UPSTREAM for bsc#1220061 -- Fix for CVE-2023-45918
Patch23:        ncurses-5.9-bsc1220061.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%global         _sysconfdir /etc
%global         _miscdir    %{_datadir}/misc
%global         _incdir     %{_includedir}
%global         root        %{_tmppath}/%{name}-%{version}-store
%global         abi         %(ver=%{version}; echo ${ver%.*})

%description
As soon as a text application needs to directly control its output to
the screen (if it wants to place the cursor at location (x,y) then
write text), ncurses is used. The panel and the forms libraries are
included in this package. These new libraries support color, special
characters, and panels.



Authors:
--------
    Thomas E. Dickey <dickey@invisible-island.net>
    Juergen Pfeifer <Juergen.Pfeifer@t-online.de>
    Eric S. Raymond <esr@thyrsus.com>
    Zeyd M. Ben-Halim <zmbenhal@netcom.com>
    Pavel Curtis

%package -n ncurses-utils
Summary:        Tools using the new curses libraries
License:        MIT
Group:          System/Base
Provides:       ncurses:%{_bindir}/tput

%description -n ncurses-utils
The ncurses based utilities are as follows:

clear -- emits clear-screen for current terminal

tabs -- set tabs on a terminal

toe   -- table of entries utility

tput  -- shell-script access to terminal capabilities.

tset  -- terminal-initialization utility

reset -- terminal initialization utility



Authors:
--------
    Thomas E. Dickey <dickey@invisible-island.net>
    Eric S. Raymond <esr@thyrsus.com>
    Zeyd M. Ben-Halim <zmbenhal@netcom.com>
    Juergen Pfeifer <Juergen.Pfeifer@t-online.de>
    Pavel Curtis

%package -n terminfo-base
Summary:        A terminal descriptions database
License:        MIT
Group:          System/Base
Provides:       ncurses:%{_datadir}/tabset

%description -n terminfo-base
This is the terminfo basic database, maintained in the ncurses package.
This database is the official successor to the 4.4BSD termcap file and
contains information about any known terminal. The ncurses library
makes use of this database to use terminals correctly.



Authors:
--------
    Thomas E. Dickey <dickey@invisible-island.net>
    Eric S. Raymond <esr@thyrsus.com>

%if %abi == 5

%package -n libncurses5
Summary:        The New curses Libraries
License:        MIT
Group:          System/Libraries
Requires:       terminfo-base
Provides:       ncurses = %{version}
Obsoletes:      ncurses < %{version}
Recommends:     ncurses-utils = %{version}
# bug437293
%ifarch ppc64
Obsoletes:      ncurses-64bit
%endif
#

%description -n libncurses5
The ncurses library is used by the most curses based terminal
applications for controling its output and input to the screen.



Authors:
--------
    Thomas E. Dickey <dickey@invisible-island.net>
    Eric S. Raymond <esr@thyrsus.com>
    Zeyd M. Ben-Halim <zmbenhal@netcom.com>
    Juergen Pfeifer <Juergen.Pfeifer@t-online.de>
    Pavel Curtis

%endif

%package -n libncurses6
Summary:        The New curses Libraries
License:        MIT
Group:          System/Libraries
Requires:       terminfo-base
%if %abi == 5
Provides:       ncurses = 6.0
%else
Provides:       ncurses = %{version}
%endif

%description -n libncurses6
The ncurses library is used by the most curses based terminal
applications for controling its output and input to the screen.



Authors:
--------
    Thomas E. Dickey <dickey@invisible-island.net>
    Juergen Pfeifer <Juergen.Pfeifer@t-online.de>
    Eric S. Raymond <esr@thyrsus.com>
    Zeyd M. Ben-Halim <zmbenhal@netcom.com>
    Pavel Curtis

%package -n terminfo
Summary:        A terminal descriptions database
License:        SUSE-Public-Domain
Group:          System/Base

%description -n terminfo
This is the terminfo reference database, maintained in the ncurses
package. This database is the official successor to the 4.4BSD termcap
file and contains information about any known terminal. The ncurses
library makes use of this database to use terminals correctly. If you
just use the Linux console, xterm, and VT100, you probably will not
need this database -- a minimal /usr/share/terminfo tree for these
terminals is already included in the terminfo-base package.



Authors:
--------
    Eric S. Raymond <esr@thyrsus.com>
    Thomas E. Dickey <dickey@invisible-island.net>

%package -n ncurses-devel
Summary:        Include Files and Libraries mandatory for Development
License:        MIT
Group:          Development/Libraries/C and C++
Provides:       ncurses:%{_incdir}/ncurses.h
Requires:       %{_bindir}/tack
Requires:       ncurses = %{version}-%{release}
%if %abi >= 6
Requires:       libncurses6 = %{version}-%{release}
%else
Requires:       libncurses5 = %{version}-%{release}
Requires:       libncurses6 = %{version}-%{release}
%endif
# bug437293
%ifarch ppc64
Obsoletes:      ncurses-devel-64bit
%endif
#

%description -n ncurses-devel
This package contains all necessary include files and libraries needed
to develop applications that require these.



Authors:
--------
    Thomas E. Dickey <dickey@invisible-island.net>
    Juergen Pfeifer <Juergen.Pfeifer@t-online.de>
    Eric S. Raymond <esr@thyrsus.com>
    Zeyd M. Ben-Halim <zmbenhal@netcom.com>
    Pavel Curtis

%package -n tack
Summary:        Terminfo action checker
License:        GPL-2.0-or-later
Group:          Development/Tools/Building
Provides:       ncurses-devel:%{_bindir}/tack
Requires:       ncurses = %{version}-%{release}

%description -n tack
This package contains the tack utility to help to build a new terminfo
entry describing an unknown terminal. It can also be used to test the
correctness of an existing entry, and to develop the correct pad
timings needed to ensure that screen updates do not fall behind the
incoming data stream.



Authors:
--------
    Daniel Weaver <danw@znyx.com>
    Eric S. Raymond <esr@thyrsus.com>

%prep
%setup -q -n ncurses-%{version}
rm -fr tack
rm -f  Ada95/src/terminal_interface-curses.adb
rm -f  mkinstalldirs
tar Oxfj %{S:1} | patch -p1 -s
tar  xfj %{S:5}
mv tack-* tack
%patch -P 1 -p0 -b .327x
%patch -P 3 -p0 -b .ow
%patch -P 4 -p0 -b .hs
%patch -P 5 -p0 -b .bo
%patch -P 6 -p0 -b .bx
%patch -P 7 -p0 -b .by
%patch -P 8 -p0 -b .bz
%patch -P 9 -p0 -b .p9
%patch -P 10 -p0 -b .p10
%patch -P 11 -p0 -b .p11
%patch -P 20 -p0 -b .p20
%patch -P 22 -p0 -b .p22
%patch -P 23 -p0 -b .p23
%patch -P 0 -p0 -b .p0
rm -vf include/ncurses_dll.h
rm -vf mkdirs.sh
rm -vf tar-copy.sh
rm -vf mk-dlls.sh

%build
%global _configure	screen -L -D -m ./configure
    SCREENDIR=$(mktemp -d ${PWD}/screen.XXXXXX) || exit 1
    SCREENRC=${SCREENDIR}/ncurses
    export SCREENRC SCREENDIR
    exec 0< /dev/null
    SCREENLOG=${SCREENDIR}/log
    cat > $SCREENRC<<-EOF
	deflogin off
	logfile $SCREENLOG
	logfile flush 1
	logtstamp off
	log on
	setsid on
	scrollback 0
	silence on
	utf8 on
	EOF
    cflags ()
    {
	local flag=$1; shift
	local var=$1; shift
	test -n "${flag}" -a -n "${var}" || return
	case "${!var}" in
	*${flag}*) return
	esac
	set -o noclobber
	case "$flag" in
	-Wl,*)
	    if echo 'int main () { return 0; }' | \
	       ${CC:-gcc} -Werror $flag -o /dev/null -xc - > /dev/null 2>&1 ; then
		eval $var=\${$var:+\$$var\ }$flag
	    fi
	    ;;
	*)
	    if ${CC:-gcc} -Werror $flag -S -o /dev/null -xc /dev/null > /dev/null 2>&1 ; then
		eval $var=\${$var:+\$$var\ }$flag
	    fi
	    if ${CXX:-g++} -Werror $flag -S -o /dev/null -xc++ /dev/null > /dev/null 2>&1 ; then
		eval $var=\${$var:+\$$var\ }$flag
	    fi
	esac
	set +o noclobber
    }

    test ! -f /.buildenv || . /.buildenv
       OPATH=$PATH
%ifarch s390x s390
      FALLBK="xterm,ibm327x,vt100,vt102,vt220"
%else
      FALLBK="xterm,linux,vt100,vt102"
%endif
	  CC=gcc
	 CXX=g++
    CFLAGS="${RPM_OPT_FLAGS} -pipe -D_REENTRANT"
    if [[ "$BUILD_BASENAME" = debug-* ]] ; then
	CFLAGS="${CFLAGS} -g -DTRACE"
    fi
    cflags -Wl,-O2                  LDFLAGS
    cflags -Wl,-Bsymbolic-functions LDFLAGS
    cflags -Wl,--hash-size=8599     LDFLAGS
    cflags -Wl,--as-needed          LDFLAGS
    CXXFLAGS=$CFLAGS
    test -n "$TERM" || TERM=linux
    GZIP="-9"
    export CC CFLAGS CXX CXXFLAGS GZIP TERM LDFLAGS
    #
    # Detect 64bit architecures and be sure that
    # we use an unsigned long for chtype to be
    # backward compatible with ncurses 5.4
    #
    echo 'int main () { return !(sizeof(void*) >= 8); }' | gcc -x c -o test64 -
    if ./test64 ; then
	WITHCHTYPE="--with-chtype=long"
    else
	WITHCHTYPE=""
	CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCES -D_FILE_OFFSET_BITS=64"
    fi
    rm -f ./test64
    #
    # For security of some configure and install scripts
    #
    TMPDIR=$(mktemp -d /tmp/ncurses.XXXXXXXX) || exit 1
    trap 'rm -rf ${TMPDIR}' EXIT
    export TMPDIR
    #
    # No --enable-term-driver as this had crashed last time
    # in ncurses/tinfo/lib_setup.c due to the fact that
    # _nc_globals.term_driver was a NULL function pointer
    #
    # No --enable-tcap-names because we may have to recompile
    # programs or foreign programs won't work
    #
    # No --enable-safe-sprintf because this seems to
    # crash on some architectures
    #
    # No --enable-xmc-glitch because this seems to break yast2
    # on console/konsole (no magic cookie support on those?)
    #
    # No --with-termlib=tinfo because libncurses depend on
    # libtinfo (is linked with) and therefore there is no
    # advantage about splitting of a libtinfo (IMHO).
    #
    touch --reference=README config.sub config.guess
    > $SCREENLOG
    tail -q -s 0.5 -f $SCREENLOG & pid=$!
    %configure \
	--without-ada		\
	--without-debug		\
	--without-profile	\
	--without-manpage-tbl	\
	--with-shared		\
	--with-normal		\
	--with-manpage-format=gzip \
	--with-manpage-renames=${PWD}/man/man_db.renames \
	--with-manpage-aliases	\
	--with-ospeed=speed_t	\
	--with-gpm		\
	--with-dlsym		\
	--with-termlib=tinfo	\
	--with-ticlib=tic	\
	--with-xterm-kbs=del	\
	--disable-root-environ	\
	--disable-termcap	\
	--disable-overwrite	\
	--disable-rpath		\
	--disable-rpath-hack	\
	--disable-leaks		\
	--disable-xmc-glitch	\
	--enable-symlinks	\
	--enable-big-core	\
	--enable-const		\
	--enable-hashmap	\
	--enable-no-padding	\
	--enable-symlinks	\
	--enable-sigwinch	\
	--enable-colorfgbg	\
	--enable-sp-funcs	\
%if %abi >= 6
	--with-pthread		\
	--enable-reentrant	\
	--enable-ext-mouse	\
	--disable-widec		\
	--enable-ext-colors	\
%else
	--without-pthread	\
	--disable-reentrant	\
	--disable-ext-mouse	\
	--disable-widec		\
	--disable-ext-colors	\
%endif
	--enable-weak-symbols	\
	--enable-wgetch-events	\
	--enable-pthreads-eintr	\
	--enable-string-hacks	\
	--prefix=%{_prefix}	\
	--exec-prefix=%{_prefix}\
	--libdir=%{_libdir}	\
	--datadir=%{_datadir}	\
	--mandir=%{_mandir}	\
	--includedir=%{_incdir}	\
	"${WITHCHTYPE}" 	\
	--disable-widec		\
	--disable-tic-depends	\
	--with-cxx-shared	\
	--with-ticlib=tic	\
	--with-pc-suffix	\
	--enable-pc-files	\
	--with-pkg-config-libdir=%{_libdir}/pkgconfig
    kill $pid
    #
    #  The configure line
    #
    c=$(grep '^ *$ *\./configure' config.log)
    #
    # This is a hack to be able to boot strap
    # a libncurses with correct fallback.c.
    #
    make %{?_smp_mflags} -C include
    make %{?_smp_mflags} -C ncurses fallback.c FALLBACK_LIST=""
    make %{?_smp_mflags} -C progs   termsort.c transform.h infocmp tic
    rm   -f ncurses/fallback.c
    PATH=$PWD/progs:$OPATH
    LD_LIBRARY_PATH=$PWD/lib
    export LD_LIBRARY_PATH PATH
    pushd ncurses/
	TERMINFO=$PWD/tmp
	export TERMINFO
	mkdir -p $TERMINFO
	cp -p $PWD/../progs/tic $PWD/../progs/tic.build
	cp -p $PWD/../progs/infocmp $PWD/../progs/infocmp.build
	(cat > ${PWD}/.build_tic)<<-EOF
%if 0%{?_crossbuild}
		export BUILD_TIC=/usr/bin/tic
		export BUILD_INFOCMP=/usr/bin/infocmp
%else
		export BUILD_TIC=$PWD/../progs/tic.build
		export BUILD_INFOCMP=$PWD/../progs/infocmp.build
%endif
	EOF
	. ${PWD}/.build_tic
	$BUILD_TIC -I -r -e $FALLBK ../misc/terminfo.src > terminfo.src
	$BUILD_TIC -o $TERMINFO -s terminfo.src
	sh -e ./tinfo/MKfallback.sh $TERMINFO ../misc/terminfo.src $BUILD_TIC ${FALLBK//,/ } > fallback.c
	rm -rf $TERMINFO
	unset  TERMINFO
	cp -p fallback.c ../fallback.c.build
    popd
    PATH=$OPATH
    unset LD_LIBRARY_PATH
    #
    # Refresh second install path
    #
    rm -rf %{root}
    mkdir  %{root}
    #
    # Now rebuild libncurses and do the rest of this job
    #
    find -name fallback.o | xargs -r rm -vf
    cp fallback.c.build ncurses/fallback.c
    make -C c++ etip.h
    make %{?_smp_mflags}
    # must not use %jobs here (would lead to: ln: ncurses.h already exists)
    find man/ -name '*.[1-8]x.*' | xargs -r rm -vf
    make install DESTDIR=%{root} includedir=%{_incdir} includesubdir=/ncurses libdir=%{_libdir}
    ln -sf %{_incdir}/ncurses/{curses,ncurses,term,termcap}.h %{root}%{_incdir}
    mkdir pc
    PKG_CONFIG_PATH=$PWD/pc:$(pkg-config --variable pc_path pkg-config)
    export PKG_CONFIG_PATH
    mv -vf %{root}%{_libdir}/pkgconfig/*.pc pc/
    sed -ri 's@^(Requires.private:).*@\1@'                      pc/*.pc
    sed -ri 's@^(Libs.private: .*)@\1 -lncurses -ltinfo -ldl@'  pc/{form,menu,panel}.pc
    sed -ri 's@^(Libs.private: .*)@\1 -ltinfo@'                 pc/tic.pc
    sed -ri 's@^(Libs: .*)@\1 -ltinfo@'                         pc/ncurses.pc
    sed -ri 's@^(Libs.private: .*)@\1 -ldl@'                    pc/ncurses.pc
    sh %{S:6} --cflags "$(pkg-config --cflags ncurses)" --libs "$(pkg-config --libs ncurses)" \
	%{root}%{_bindir}/ncurses5-config
    # Check for tack program on base of above ncurses
    #
    LD_LIBRARY_PATH=$PWD/lib
    export LD_LIBRARY_PATH PATH
    pushd tack/
%if 0%{?qemu_user_space_build:1}%{?_crossbuild}
	echo "Skipping LDD test due to running under QEMU / cross-building"
%else
	ldd ./tack
%endif
    popd
    unset LD_LIBRARY_PATH
    test ! -L tack || rm -f tack
%if %abi < 6
    make clean
    #
    # Now use --with-pthread for reentrant pthread support (abi > 5).
    #
    > $SCREENLOG
    tail -q -s 0.5 -f $SCREENLOG & pid=$!
    eval screen -L -D -m ./${c#*./} --with-pthread --enable-reentrant --enable-ext-mouse --disable-widec --disable-ext-colors --without-progs
    kill $pid
    find -name fallback.o | xargs -r rm -vf
    cp fallback.c.build ncurses/fallback.c
    make -C c++ etip.h
    make %{?_smp_mflags}
    sed -ri 's@(LDFLAGS=)$@\1-L\\${libdir}@
	     s@^(libdir=).show_libdir@\1%{_libdir}/ncurses6@
	     s@^(includedir=).show_includedir@\1%{_incdir}/ncurses6@' misc/gen-pkgconfig
    # must not use %jobs here (would lead to: ln: ncurses.h already exists)
    make install.libs install.includes DESTDIR=%{root} includedir=%{_incdir}/ncurses6 includesubdir=/ncurses libdir=%{_libdir}/ncurses6
    ln -sf %{_incdir}/ncurses6/ncurses/{curses,ncurses,term}.h %{root}%{_incdir}/ncurses6/
    for pc in %{root}%{_libdir}/pkgconfig/*.pc
    do
	test -e "$pc" || break
	base=${pc%%.pc}
	base=${base##*/}
	sed -ri 's@^(includedir=).*@\1%{_incdir}/ncurses6/ncurses@' "$pc"
	sed -ri 's@^(libdir=).*@\1%{_libdir}/ncurses6@' "$pc"
	mv -f $pc pc/${base}6.pc
	sed -ri 's@^(Cflags: )@\1-I%{_incdir}/ncurses6 @' pc/${base}6.pc
    done
    sed -ri 's@^(Requires.private:).*@\1@'                      pc/*.pc
    sed -ri 's@^(Libs.private: .*)@\1 -lncurses -ltinfo -ldl@'  pc/{form,menu,panel}6.pc
    sed -ri 's@^(Libs.private: .*)@\1 -ltinfo@'                 pc/tic6.pc
    sed -ri 's@^(Libs: .*)@\1 -ltinfo@'                         pc/ncurses6.pc
    sed -ri 's@^(Libs.private: .*)@\1 -ldl@'                    pc/ncurses6.pc
    sh %{S:6} --cflags "$(pkg-config --cflags ncurses6)" --libs "$(pkg-config --libs ncurses6)" \
	%{root}%{_bindir}/ncurses6-config
    pushd man
	sh ../edit_man.sh normal installing %{root}%{_mandir} . ncurses6-config.1
    popd
%endif
    make clean
    #
    # Now use --enable-widec for UTF8/wide character support.
    # The libs with 16 bit wide characters are binary incompatible
    # to the normal 8bit wide character libs.
    #
    > $SCREENLOG
    tail -q -s 0.5 -f $SCREENLOG & pid=$!
%if %abi >= 6
    eval screen -L -D -m ./${c#*./} --with-pthread --enable-reentrant --enable-ext-mouse --enable-widec --enable-ext-colors --without-progs
%else
    eval screen -L -D -m ./${c#*./} --disable-ext-mouse --enable-widec --disable-ext-colors --without-progs
%endif
    kill $pid
    find -name fallback.o | xargs -r rm -vf
    cp fallback.c.build ncurses/fallback.c
    make -C c++ etip.h
    make %{?_smp_mflags}
    # must not use %jobs here (would lead to: ln: ncurses.h already exists)
    make install.libs install.includes DESTDIR=%{root} includedir=%{_incdir} includesubdir=/ncursesw libdir=%{_libdir}
    rm -vf %{root}%{_libdir}/pkgconfig/tic.pc
    rm -vf %{root}%{_libdir}/pkgconfig/tinfo.pc
    mv -vf %{root}%{_libdir}/pkgconfig/*.pc pc/
    sed -ri 's@^(Requires.private:).*@\1@'                      pc/*.pc
    sed -ri 's@^(Libs.private: .*)@\1 -lncursesw -ltinfo -ldl@' pc/{form,menu,panel}w.pc
    sed -ri 's@^(Libs: .*)@\1 -ltinfo@'                         pc/ncursesw.pc
    sed -ri 's@^(Libs.private: .*)@\1 -ldl@'                    pc/ncursesw.pc
    sh %{S:6} --cflags "$(pkg-config --cflags ncursesw)" --libs "$(pkg-config --libs ncursesw)" \
	%{root}%{_bindir}/ncursesw5-config
    pushd man
	sh ../edit_man.sh normal installing %{root}%{_mandir} . ncursesw5-config.1
    popd
%if %abi < 6
    make clean
    #
    # Do both --enable-widec and --with-pthread (abi > 5).
    #
    > $SCREENLOG
    tail -q -s 0.5 -f $SCREENLOG & pid=$!
    eval screen -L -D -m ./${c#*./} --with-pthread --enable-reentrant --enable-ext-mouse --enable-widec --enable-ext-colors --without-progs
    kill $pid
    find -name fallback.o | xargs -r rm -vf
    cp fallback.c.build ncurses/fallback.c
    make -C c++ etip.h
    make %{?_smp_mflags}
    sed -ri 's@(LDFLAGS=)$@\1-L\\${libdir}@
	     s@^(libdir=).show_libdir@\1%{_libdir}/ncurses6@
	     s@^(includedir=).show_includedir@\1%{_incdir}/ncurses6@' misc/gen-pkgconfig
    # must not use %jobs here (would lead to: ln: ncurses.h already exists)
    make install.libs install.includes DESTDIR=%{root} includedir=%{_incdir}/ncurses6 includesubdir=/ncursesw libdir=%{_libdir}/ncurses6
    rm -vf %{root}%{_libdir}/pkgconfig/tic.pc
    rm -vf %{root}%{_libdir}/pkgconfig/tinfo.pc
    for pc in %{root}%{_libdir}/pkgconfig/*.pc
    do
	test -e "$pc" || break
	base=${pc%%.pc}
	base=${base##*/}
	sed -ri 's@^(includedir=).*@\1%{_incdir}/ncurses6/ncursesw@' "$pc"
	sed -ri 's@^(libdir=).*@\1%{_libdir}/ncurses6@' "$pc"
	mv -f $pc pc/${base}6.pc
	sed -ri 's@^(Cflags: )@\1-I%{_incdir}/ncurses6 @' pc/${base}6.pc
    done
    sed -ri 's@^(Requires.private:).*@\1@'                      pc/*.pc
    sed -ri 's@^(Libs.private: .*)@\1 -lncursesw -ltinfo -ldl@' pc/{form,menu,panel}w6.pc
    sed -ri 's@^(Libs: .*)@\1 -ltinfo@'                         pc/ncursesw6.pc
    sed -ri 's@^(Libs.private: .*)@\1 -ldl@'                    pc/ncursesw6.pc
    sh %{S:6} --cflags "$(pkg-config --cflags ncursesw6)" --libs "$(pkg-config --libs ncursesw6)" \
	%{root}%{_bindir}/ncursesw6-config
    pushd man
	sh ../edit_man.sh normal installing %{root}%{_mandir} . ncursesw6-config.1
    popd
%endif

%install
    GZIP="-9"
    export GZIP
    (cd %{root}/; tar -cpSf - *)|tar -xpsSf - -C %{buildroot}/
    rm -rf %{root}
    mkdir %{buildroot}/%{_lib}
    for model in libncurses libncursest libncursesw libncursestw libtinfo
    do
	for lib in %{buildroot}%{_libdir}/${model}.so.* ; do
	    test   -e "${lib}" || continue
	    mv "${lib}" %{buildroot}/%{_lib}/ || continue
	done
	for lib in %{buildroot}/%{_lib}/${model}.so.%{abi} ; do
	    test -e "${lib}" || continue
	    test -L "${lib}" || continue
	    lib=${lib#%{buildroot}}
	    lnk=%{buildroot}%{_libdir}/${model}.so
	    case "${lib##*/}" in
	    libncurses*)
		rm -f ${lnk}
		echo '/* GNU ld script */'		>  ${lnk}
		echo "INPUT(${lib} AS_NEEDED(-ltinfo))" >> ${lnk}
		;;
	    *)	ln -sf ${lib} %{buildroot}%{_libdir}/${model}.so
	    esac
	done
    done
%if 0
    lnk=%{buildroot}%{_libdir}/libtermcap.so
    echo '/* GNU ld script */'		>  ${lnk}
    echo "INPUT(AS_NEEDED(-ltinfo))"	>> ${lnk}
%endif
    chmod 0755 %{buildroot}/%{_lib}/lib*.so.*
    chmod 0755 %{buildroot}/%{_libdir}/lib*.so.*
    chmod a-x  %{buildroot}/%{_libdir}/lib*.a
%if %abi < 6
    if test -d %{buildroot}%{_libdir}/ncurses6 ; then
	mv %{buildroot}%{_libdir}/ncurses6/*.so.6*   %{buildroot}%{_libdir}/
	for lib in %{buildroot}%{_libdir}/ncurses6/*.so
	do
	    lnk=$lib
	    lib=/%{_lib}/${lib##*/}.6
	    case "${lib##*/}" in
	    libncurses*)
		rm -f "${lnk}"
		echo '/* GNU ld script */'		>  ${lnk}
		echo "INPUT(${lib} AS_NEEDED(-ltinfo))"	>> ${lnk}
		;;
	    libtinfo*)
		test -L "${lnk}" || continue
		ln -sf ${lib} ${lnk}
		;;
	    *)
		test -L "${lnk}" || continue
		ln -sf ../${lib##*/} ${lnk}
	    esac
	done
	for model in libncurses libncursest libncursesw libncursestw libtinfo
	do
	    for lib in %{buildroot}%{_libdir}/${model}.so.* ; do
		test   -e "${lib}" || continue
		mv "${lib}" %{buildroot}/%{_lib}/ || continue
	    done
	    for lib in %{buildroot}/%{_lib}/${model}.so.6 ; do
		test -e "${lib}" || continue
		test -L "${lib}" || continue
		lib=${lib#%{buildroot}}
		lnk=%{buildroot}%{_libdir}/ncurses6/${model}.so
		case "${lib##*/}" in
		libncurses*)
		    rm -f ${lnk}
		    echo '/* GNU ld script */'		    >  ${lnk}
		    echo 'SEARCH_DIR(%{_libdir}/ncurses6)'  >> ${lnk}
		    echo "INPUT(${lib} AS_NEEDED(-ltinfo))" >> ${lnk}
		    ;;
		*)  ln -sf ${lib} %{buildroot}%{_libdir}/ncurses6/${model}.so
	    esac
	    done
	done
	chmod 0755 %{buildroot}/%{_lib}/lib*.so.6*
	chmod 0755 %{buildroot}/%{_libdir}/lib*.so.6*
	chmod a-x  %{buildroot}/%{_libdir}/ncurses6/lib*.a
    fi
%endif
    test -n "%{buildroot}" || ldconfig -N
    mkdir -p %{buildroot}%{_defaultdocdir}/ncurses
    bzip2 -c misc/terminfo.src > misc/terminfo.src.bz2
    install -m 644 misc/terminfo.src.bz2	%{buildroot}%{_defaultdocdir}/ncurses/
    install -m 644 doc/html/*.html		%{buildroot}%{_defaultdocdir}/ncurses/
    bzip2 doc/ncurses-intro.doc -c > doc/ncurses-intro.txt.bz2
    install -m 644 doc/ncurses-intro.txt.bz2	%{buildroot}%{_defaultdocdir}/ncurses/
    bzip2 doc/hackguide.doc -c > doc/hackguide.txt.bz2
    install -m 644 doc/hackguide.txt.bz2	%{buildroot}%{_defaultdocdir}/ncurses/
    install -m 644 %{S:3}			%{buildroot}%{_defaultdocdir}/ncurses/
    install -m 644 README			%{buildroot}%{_defaultdocdir}/ncurses/
    install -m 644 NEWS				%{buildroot}%{_defaultdocdir}/ncurses/
    mkdir -p %{buildroot}%{_sysconfdir}
    mkdir -p %{buildroot}%{_miscdir}
    LD_LIBRARY_PATH=%{buildroot}%{_libdir}:%{buildroot}/%{_lib}
    export LD_LIBRARY_PATH
    pushd ncurses/
	. ${PWD}/.build_tic
	{ echo "# See annotated version in %{_defaultdocdir}/ncurses/terminfo.src.bz2"
	$BUILD_TIC -C -r ../misc/terminfo.src | grep -E -v '^#'; } > termcap
	# Gererate new termcap entries for various linux consoles
	TERMCAP=termcap \
	TERMINFO=%{buildroot}%{_datadir}/terminfo \
	    bash %{SOURCE2}
	install -m 0644 termcap.new %{buildroot}%{_miscdir}/termcap
    popd
    unset LD_LIBRARY_PATH
    if test `%{_bindir}/id -u` = '0' ; then
	chown root:root %{buildroot}%{_miscdir}/termcap
	chmod 0644      %{buildroot}%{_miscdir}/termcap
    fi
    ln -sf %{_miscdir}/termcap %{buildroot}%{_sysconfdir}/termcap
    (cat > default.list) <<-EOF
	%{tabset std}
	%{tabset stdcrt}
	%{tabset vt100}
	%{tabset vt300}
	%{terminfo a/ansi}
	%{terminfo a/arpanet}
	%{terminfo d/dumb}
	%{terminfo d/dialup}
	%{terminfo g/gnome}
	%{terminfo g/gnome-rh72}
	%{terminfo g/gnome-rh80}
	%{terminfo g/gnome-rh90}
	%{terminfo g/gnome-fc5}
	%{terminfo i/ibm327x}
	%{terminfo k/klone+color}
	%{terminfo k/konsole}
	%{terminfo k/konsole-256color}
	%{terminfo k/kvt}
	%{terminfo k/kvt-rh}
	%{terminfo l/linux}
	%{terminfo l/linux-m}
	%{terminfo l/linux-nic}
	%{terminfo m/mlterm}
	%{terminfo n/net}
	%{terminfo n/network}
	%{terminfo n/nxterm}
	%{terminfo p/patch}
	%{terminfo r/rxvt}
	%{terminfo r/rxvt-basic}
	%{terminfo r/rxvt-color}
	%{terminfo r/rxvt-256color}
	%{terminfo r/rxvt-unicode}
	%{terminfo r/rxvt-unicode-256color}
	%{terminfo s/screen}
	%{terminfo s/screen-w}
	%{terminfo s/screen-256color}
	%{terminfo s/sun}
	%{terminfo s/switch}
	%{terminfo u/unknown}
	%{terminfo v/vt100}
	%{terminfo v/vt102}
	%{terminfo v/vt220}
	%{terminfo v/vt220-8}
	%{terminfo v/vt220-8bit}
	%{terminfo v/vt320}
	%{terminfo v/vt52}
	%{terminfo v/vte}
	%{terminfo x/xterm}
	%{terminfo x/xterm-color}
	%{terminfo x/xterm-256color}
	%{terminfo x/xterm-basic}
	%{terminfo x/xterm-nic}
	%{terminfo x/xterm-r6}
	EOF
    find %{buildroot}%{tabset ""} %{buildroot}%{terminfo ""} \
	\( -type f -or -type l \) | \
	sed "s@^%{buildroot}@@g" | \
	grep -v -F -x -f default.list \
	> extension.list
    rm -f %{buildroot}%{_prefix}/lib/terminfo
%if %abi < 6
    cp -p pc/*.pc %{buildroot}%{_libdir}/pkgconfig/

%post   -n libncurses5 -p /sbin/ldconfig

%postun -n libncurses5 -p /sbin/ldconfig
%endif

%post   -n libncurses6 -p /sbin/ldconfig

%postun -n libncurses6 -p /sbin/ldconfig

%files -n terminfo-base -f default.list
%defattr(-,root,root)
%{_sysconfdir}/termcap
%config %{_miscdir}/termcap
%dir %{_datadir}/tabset/
%dir %{_datadir}/terminfo/
%dir %{_datadir}/terminfo/*/

%files -n ncurses-utils
%defattr(-,root,root)
%{_bindir}/clear
%{_bindir}/reset
%{_bindir}/tabs
%{_bindir}/toe
%{_bindir}/tput
%{_bindir}/tset
%doc %{_mandir}/man1/clear.1.gz
%doc %{_mandir}/man1/reset.1.gz
%doc %{_mandir}/man1/tabs.1.gz
%doc %{_mandir}/man1/toe.1.gz
%doc %{_mandir}/man1/tput.1.gz
%doc %{_mandir}/man1/tset.1.gz
%doc %{_mandir}/man5/*.gz
%if %abi == 5

%files -n libncurses5
%defattr(-,root,root)
/%{_lib}/lib*.so.5*
%{_libdir}/lib*.so.5*
%endif

%files -n libncurses6
%defattr(-,root,root)
/%{_lib}/lib*.so.6*
%{_libdir}/lib*.so.6*

%files -n ncurses-devel
%defattr(-,root,root)
%dir %{_defaultdocdir}/ncurses/
%doc %{_defaultdocdir}/ncurses/*
%{_bindir}/ncurses*-config
%{_bindir}/captoinfo
%{_bindir}/infocmp
%{_bindir}/infotocap
%{_bindir}/tic
%dir %{_incdir}/ncurses/
%dir %{_incdir}/ncursesw/
%dir %{_incdir}/ncurses6/
%dir %{_incdir}/ncurses6/ncurses/
%dir %{_incdir}/ncurses6/ncursesw/
%{_incdir}/*.h
%{_incdir}/ncurses*/*.h
%{_incdir}/ncurses*/*/*.h
%dir %{_libdir}/ncurses6/
%{_libdir}/lib*.a
%{_libdir}/lib*.so
%{_libdir}/ncurses6/lib*.a
%{_libdir}/ncurses6/lib*.so
%{_libdir}/pkgconfig/*.pc
%doc %{_mandir}/man1/*-config.1.gz
%doc %{_mandir}/man1/captoinfo.1.gz
%doc %{_mandir}/man1/infocmp.1.gz
%doc %{_mandir}/man1/infotocap.1.gz
%doc %{_mandir}/man1/tic.1.gz
%doc %{_mandir}/man3/*.gz
%doc %{_mandir}/man7/*.gz

%files -n tack
%defattr(-,root,root)
%{_bindir}/tack
%doc %{_mandir}/man1/tack.1.gz

%files -f extension.list -n terminfo
%defattr(-,root,root)

%changelog
openSUSE Build Service is sponsored by