# Maintainer: micbou <contact@micbou.com>

pkgbase=libqrencode
pkgname=('libqrencode' 'libqrencode-devel')
pkgver=4.1.1
pkgrel=3
pkgdesc="QR Code encoding library"
conflicts=(${pkgbase}-git)
replaces=(${pkgbase}-git)
arch=('i686' 'x86_64')
url='https://fukuchi.org/works/qrencode/'
msys2_repository_url="https://github.com/fukuchi/libqrencode"
license=('LGPL')
makedepends=('gcc' 'autotools' 'libiconv-devel')
source=("${pkgbase}-${pkgver}.tar.gz::https://github.com/fukuchi/libqrencode/archive/v${pkgver}.tar.gz")
sha256sums=('5385bc1b8c2f20f3b91d258bf8ccc8cf62023935df2d2676b5b67049f31a049c')
msys2_references=(
  'archlinux: qrencode'
)

prepare() {
  cd ${srcdir}/${pkgbase}-${pkgver}
  ./autogen.sh
}

build() {
  mkdir -p build-${pkgbase}-${pkgver}-${CHOST}
  cd build-${pkgbase}-${pkgver}-${CHOST}

  ../${pkgbase}-${pkgver}/configure -C \
    --prefix=/usr \
    --build=${CHOST} \
    --with-tests

  make LDFLAGS="${LDFLAGS} -no-undefined"
  make DESTDIR=${srcdir}/dest install
}

check () {
  cd build-${pkgbase}-${pkgver}-${CHOST}
  make check
}

package_libqrencode() {
  groups=('libraries')

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

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

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

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