
_realname=netcdf-cxx
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.3.1
pkgrel=7
pkgdesc="NetCDF C++ bindings (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/Unidata/netcdf-cxx4/"
license=(spdx:NetCDF)
depends=(
  "${MINGW_PACKAGE_PREFIX}-hdf5"
  "${MINGW_PACKAGE_PREFIX}-netcdf"
  'sed'     # for ncxx4-config
  )
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-autotools"
  )
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        '0001-netcdf-cxx-4.3.1-examples-fix-plugin-name-on-MINGW32-64-and-CLANG32-64.patch')
sha256sums=('e3fe3d2ec06c1c2772555bf1208d220aab5fee186d04bd265219b0bc7a978edc'
            'c09052c393f0eee15a0e58af9cc3fa9d42c4d1b9b5076fb84bafa2eb14a2a1f3')

prepare() {
  cd "${_realname}${pkgver/.*/}-${pkgver}"

  patch -p1 < '../0001-netcdf-cxx-4.3.1-examples-fix-plugin-name-on-MINGW32-64-and-CLANG32-64.patch'

  autoreconf -vfi
}

build() {
  mkdir -p "build-${MSYSTEM}" && cd "build-${MSYSTEM}"

  ../${_realname}${pkgver/.*/}-${pkgver}/configure -C \
    --prefix="${MINGW_PREFIX}"

  # file VERSION (generated by configure) confuses those
  # CLANG* header files which #include <version>
  mv -f VERSION .VERSION

  make libh5bzip2_la_LIBADD=-lhdf5 LIBS=-lnetcdf
}

check() {
  make -j1 check -C "build-${MSYSTEM}"
}

package() {
  make install DESTDIR="${pkgdir}" -C "build-${MSYSTEM}"
  install -Dm644 "${_realname}${pkgver/.*/}-${pkgver}"/COPYRIGHT \
    -t "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/
}
