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

pkgbase=libidn2
pkgname=('libidn2' 'libidn2-devel')
_basever=2.3.8
pkgver=${_basever}
pkgrel=1
pkgdesc="Implementation of the Stringprep, Punycode and IDNA specifications"
url="https://www.gnu.org/software/libidn/#libidn2"
msys2_repository_url="https://gitlab.com/libidn/libidn2"
msys2_references=(
  "cpe: cpe:/a:gnu:libidn2"
)
arch=('i686' 'x86_64')
license=('GPL3' 'LGPL')
makedepends=('gcc' 'texinfo' 'libunistring-devel' 'gettext-devel' 'gtk-doc' 'autotools')
options=('!libtool' 'staticlibs')
source=(https://ftp.gnu.org/gnu/libidn/${pkgname}-${pkgver}.tar.gz{,.sig})
sha256sums=('f557911bf6171621e1f72ff35f5b1825bb35b52ed45325dcdee931e5d3c0787a'
            'SKIP')
validpgpkeys=('B1D2BD1375BECB784CF4F8C4D73CF638C53C06BE') # Simon Josefsson <simon@josefsson.org>

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

  # https://gitlab.com/libidn/libidn2/-/issues/108
  AUTOPOINT=true 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=('libunistring' '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_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/
}
