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

pkgname=('libidn' 'libidn-devel')
pkgver=1.43
pkgrel=1
pkgdesc="Implementation of the Stringprep, Punycode and IDNA specifications"
url="https://www.gnu.org/software/libidn/"
msys2_repository_url="https://gitlab.com/libidn/libidn"
msys2_references=(
  "cpe: cpe:/a:gnu:libidn"
)
arch=('i686' 'x86_64')
license=('GPL3' 'LGPL')
makedepends=('gcc' 'texinfo' 'autotools' 'gettext-devel' 'gtk-doc' 'gperf')
options=('!libtool' 'staticlibs')
source=(https://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.gz)
sha256sums=('bdc662c12d041b2539d0e638f3a6e741130cdb33a644ef3496963a443482d164')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}

  autoreconf -ivf

  # autoreconf leads to an outdated wint_t.m4 being used and makes things fail
  # replace the source with a newer one to fix it.. not sure what the real fix would be
  cp gl/m4/wint_t.m4 lib/m4
}

build() {
  [[ -d ${srcdir}/build-${CHOST} ]] && rm -rf ${srcdir}/build-${CHOST}
  mkdir ${srcdir}/build-${CHOST}
  cd ${srcdir}/build-${CHOST}

  export MSYSTEM=CYGWIN
  ../${pkgname}-${pkgver}/configure \
    --prefix=/usr \
    --build=${CHOST} \
    --enable-shared \
    --enable-static
  make
  make DESTDIR=${srcdir}/dest-${CHOST} install
}

package_libidn() {
  groups=('libraries')
  depends=('libintl')

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