# Maintainer: Marko Käning <mk-lists@mailbox.org>
# Contributor: Andrew Sun <adsun701@gmail.com>

_realname=libbsdf
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.11.0
pkgrel=1
pkgdesc="Library for handling BSDF files (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/KimuraRyo/libbsdf'
license=('spdx:MPL-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-eigen3")
source=("https://github.com/KimuraRyo/${_realname}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('1f830d4a28b0c81b77ef4bfd0d8e2dadf46b4369e4d53f43a37d761566387411')

build() {
  mkdir -p build-${MSYSTEM} && cd 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 \
    -G"Ninja" \
    -DCMAKE_BUILD_TYPE=Release \
    -DEIGEN3_INCLUDE_DIR=${MINGW_PREFIX}/include/eigen3 \
    ${extra_config[@]} \
    ../${_realname}-${pkgver}

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

package() {
  mkdir -p "${pkgdir}"${MINGW_PREFIX}/share/licenses/libbsdf
  cp -f "${srcdir}"/${_realname}-${pkgver}/LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/libbsdf

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/include
  cp -rf "${srcdir}"/${_realname}-${pkgver}/include/libbsdf "${pkgdir}"${MINGW_PREFIX}/include/

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/lib
  cp -f "${srcdir}"/build-${MSYSTEM}/liblibbsdf.a "${pkgdir}"${MINGW_PREFIX}/lib/
}
