# Maintainer: Yusuke Sasaki <yusuke.sasaki.nuem@gmail.com>

_realname=msgpack-c
pkgbase="mingw-w64-${_realname}"
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=6.1.0
pkgrel=1
pkgdesc="MessagePack implementation for C and C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/msgpack/msgpack-c"
license=('spdx:BSL-1.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/msgpack/msgpack-c/releases/download/c-${pkgver}/msgpack-c-${pkgver}.tar.gz")
sha256sums=('674119f1a85b5f2ecc4c7d5c2859edf50c0b05e0c10aa0df85eefa2c8c14b796')

build() {
  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=" \
    cmake -G "Ninja" -B "build-${MSYSTEM}" -S "msgpack-c-${pkgver}" \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DMSGPACK_BUILD_EXAMPLES=OFF \
      -DMSGPACK_BUILD_TESTS=OFF \
      -DMSGPACK_ENABLE_SHARED=ON \
      -DMSGPACK_ENABLE_STATIC=ON \
      "${extra_config[@]}"

  cmake --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}"
  install -Dm644 "${srcdir}"/msgpack-c-${pkgver}/LICENSE_1_0.txt -t "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}
}
