# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase=libidn2
pkgname=('libidn2' 'libidn2-devel')
_basever=2.3.2
_subver=
pkgver=${_basever}${_subver}
pkgrel=1
pkgdesc="Implementation of the Stringprep, Punycode and IDNA specifications"
url="https://www.gnu.org/software/libidn/"
arch=('i686' 'x86_64')
license=('GPL3' 'LGPL')
makedepends=('gcc' 'make' 'pkg-config' 'texinfo' 'libunistring-devel' 'gtk-doc')
options=('!libtool' 'staticlibs')
source=(https://ftp.gnu.org/gnu/libidn/${pkgname}-${pkgver}.tar.gz{,.sig}
        libidn2-2.1.0-msys2.patch)
sha256sums=('76940cd4e778e8093579a9d195b25fff5e936e9dc6242068528b437a76764f91'
            'SKIP'
            'fe42d024e9e4bd0d8abdab43b48ad4812a0a42f6a99f01f9862a3b9c03d1577d')
validpgpkeys=('9AA9BDB11BB1B99A21285A330664A76954265E8C') # Simon Josefsson <simon@josefsson.org>

prepare() {
  cd ${srcdir}/${pkgname}-${_basever}
  patch -p1 -i ${srcdir}/libidn2-2.1.0-msys2.patch

  autoreconf -ivf
}

build() {
  [[ -d ${srcdir}/build-${CHOST} ]] && rm -rf ${srcdir}/build-${CHOST}
  mkdir ${srcdir}/build-${CHOST}
  cd ${srcdir}/build-${CHOST}
  ../${pkgname}-${_basever}/configure \
    --prefix=/usr \
    --build=${CHOST} \
    --enable-shared \
    --enable-static
  make
  make DESTDIR=${srcdir}/dest-${CHOST} install
}

package_libidn2() {
  groups=('libraries')
  depends=('info' 'libunistring')
  install=libidn2.install

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest-${CHOST}/usr/bin/*.dll ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest-${CHOST}/usr/share ${pkgdir}/usr/
}

package_libidn2-devel() {
  pkgdesc="Libidn2 headers and libraries"
  groups=('development')
  depends=("libidn2=${pkgver}")

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest-${CHOST}/usr/bin/*.exe ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest-${CHOST}/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest-${CHOST}/usr/lib ${pkgdir}/usr/
}
