# No Testcase run by default. To enable: rpm(or rpmbuild) -ba --define 'dotests 1' ncurses*.spec
%{!?dotests: %define dotests 0}

Summary: A terminal handling library
Name: ncurses
Version: 6.3
Release: 1 
License: MIT
Group: System Environment/Libraries
URL: http://invisible-island.net/ncurses/ncurses.html
Source0: https://ftp.gnu.org/gnu/ncurses//ncurses-%{version}.tar.gz
Source1:ftp://invisible-island.net/ncurses/%{name}-%{version}.tar.gz.sig

Requires: libgcc >= 8.3.0-1
Requires: libstdc++ >= 8.3.0-1

%description
The curses library routines are a terminal-independent method of
updating character screens with reasonable optimization.  The ncurses
(new curses) library is a freely distributable replacement for the
discontinued 4.4 BSD classic curses library.


%package devel
Summary: Development files for the ncurses library
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}

%description devel
The header files and libraries for developing applications that use
the ncurses terminal handling library.

Install the ncurses-devel package if you want to develop applications
which will use ncurses.


%prep
%setup -q

# Duplicate source for 32 & 64 bits
rm -rf /tmp/%{name}-%{version}-32bit
mkdir  /tmp/%{name}-%{version}-32bit
mv *   /tmp/%{name}-%{version}-32bit
mkdir 32bit
mv     /tmp/%{name}-%{version}-32bit/* 32bit
rm -rf /tmp/%{name}-%{version}-32bit
mkdir 64bit
cp -rp 32bit/* 64bit/

%build
export RM="/usr/bin/rm -f"
# hack to get shared libraries working on AIX
find . -name Makefile.in -exec /opt/freeware/bin/sed -i 's/@OBJEXT@/lo/' {} \;

# setup environment for 32-bit and 64-bit builds
export CONFIG_SHELL=/bin/sh
export CONFIGURE_ENV_ARGS=/bin/sh

# setup environment for 32-bit and 64-bit builds
export AR="ar -X32_64"
export NM="nm -X32_64"

# first build the 64-bit version
cd 64bit
export OBJECT_MODE=64
export CC="gcc -maix64"
export CXX="g++ -maix64"

# shell function to configure ncurses
configurencurses() {
./configure \
    --prefix=%{_prefix} \
    --mandir=%{_mandir} \
    --libdir=%{_libdir}64 \
    --without-ada \
    --without-normal \
    --without-debug \
    --with-shared \
    --with-libtool \
    --enable-overwrite \
    --enable-hard-tabs \
    --enable-xmc-glitch \
    --enable-colorfgbg \
    --disable-static \
    --enable-pc-files \
    --with-pkg-config-libdir=%{_libdir}64/pkgconfig \
    $*
}

configurencurses

make %{?_smp_mflags}

if [ "%{dotests}" == 1 ]
then
    (gmake -i check || true)
fi

# now build the 32-bit version
cd ../32bit
export OBJECT_MODE=32
export CC="gcc"
export CXX="g++"

export LDFLAGS="-L/opt/freeware/lib -L/usr/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib"

# shell function to configure ncurses
configurencurses() {
./configure \
    --prefix=%{_prefix} \
    --mandir=%{_mandir} \
    --libdir=%{_libdir} \
    --without-ada \
    --without-normal \
    --without-debug \
    --with-shared \
    --with-libtool \
    --enable-overwrite \
    --enable-hard-tabs \
    --enable-xmc-glitch \
    --enable-colorfgbg \
    --disable-static \
    --enable-pc-files \
    --with-pkg-config-libdir=%{_libdir}/pkgconfig \
    $*
}

configurencurses

make %{?_smp_mflags}

if [ "%{dotests}" == 1 ]
then
    (gmake -i check || true)
fi

%install

# first install 64bit
cd 64bit
export OBJECT_MODE=64
export CC="gcc -maix64"
export CXX="g++ -maix64"
export AR="ar -X32_64"

export LDFLAGS="-L/opt/freeware/lib64 -L/opt/freeware/lib -L/usr/lib -Wl,-blibpath:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib"

[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install

(
  cd ${RPM_BUILD_ROOT}%{_bindir}
  for f in *
  do
    mv ${f} ${f}_64
  done
)

(
  for library in libncurses libpanel libmenu libform libncurses++
  do
        cd ${RPM_BUILD_ROOT}%{_libdir}64
	rm -f ${library}.a
        ${AR} -rv ${library}.a ${library}.so.6
        ln -sf ${library}.so.6 ${library}.so
  done
)

cd ../32bit

export OBJECT_MODE=32
export CC="gcc"
export CXX="g++"

make DESTDIR=$RPM_BUILD_ROOT install

/usr/bin/strip -X32_64 ${RPM_BUILD_ROOT}%{_bindir}/* || :

(
  cd ${RPM_BUILD_ROOT}%{_bindir}
  for f in $(ls | grep -v -e _32 -e _64)
  do
    mv ${f} ${f}_32
    ln -sf ${f}_64 ${f}
  done
)

(
  for library in libncurses libpanel libmenu libform libncurses++
  do
        cd ${RPM_BUILD_ROOT}%{_libdir}
        rm -f ${library}.a
        ${AR} -rv ${library}.a ${library}.so.6
        ${AR} -q ${library}.a ${RPM_BUILD_ROOT}%{_libdir}64/${library}.so.6
        ln -sf ${library}.so.6 ${library}.so
        
  done
)

mkdir ${RPM_BUILD_ROOT}%{_includedir}/ncurses
for f in ${RPM_BUILD_ROOT}%{_includedir}/*.h; do
  ln -s ../$(basename $f) ${RPM_BUILD_ROOT}%{_includedir}/ncurses
done


%files
%defattr(-,root,system)
%doc 32bit/ANNOUNCE 32bit/AUTHORS 32bit/README 32bit/TO-DO
%{_bindir}/[cirt]*
%{_libdir}/*.a
%{_libdir}64/*.a
%{_libdir}/*.so*
%{_libdir}64/*.so*
%{_libdir}/terminfo
%{_datadir}/terminfo
%{_datadir}/tabset
%{_mandir}/man1/[cirt]*
%{_mandir}/man5/*
%{_mandir}/man7/*


%files devel
%defattr(-,root,system)
%doc 32bit/doc/html/hackguide.html 32bit/doc/html/ncurses-intro.html 32bit/c++/README*
%{_bindir}/ncurses*-config*
%{_includedir}/*.h
%dir %{_includedir}/ncurses
%{_includedir}/ncurses/*.h
%{_mandir}/man1/ncurses6-config.1
%{_mandir}/man3/*
%{_libdir}/pkgconfig/*.pc
%{_libdir}64/pkgconfig/*.pc


%clean
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT


%changelog
* Tue Mar 22 2022 Neha Jain <nehajain29@in.ibm.com> - 6.3-1
-updated to latest version

* Wed Aug 11 2021 Ayappan P <ayappap2@in.ibm.com> - 6.2-3
- Fix header files location in line with other distros

* Wed Sep 16 2020 Reshma V Kumar <reskumar@in.ibm.com> - 6.2-2
- Rebuild to fix broken symbolic link of ncurses6-config
- Remove .la files and stop shipping files in /usr directory

* Wed Mar 11 2020 Reshma V Kumar <reskumar@in.ibm.com> - 6.2-1
- Update to fix CVE-2019-17594,CVE-2019-17595

* Tue Jan 08 2019 Ayappan P <ayappap2@in.ibm.com> - 6.1-2
- Fix library issues

* Wed Mar 14 2018 Reshma V Kumar <reskumar@in.ibm.com> -6.1-1
- Update to 6.1 to fix security vulnerability

* Wed Jun 01 2016 Reshma V Kumar <reskumar@in.ibm.com> -6.0-1
- updated to latest version

* Fri Feb 03 2012 Gerard Visiedo <gerard.visiedo@bull.net> - 5.9-3
- Initial port on Aix6.1

* Tue Oct 04 2011 Gerard Visiedo <gerard.visiedo@bull.net> - 5.9-2
- rebuild for compatibility with new libiconv.a 1.13.1-2

* Wed Jul 13 2011 Gerard Visiedo <gerard.visiedo@bull.net - 5.9-1
- Initial port on Aix 5.3


