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

pkgname=('libidn' 'libidn-devel')
pkgver=1.36
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')
options=('!libtool' 'staticlibs')
source=(https://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.gz
        libidn-1.36-msys2.patch)
sha256sums=('14b67108344d81ba844631640df77c9071d9fb0659b080326ff5424e86b14038'
            '261e78ad7ecfa793d96fe6a45c00fc0e3d101c2194f1e68344a6556fe9bb0253')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}
  patch -p1 -i $srcdir/libidn-1.36-msys2.patch

  autoreconf -ivf
}

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

package_libidn() {
  groups=('libraries')
  depends=('info')
  install=libidn.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_libidn-devel() {
  pkgdesc="Libidn headers and libraries"
  groups=('development')
  depends=("libidn=${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/
}
