#!/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.3
pkgrel=03
pkgdesc='System V Release 4.0 curses emulation library'
arch=(x86_64)
_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/$pkgname-$pkgver.tar.gz{,.asc}
  $pkgname-$pkgver-libs.patch
  $pkgname-$pkgver-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 \
    --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() {
  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
}

#---- license gpg-key sha256sums ----

license=(MIT)

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

sha256sums=(97fc51ac2b085d4cde31ef4d2c3122c21abc217e9090a43a30fc5ec21684e059  # ncurses-6.3.tar.gz
	37b9e80c11fa02fbd8caf42ab9573427f54f2c7212eb4aeec9f455b5d79dee14  # ncurses-6.3.tar.gz.asc
	dc4261b6642058a9df1c0945e2409b24f84673ddc3a665d8a15ed3580e51ee25  # ncurses-6.3-libs.patch
	b8544a607dfbeffaba2b087f03b57ed1fa81286afca25df65f61b04b5f3b3738) # ncurses-6.3-pkgconfig.patch
