pkgname="ncurses"
pkgver="6.5-20250809"
pkgdesc='System V Release 4.0 curses emulation library'
homepage="https://www.gnu.org/software/ncurses/"
license=(MIT-open-group)
sources=("${pkgname}-${pkgver}.tgz")
urls=("https://invisible-mirror.net/archives/ncurses/current/${sources[0]}")
md5sums=("679987405412f970561cc85e1e6428a2")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
}

src_build() {
  ./configure --prefix=/usr           \
              --mandir=/usr/share/man \
              --with-shared           \
              --without-debug         \
              --without-normal        \
              --with-cxx-shared       \
              --enable-pc-files       \
              --with-pkg-config-libdir=/usr/lib/pkgconfig
  make
}

src_install() {
  make DESTDIR="$pkgdir" install
  install -vDm 644 COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
  sed -e 's/^#if.*XOPEN.*$/#if 1/' \
    -i "${pkgdir}/usr/include/curses.h"
  for lib in ncurses form panel menu ; do
    ln -sfv lib${lib}w.so "${pkgdir}/usr/lib/lib${lib}.so"
    ln -sfv ${lib}w.pc    "${pkgdir}/usr/lib/pkgconfig/${lib}.pc"
  done
  ln -sfv libncursesw.so "${pkgdir}/usr/lib/libcurses.so"
  install -vd "${pkgdir}/usr/share/doc/${pkgname}-${pkgver}"
  cp -v -R doc -T "${pkgdir}/usr/share/doc/${pkgname}-${pkgver}"

  # non-wide
  make distclean
  ./configure --prefix=/usr    \
              --with-shared    \
              --without-normal \
              --without-debug  \
              --without-cxx-binding \
              --with-abi-version=5
  make sources libs
  cp -av lib/lib*.so.5* "${pkgdir}/usr/lib"
}
