# Maintainer: Tao Zuhong <taozuhong@hotmail.com>

_realname=mongo-c-driver
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.1.2
pkgrel=1
pkgdesc="libbson and libmongoc, the libraries constituting the MongoDB C Driver (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/mongodb/mongo-c-driver"
license=("spdx:Apache-2.0")
msys2_references=(
  'archlinux: mongo-c-driver'
  'cpe: cpe:2.3:a:mongodb:c_driver'
  'gentoo: dev-libs/mongo-c-driver'
)
depends=("${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-zstd"
         "${MINGW_PACKAGE_PREFIX}-openssl")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("mongo-c-driver-${pkgver}.tar.gz::https://github.com/mongodb/mongo-c-driver/archive/refs/tags/${pkgver}.tar.gz")
sha256sums=('df1280403326611dd3d8277a93be2301fae481c68cc749bb746d7bea81417ee9')

prepare() {
  cd mongo-c-driver-${pkgver}
}

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

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  "${MINGW_PREFIX}"/bin/cmake.exe \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DENABLE_STATIC=ON \
	-DENABLE_SHARED=ON \
	-DENABLE_EXAMPLES=OFF \
	-DENABLE_TESTS=OFF \
	-DENABLE_ZSTD=ON \
	-DENABLE_ZLIB=BUNDLED \
	-DENABLE_SSL=OPENSSL \
	-DENABLE_SASL=OFF \
    "${_extra_config[@]}" \
    ../mongo-c-driver-${pkgver}

  "${MINGW_PREFIX}"/bin/cmake.exe --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install .
}
