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

pkgname=('libidn' 'libidn-devel')
pkgver=1.30
pkgrel=1
pkgdesc="Implementation of the Stringprep, Punycode and IDNA specifications"
url="http://www.gnu.org/software/libidn/"
arch=('i686' 'x86_64')
license=('GPL3' 'LGPL')
makedepends=('gcc' 'make' 'pkg-config' 'texinfo')
options=('!libtool' 'staticlibs')
source=(http://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.gz
        libidn-1.26-msys2.patch)
sha1sums=('557e1e37f0978e975b21bcdc243c198cb708bb75'
          '17e3ff169c78a57d3d5839492c6dab9fa2310f96')

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

  mkdir ${srcdir}/mytemp
  cp -rf ${srcdir}/${pkgname}-${pkgver}/build-aux/snippet ${srcdir}/mytemp/
  autoreconf -ivf
  cp -rf ${srcdir}/mytemp/snippet ${srcdir}/${pkgname}-${pkgver}/build-aux/
  rm -rf ${srcdir}/mytemp
}

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/
}
