# Maintainer: Marko Käning <mk-lists@mailbox.org>

_realname=bsdfprocessor
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.2.1
pkgrel=1
epoch=
pkgdesc="Application for displaying and editing of BSDF files (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://github.com/KimuraRyo/BSDFProcessor'
license=('MPL2')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-eigen3"
             "${MINGW_PACKAGE_PREFIX}-libbsdf"
             "${MINGW_PACKAGE_PREFIX}-qt5"
             "${MINGW_PACKAGE_PREFIX}-OpenSceneGraph")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-OpenSceneGraph")
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/KimuraRyo/${_realname}/archive/v${pkgver}.tar.gz"
        'optimisations-CMakeLists.txt.patch')
sha256sums=('5f9325fa887d275453bddbb18c4b794fe0ce83bb439fa486f687c468bf27c4f4'
            '55c03bbbf2b790c0aaa71f1b8638de1145c709b2ec251398acc4aef1d28121bc')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np0 -i "${srcdir}/optimisations-CMakeLists.txt.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 \
    -DLIBBSDF_DIR=${MINGW_PREFIX}/include/libbsdf \
    -DCMAKE_CXX_FLAGS=-std=c++11 \
    ../${_realname}-${pkgver}

  make
}

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

  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin
  cp -f "${srcdir}"/build-${MINGW_CHOST}/BSDFProcessor.exe ${pkgdir}${MINGW_PREFIX}/bin/bsdfprocessor.exe
}
