# Maintainer: Johannes Schindelin <johannes.schindelin@gmx.de>

pkgbase='msgpack-c'
pkgname=('msgpack-c' 'msgpack-c-devel')
pkgver=7.0.1
pkgrel=1
pkgdesc='MessagePack implementation for C'
arch=('i686' 'x86_64')
url='https://msgpack.org'
msys2_repository_url='https://github.com/msgpack/msgpack-c'
msys2_references=(
  'anitya: 235285'
  'archlinux: msgpack-c'
)
license=('spdx:BSL-1.0')
makedepends=(
  'cmake'
  'gcc'
  'ninja'
)
source=("https://github.com/msgpack/msgpack-c/releases/download/c-${pkgver}/${pkgbase}-${pkgver}.tar.gz")
sha256sums=('2d80f190ab89b73b513025d8aef09b144e5c07b3734dfe99dd0137725d355504')

build() {
  cd "${pkgbase}-${pkgver}"

  local _cmake_options=(
    -B build
    -G Ninja
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_INSTALL_PREFIX=/usr
    -D BUILD_SHARED_LIBS=ON
    -D MSGPACK_BUILD_EXAMPLES=OFF
    -D MSGPACK_ENABLE_STATIC=OFF
  )

  cmake "${_cmake_options[@]}"
  cmake --build build
  DESTDIR="${srcdir}/dest" cmake --install build
}

package_msgpack-c() {
  pkgdesc='MessagePack implementation for C (runtime)'
  groups=('libraries')
  depends=(
    'zlib'
  )

  install -dm755 "${pkgdir}/usr/bin"
  install -m755 "${srcdir}/dest/usr/bin/"*.dll "${pkgdir}/usr/bin/"

  install -dm755 "${pkgdir}/usr/share/licenses/${pkgname}"
  install -m644 "${pkgbase}-${pkgver}/LICENSE"* "${pkgdir}/usr/share/licenses/${pkgname}/"
}

package_msgpack-c-devel() {
  pkgdesc='MessagePack implementation for C (headers & libraries)'
  groups=('development')
  depends=(
    'zlib-devel'
  )

  mkdir -p "${pkgdir}/usr"
  cp -rf "${srcdir}/dest/usr/include" "${pkgdir}/usr/"
  cp -rf "${srcdir}/dest/usr/lib" "${pkgdir}/usr/"
}
