# Maintainer: Márcio Silva <coadde@lavabit.com>

_bldname=blender
_bldver=2.68
_bldep=10

# ($srcdir/Tools/${_bldname^}2.5Export/__init__.py:bl_info>version)
_addver=2.0.1
_addrel=1

pkgbase=ogre
pkgname=(
  $pkgbase-libre
  #$_bldname-addon-$pkgbase # package unstable
)
pkgver=1.8.1
pkgrel=5
pkgdesc='Scene-oriented, flexible 3D engine written in C++, without nonfree software support and files'
arch=(
  mips64el
  x86_64
  i686
)
url=http://www.${pkgbase}3d.org
license=MIT
depends=(
  boost-libs
  freeimage
  freetype2
  glu
  libxaw
  libxrandr
  ois
  zziplib
)
makedepends=(
  boost
  cmake
  doxygen
  graphviz
  mesa
  ttf-dejavu
)
source=https://downloads.sourceforge.net/$pkgbase/${pkgbase}_src_v${pkgver//./-}.tar.bz2
sha512sums=0bbce593e5a9ebf51e3cb53661f6447d99ae28a53365d7f518c6d408216690527ef7552385160cff8d5c3ef15d3ab5c2520ef2c1f51fda5541d5d4dca4663ae2

build() {
  cd $srcdir/${pkgbase}_src_v${pkgver//./-}

  # get a clean build dir
  [[ -d build ]] && rm -vrf build
  mkdir -v build && cd build

  # SAMPLES, SAMPLES_SOURCE and TESTS are nonfree
  cmake .. \
    -DCMAKE_BUILD_TYPE=Release\
    -DCMAKE_INSTALL_PREFIX=/usr\
    -DCPACK_PACKAGE_DESCRIPTION_SUMMARY='Libre 3D Graphics Engine'\
    -D${pkgbase^^}_BUILD_COMPONENT_PAGING=TRUE\
    -D${pkgbase^^}_BUILD_COMPONENT_PROPERTY=TRUE\
    -D${pkgbase^^}_BUILD_COMPONENT_RTSHADERSYSTEM=TRUE\
    -D${pkgbase^^}_BUILD_COMPONENT_TERRAIN=TRUE\
    -D${pkgbase^^}_BUILD_PLATFORM_NACL=FALSE\
    -D${pkgbase^^}_BUILD_PLUGIN_BSP=TRUE\
    -D${pkgbase^^}_BUILD_PLUGIN_OCTREE=TRUE\
    -D${pkgbase^^}_BUILD_PLUGIN_PCZ=TRUE\
    -D${pkgbase^^}_BUILD_PLUGIN_PFX=TRUE\
    -D${pkgbase^^}_BUILD_RENDERSYSTEM_GL=TRUE\
    -D${pkgbase^^}_BUILD_RENDERSYSTEM_GLES=FALSE\
    -D${pkgbase^^}_BUILD_RENDERSYSTEM_GLES2=FALSE\
    -D${pkgbase^^}_BUILD_RTSHADERSYSTEM_CORE_SHADERS=TRUE\
    -D${pkgbase^^}_BUILD_RTSHADERSYSTEM_EXT_SHADERS=TRUE\
    -D${pkgbase^^}_BUILD_SAMPLES=FALSE\
    -D${pkgbase^^}_BUILD_TESTS=FALSE\
    -D${pkgbase^^}_BUILD_TOOLS=TRUE\
    -D${pkgbase^^}_CONFIG_ENABLE_DDS=TRUE\
    -D${pkgbase^^}_CONFIG_ENABLE_FREEIMAGE=TRUE\
    -D${pkgbase^^}_CONFIG_ENABLE_GLES2_GLSL_OPTIMISER=TRUE\
    -D${pkgbase^^}_CONFIG_ENABLE_PVRTC=TRUE\
    -D${pkgbase^^}_CONFIG_ENABLE_VIEWPORT_ORIENTATIONMODE=TRUE\
    -D${pkgbase^^}_CONFIG_ENABLE_ZIP=TRUE\
    -D${pkgbase^^}_CONFIG_NEW_COMPILERS=TRUE\
    -D${pkgbase^^}_CONFIG_THREAD_PROVIDER=boost\
    -D${pkgbase^^}_INSTALL_DOCS=FALSE\
    -D${pkgbase^^}_INSTALL_SAMPLES=FALSE\
    -D${pkgbase^^}_INSTALL_SAMPLES_SOURCE=FALSE\
    -D${pkgbase^^}_INSTALL_TOOLS=TRUE\
    -D${pkgbase^^}_LIB_DIRECTORY=lib\
    -D${pkgbase^^}_PROFILING=TRUE\
    -D${pkgbase^^}_USE_BOOST=TRUE
  make V=0
}

package_ogre-libre() {
  optdepends=(
    "boost: for developing using $pkgbase"
    "$pkgbase-docs: documentation"
  )
  provides=($pkgbase=$pkgver)
  conflicts=$pkgbase
  replaces=$pkgbase

  cd $srcdir/${pkgbase}_src_v${pkgver//./-}/build

  make DESTDIR=$pkgdir install

  # install license
  install -vDm644 ../Docs/License.html $pkgdir/usr/share/licenses/$pkgbase/license.html

  # remove nonfree files
  rm -vr $pkgdir/usr/lib/OGRE/cmake
  rm -v $pkgdir/usr/include/OGRE/Example*.h
}

package_blender-addon-ogre() {
  pkgdesc="${pkgbase^} Mesh Exporter: A addon for the ${_bldname^} which allows export mesh and (skeletal/morph/pose) animations to ${pkgbase^}3D format (built for the $_bldname-libre package)"
  arch=any
  depends=(
    "$_bldname-libre>=$(($_bldep-1)):$_bldver"
    "$_bldname-libre<$_bldep:${_bldver::2}$((${_bldver:2:4}+1))"
  )
  _pkgver=$pkgver
  pkgver=$_addver.v$_bldver
  pkgrel=$_addrel

  cd $srcdir/${pkgbase}_src_v${_pkgver//./-}
  a=$pkgdir/usr/share/$_bldname/$_bldver/scripts/addons               
  install -vd $a && cp -va Tools/${_bldname^}2.5Export $a/$pkgbase
}

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