#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobcore/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=ncurses
pkgver=6.4_20230520
pkgrel=01
pkgdesc='System V Release 4.0 curses emulation library'
_url='https://invisible-island.net/ncurses/ncurses.html'
url="https://invisible-mirror.net/archives"
depends=(glibc gcc-libs)
makedepends=(autoconf-archive)
optdepends=('bash: for ncursesw6-config')
provides=(libncurses++w.so libformw.so libmenuw.so libpanelw.so libncursesw.so)
replaces=(alacritty-terminfo)
#options=(debug) # uncomment this to produce the debug pkg
source=($url/$pkgname/current/$pkgname-${pkgver/_/-}.tgz{,.asc}
  $pkgname-6.3-libs.patch
  $pkgname-6.3-pkgconfig.patch)

prepare() {
   # do not link against test libraries
   patch -Np1 -d $pkgname-${pkgver/_/-} -i ../$pkgname-6.3-libs.patch
   # do not leak build-time LDFLAGS into the pkgconfig files:
   # https://bugs.archlinux.org/task/68523
   patch -Np1 -d $pkgname-${pkgver/_/-} -i ../$pkgname-6.3-pkgconfig.patch
   # NOTE: can't run autoreconf because the autotools setup is custom and ancient
}


build() {
  cd $pkgname-${pkgver/_/-}

  ./configure --prefix=/usr \
    --enable-widec \
    --enable-pc-files \
    --disable-root-access \
    --disable-root-environ \
    --disable-setuid-environ \
    --mandir=/usr/share/man \
    --with-cxx-binding \
    --with-cxx-shared \
    --with-manpage-format=normal \
    --with-pkg-config-libdir=/usr/lib/pkgconfig \
    --with-shared \
    --with-versioned-syms \
    --without-ada \
    --with-xterm-kbs=del \
    --without-debug
  make
}

package() {
  local _pkgver=${pkgver/_*/}

  make DESTDIR="$pkgdir" install -C $pkgname-${pkgver/_/-}
  install -vDm 644 $pkgname-${pkgver/_/-}/COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"


  # fool packages looking to link to non-wide-character ncurses libraries
  for lib in ncurses ncurses++ form panel menu; do
    printf "INPUT(-l%sw)\n" "${lib}" > "$pkgdir/usr/lib/lib${lib}.so"
    ln -sv ${lib}w.pc "$pkgdir/usr/lib/pkgconfig/${lib}.pc"
  done

  # some packages look for -lcurses during build
  printf 'INPUT(-lncursesw)\n' > "$pkgdir/usr/lib/libcursesw.so"
  ln -sv libncurses.so "$pkgdir/usr/lib/libcurses.so"

  # tic and ticinfo functionality is built in by default
  # make sure that anything linking against it links against libncursesw.so instead
  for lib in tic tinfo; do
    printf "INPUT(libncursesw.so.%s)\n" "${_pkgver:0:1}" > "$pkgdir/usr/lib/lib${lib}.so"
    ln -sv libncursesw.so.${pkgver:0:1} "$pkgdir/usr/lib/lib${lib}.so.${_pkgver:0:1}"
    ln -sv ncursesw.pc "$pkgdir/usr/lib/pkgconfig/${lib}.pc"
  done
}

#---- arch license gpg-key & sha256sums ----

arch=(x86_64)

license=(MIT)

validpgpkeys=('19882D92DDA4C400C22C0D56CC2AF4472167BE03')  # Thomas Dickey <dickey@invisible-island.net>

sha256sums=(a04f69bde2f1b1325d1fb460db7cea28b6da97786ead8ce645daacfb0bcbc004  # ncurses-6.4-20230520.tgz
	9d4311c1ee185968471d08506a02ae24a4256dca259e1a57b876300566e37c0a  # ncurses-6.4-20230520.tgz.asc
	dc4261b6642058a9df1c0945e2409b24f84673ddc3a665d8a15ed3580e51ee25  # ncurses-6.3-libs.patch
	b8544a607dfbeffaba2b087f03b57ed1fa81286afca25df65f61b04b5f3b3738) # ncurses-6.3-pkgconfig.patch

##  908fdf74b6a93f800bd89d4c8f19eef7a786f16acc5d34001be4af4995fabd07  ncurses-6.4_20230520-01-x86_64.pkg.tar.lz

