# Contributor: Sven-Hendrik Haase <[email protected]>
# Contributor: Jookia <[email protected]>
# Maintainer: Matthias "matthiaskrgr" Kr├╝ger

pkgname=desurium
pkgver=0.8.0_rc9
pkgrel=1
pkgdesc="A community-driven digital distribution service for gamers (open source version)"
url="http://github.com/lodle/Desurium"
license=('GPL3')
arch=('i686' 'x86_64')
makedepends=('cmake' 'git' 'boost' 'scons' 'gendesk' 'sed')
depends=('v8' 'tinyxml' 'boost-libs' 'flashplugin' 'libxxf86vm' 'gperf'
         'curl' 'c-ares' 'libnotify' 'libgnome-keyring' 'yasm' 'libxslt'
         'cups' 'flex' 'alsa-lib' 'libjpeg-turbo' 'speex' 'libevent'
         'gconf' 'xdg-user-dirs' 'flac' 'libwebp' 'xdg-utils')
provides=('desura')
conflicts=('desura')

CMAKE_ARGS="
    -DCMAKE_INSTALL_PREFIX=/usr
    -DBINDIR=/usr/bin
    -DDATADIR=/usr/share/
    -DRUNTIME_LIBDIR=/usr/lib/
    -DWITH_FLASH=off
    -DBUILD_CEF=OFF"

if [ "${CARCH}" = "x86_64" ]; then
    depends+=('binutils-multilib')
    CMAKE_ARGS+=" -D32BIT_SUPPORT=ON"
  else  # 32 bit
    depends+=('binutils')
fi

build() {
  cd "$srcdir"
  msg "Connecting to GIT server...."

  if [[ -d "Desurium" ]]; then
    cd "Desurium"
    msg "Removing build files..."
    rm -rf build
    msg "Updating..."
    git fetch
    msg "The repo has been updated."
  else
    msg "Cloning..."
    git clone git://github.com/lodle/Desurium.git "Desurium"
  fi

  cd "$srcdir/Desurium"
  echo "Note: checking out '$pkgver'."
  git checkout --quiet $pkgver

  msg "GIT checkout done or server timeout"
  msg "Starting build..."

  cd "$srcdir/Desurium"
  if [ ! -d build ] ; then
    mkdir build
  fi
  cd build
  msg "Running cmake..."

  cmake $CMAKE_ARGS ..
  msg "Running make..."
  make
}

check() {
  cd "$srcdir/Desurium/build"
  make test
}

package() {
  cd "$srcdir/Desurium/build"

  msg "Compiling into pkgdir this time..."
  make DESTDIR="$pkgdir/" install

  cd $srcdir

  gendesk -n ../PKGBUILD
  sed -i \
    -e 's/Icon=.*$/Icon=desura/' \
    -e 's/Exec=.*$/Exec=desura/' \
    -e 's/Categories=.*$/Categories=Game;/' \
    -e 's/Name=.*$/Name=Desurium/' ${pkgname}.desktop

  install -m644 -D \
    ${srcdir}/Desurium/src/branding_desurium/data/desura_lin.png \
    ${pkgdir}/usr/share/pixmaps/desura.png

  install -m644 -D \
    ${pkgname}.desktop \
    ${pkgdir}/usr/share/applications/desura.desktop

  msg "Compiling done"
  
  mkdir -p ${pkgdir}/usr/bin
}

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