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

_realname=libunistring
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.10
pkgrel=4
pkgdesc="Library for manipulating Unicode strings and C strings. (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://www.gnu.org/software/libunistring"
license=('LGPL' 'GPL3')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-libiconv")
options=('staticlibs' 'strip')
source=("https://ftp.gnu.org/gnu/libunistring/${_realname}-${pkgver}.tar.gz"
        fix-pointer-casts.patch)
sha256sums=('a82e5b333339a88ea4608e4635479a1cfb2e01aafb925e1290b65710d43f610b'
            '77ae425f982b61ae69c53f689f90a0a57706be73298acb1df61cca74855edf69')

prepare() {
  cd ${srcdir}/libunistring-${pkgver}
  patch -Nbp1 -i ${srcdir}/fix-pointer-casts.patch
  autoreconf -fiv
}

build() {
  #export lt_cv_deplibs_check_method='pass_all'
  [[ -d "${srcdir}/build-static-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-static-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-static-${MINGW_CHOST}" && cd "${srcdir}/build-static-${MINGW_CHOST}"
  ../libunistring-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-threads=windows \
    --disable-shared

  make

  [[ -d "${srcdir}/build-shared-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-shared-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-shared-${MINGW_CHOST}" && cd "${srcdir}/build-shared-${MINGW_CHOST}"
  ../libunistring-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-threads=windows \
    --disable-static

  make
}

package() {
  cd "${srcdir}/build-static-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  cd "${srcdir}/build-shared-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.LIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.LIB"
}
