# $Id: PKGBUILD 106362 2014-03-01 03:49:24Z fyan $
# Maintainer: Felix Yan <felixonmars@gmail.com>
# Contributor: Jaroslav Lichtblau <dragonlord@aur.archlinux.org>
# Contributor: Michal Krenek <mikos@sg1.cz>

pkgbase=boinc
pkgname=(boinc boinc-nox)
pkgver=7.2.42
_tag="client_release/7.2/$pkgver"
pkgrel=1
arch=('i686' 'x86_64')
url="http://boinc.berkeley.edu/"
license=('LGPL')
makedepends=('libxslt' 'perl-xml-sax' 'git' 'libxss' 'libnotify' 'wxgtk2.8' 'sqlite3' 'curl' 'inetutils' 'libxmu' 'freeglut' 'glu' 'mesa')
install=$pkgbase.install
source=("git://boinc.berkeley.edu/boinc-v2.git#tag=$_tag"
	boinc.bash
	boinc.desktop
	boinc.service
	boinc-AM_CONDITIONAL.patch)

prepare() {
  cd "$srcdir/$pkgbase-v2"
  patch -Np1 -i "${srcdir}/boinc-AM_CONDITIONAL.patch"

  ./_autosetup

  cp -r "$srcdir/$pkgbase-v2" "$srcdir/$pkgbase-v2-nox"
}

build() {
  msg "Starting make..."
  
  cd "$srcdir/$pkgbase-v2"
  LDFLAGS='-lX11' ./configure \
    --prefix=/usr \
    --disable-server \
    --enable-unicode \
    --with-ssl \
    --enable-dynamic-client-linkage \
    --with-wxdir=/usr/lib \
    --with-wx-config=$(which wx-config-2.8) \
    --disable-static \
    --enable-client \
    --enable-manager \
    --with-x
  make

  # Build boinc-nox
  cd "$srcdir/$pkgbase-v2-nox"
  PKG_CONFIG="$(which pkg-config)" ./configure \
    --prefix=/usr \
    --disable-server \
    --enable-unicode \
    --with-ssl \
    --enable-dynamic-client-linkage \
    --disable-xss \
    --disable-static \
    --enable-client \
    --disable-manager \
    --without-wxdir \
    --without-x
  make
}

package_boinc() {
  pkgdesc="Berkeley Open Infrastructure for Network Computing for desktop"
  depends=("libxss" "libnotify" "wxgtk2.8" "curl" "sqlite3")

  cd $pkgbase-v2

  make DESTDIR="$pkgdir" install

  #install systemd unit
  install -Dm644 "${srcdir}/$pkgbase.service" "${pkgdir}/usr/lib/systemd/system/$pkgbase.service"

  #install bash-completion
  install -Dm644 "${srcdir}/$pkgbase.bash" "${pkgdir}/usr/share/bash-completion/completions/$pkgbase"

  #install .desktop File
  install -Dm644 "${srcdir}/${pkgbase}.desktop" "${pkgdir}/usr/share/applications/${pkgbase}.desktop"

  #install icons
  install -Dm644 "${srcdir}/${pkgbase}-v2/clientgui/res/boincmgr.48x48.png" "${pkgdir}/usr/share/pixmaps/$pkgbase.png"

  #remove initscripts stuff
  rm -rf "$pkgdir/etc"
}

package_boinc-nox() {
  pkgdesc="Berkeley Open Infrastructure for Network Computing for desktop without Xorg dependencies"
  depends=("curl" "libjpeg-turbo")
  provides=("boinc")
  conflicts=("boinc")

  cd $pkgbase-v2-nox

  make DESTDIR="$pkgdir" install

  #install systemd unit
  install -Dm644 "${srcdir}/$pkgbase.service" "${pkgdir}/usr/lib/systemd/system/$pkgbase.service"

  #install bash-completion
  install -Dm644 "${srcdir}/$pkgbase.bash" "${pkgdir}/usr/share/bash-completion/completions/$pkgbase"

  #remove initscripts stuff
  rm -rf "$pkgdir/etc"
}

md5sums=('SKIP'
         '4d00e1aa4090a3f51feb20f5a541b9ee'
         'db62de2f08117e6379a3c613b58fa7ff'
         '3d5cbab785cc8b004661b17c65883fd5'
         'e27047518dec54d4db38816487a28661')
