# Contributor (MSYS2): David Macek <david.macek.0@gmail.com>
# Maintainer (Arch Linux): Kyle Keen <keenerd@gmail.com>
# Maintainer (Arch Linux): Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor (Arch Linux): Geoffroy Carrier <geoffroy.carrier@koon.fr>
# Contributor (Arch Linux): arjan <arjan@archlinux.org>
# Contributor (Arch Linux): Tom Newsom <Jeepster@gmx.co.uk>

_realname=ucl
pkgname=("ucl" "ucl-devel")
pkgver=1.03
pkgrel=4
pkgdesc="Portable lossless data compression library written in ANSI C"
arch=('i686' 'x86_64')
license=('GPL')
makedepends=('autotools' 'gcc')
url="https://www.oberhumer.com/opensource/ucl/"
msys2_references=(
  "anitya: 13446"
)
source=("https://www.oberhumer.com/opensource/${_realname}/download/${_realname}-${pkgver}.tar.gz"
        "001-autoconf-compat.patch"
        "002-missing-macros.patch"
        "003-no-undefined.patch")
sha256sums=('b865299ffd45d73412293369c9754b07637680e5c826915f097577cd27350348'
            '0cbd00a8383c098f98d5b022fcb4fa8d1448501e00221a223be04be0383bafc0'
            '207f14915b1293944aead438bf7f39c87c465fd7ed3873f3a205996ea811d5e1'
            '56a110aedab800c0a06cf4fd4dcef8f78691a0d091e2f143a2a8f02cfbb4c172')

prepare() {
  cd "${_realname}-${pkgver}"
  rm -f acinclude.m4

  patch -p1 -i "${srcdir}/001-autoconf-compat.patch"
  patch -p1 -i "${srcdir}/002-missing-macros.patch"
  patch -p1 -i "${srcdir}/003-no-undefined.patch"

  touch ChangeLog
  WANT_AUTOCONF="2.69" autoreconf -fiv
}

build() {
  cd "${_realname}-${pkgver}"

  CPPFLAGS="$CPPFLAGS -std=c90 -fPIC" \
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --enable-shared \
    --enable-static \
    --disable-asm

  make
  make DESTDIR=${srcdir}/dest install
}

package_ucl() {
  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  
  install -Dm644 "${srcdir}/${pkgname}-${pkgver}/COPYING" "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}

package_ucl-devel() {
  groups=('development')
  options=(staticlibs)
  depends=("ucl=${pkgver}")
  pkgdesc="ucl headers and libraries"

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
