# Maintainer: Jeroen Ooms <jeroen@berkeley.edu>

_realname=udunits
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.2.27.6
pkgrel=1
pkgdesc="Unidata unit conversion library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=("custom")
url="https://www.unidata.ucar.edu/software/udunits/"
source=("https://github.com/Unidata/UDUNITS-2/archive/v${pkgver}.tar.gz")
sha256sums=('74fd7fb3764ce2821870fa93e66671b7069a0c971513bf1904c6b053a4a55ed1')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-expat")
options=('staticlibs' 'strip')

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'MSYS Makefiles' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_BUILD_TYPE=Release \
      ../UDUNITS-2-${pkgver}

  make
}

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