# 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.9.11
pkgrel=1
epoch=
pkgdesc="Library for handling BSDF files (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://github.com/KimuraRyo/libbsdf'
license=('MPL2')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-eigen3")
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/KimuraRyo/${_realname}/archive/v${pkgver}.tar.gz"
        'optimisations-CMakeLists.txt.patch'
        'missing-header.patch')
sha256sums=('3fe061d5da76201b7b04a4d146455ccea30c581155f5af847a584409fd0c3881'
            '4fc5acd2b1f046c75fcccb55c0bcb79f5408939af2a3a4c2220b248be4cae487'
            'af87d5866a8a2eb121dddf5e7dde58a376f2168615928c5038ac7b6bb1d20be6')


prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np0 -i "${srcdir}/optimisations-CMakeLists.txt.patch"
  patch -Np1 -i "${srcdir}/missing-header.patch"
}


build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_BUILD_TYPE=Release \
    -DEIGEN3_INCLUDE_DIR=${MINGW_PREFIX}/include/eigen3 \
    -DCMAKE_CXX_FLAGS=-std=c++11 \
    ../${_realname}-${pkgver}

  make
}

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-${MINGW_CHOST}/liblibbsdf.a ${pkgdir}${MINGW_PREFIX}/lib/
}
