# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=tiny-dnn
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.0a3
pkgrel=2
pkgdesc="C++14 implementation of deep learning (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('BSD3')
depends=("${MINGW_PACKAGE_PREFIX}-intel-tbb"
         "${MINGW_PACKAGE_PREFIX}-protobuf")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
url="https://tiny-dnn.readthedocs.io/"
source=(${_realname}-${pkgver}.tar.gz::https://github.com/tiny-dnn/tiny-dnn/archive/v${pkgver}.tar.gz
        build-fixes.patch)
options=('!strip' 'staticlibs')
sha256sums=('e2c61ce8c5debaa644121179e9dbdcf83f497f39de853f8dd5175846505aa18b'
            '4b0660757ca19127dff48796d15e2c072ea03417700fbf7a43babd71ef6e6602')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/build-fixes.patch
}

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=RELEASE \
    -DUSE_TBB=ON \
    ../${_realname}-${pkgver}

  make generated_proto
}

package() {
  cd "${srcdir}//build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
