# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>

pkgname=libcaca
pkgver=0.99.beta20
pkgrel=4.1
pkgdesc='Color ASCII art library'
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url='http://caca.zoy.org/wiki/libcaca'
license=('WTFPL')
depends=('freeglut' 'gcc-libs' 'glibc' 'glu' 'imlib2' 'libglvnd' 'libx11' 'ncurses' 'slang' 'zlib')
makedepends=('doxygen' 'pango' 'python')
options=(!lto)
optdepends=('python: Python bindings')
source=("https://github.com/cacalabs/libcaca/releases/download/v$pkgver/$pkgname-$pkgver.tar.bz2"
        'libcaca-0.99.beta20-CVE-2022-0856.patch')
sha256sums=('ff9aa641af180a59acedc7fc9e663543fb397ff758b5122093158fd628125ac1'
            '242308d530e20f018c1a275a90c0697b107bf2bfd28e928610bbbe80707bdeef')

prepare() {
  cd $pkgname-$pkgver
  # Prevent a divide-by-zero by checking for a zero width or height
  # https://github.com/cacalabs/libcaca/pull/66
  patch -Np1 -i ../libcaca-0.99.beta20-CVE-2022-0856.patch
}

build() {
  cd $pkgname-$pkgver
  ./configure --prefix=/usr
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  cd $pkgname-$pkgver
  make check
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
}
