# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=coin
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.0.0
pkgrel=4
pkgdesc="A high-level 3D graphics toolkit, fully compatible with SGI Open Inventor 2.1 (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/coin3d/coin"
license=('custom:coin')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-graphviz"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-fontconfig"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-openal")
options=('!strip' 'staticlibs' '!buildflags')
source=("coin-Coin-${pkgver}.tar.gz::https://github.com/coin3d/coin/archive/Coin-${pkgver}.tar.gz"
        'coin-4.0.0-use-cpack-off.patch')
sha256sums=('b00d2a8e9d962397cf9bf0d9baa81bcecfbd16eef675a98c792f5cf49eb6e805'
            '247e3f9d8df8cca311019bfb00c550b6f91cc895763e0e1f9384e97a7b64a612')

prepare() {
  cd "${srcdir}/coin-Coin-${pkgver}"
  patch -p1 -i "${srcdir}/coin-4.0.0-use-cpack-off.patch"
}

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

  [[ "${CARCH}" == "i686" ]] && {
    # For more info see https://github.com/coin3d/coin/issues/440
    local _cmake_opts="-DCMAKE_CXX_FLAGS=-fno-ipa-icf"
  }

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DCOIN_BUILD_DOCUMENTATION=ON \
    -DUSE_EXTERNAL_EXPAT=ON \
    -DFONTCONFIG_RUNTIME_LINKING=OFF \
    -DFREETYPE_RUNTIME_LINKING=OFF \
    -DLIBBZIP2_RUNTIME_LINKING=OFF \
    -DOPENAL_RUNTIME_LINKING=OFF \
    -DZLIB_RUNTIME_LINKING=OFF \
    -DGLU_RUNTIME_LINKING=OFF \
    -DCOIN_EXTRA_CFLAGS=-DCOIN_DLL \
    ${_cmake_opts} \
    ../coin-Coin-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  make DESTDIR=${pkgdir} install

  install -Dm644 "${srcdir}/coin-Coin-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}

# vim:set ts=2 sw=2 et:
