# $Id: PKGBUILD 166675 2012-09-15 10:31:01Z guillaume $
# Maintainer: Andreas Radke <andyrtr@archlinux.org>
# Maintainer: Guillaume ALAUX <guillaume@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>

pkgbase=rhino
pkgname=('java-rhino' 'rhino' 'rhino-javadoc')
pkgver=1.7R4
pkgrel=1
arch=('any')
url="http://www.mozilla.org/rhino/"
license=('MPL')
makedepends=('apache-ant')
source=(https://github.com/downloads/mozilla/rhino/${pkgbase}${pkgver/./_}.zip
        http://mirrors.axint.net/apache/xmlbeans/binaries/xmlbeans-2.5.0.tgz
        rhino
        rhino.1
        rhino-debugger
        rhino-debugger.1
        rhino-jsc
        rhino-jsc.1)
md5sums=('ad67a3dff135e3a70f0c3528a2d6edf2'
         '982e8e3d36aa5f7839f7675adc2b0c53'
         '2006b1ac37d162597b959acd685a4bee'
         '9c6bfda92befa45d484c88f9c7a2403b'
         '08d1ab306f0e07bc9a93afead55d54e8'
         '6c86e6746df7a327b46196a2c4942e0f'
         'dad268ba00bb4182045507d4017d9815'
         'af86e6abdf97ee68958ece356a9a7bc1')

build() {
  cd ${srcdir}/${pkgbase}${pkgver/./_}
  ant \
    -Dxbean.jar=${srcdir}/xmlbeans-2.5.0/lib/xbean.jar \
    -Djsr173.jar=${srcdir}/xmlbeans-2.5.0/lib/jsr173_1.0_api.jar \
    jar \
    javadoc
}

# As explained on the build.xml, tests are difficult to run from CLI. We skip them.

package_java-rhino() {
  pkgdesc="Open-source implementation of JavaScript written entirely in Java - JAR"
  depends=('java-runtime-headless')

  cd ${srcdir}/${pkgbase}${pkgver/./_}/build/${pkgbase}${pkgver/./_}
  install -Dm644 js.jar ${pkgdir}/usr/share/java/js-${pkgver}.jar
  ln -s js-${pkgver}.jar ${pkgdir}/usr/share/java/js.jar
}

package_rhino() {
  pkgdesc="Open-source implementation of JavaScript written entirely in Java"
  depends=('java-rhino' 'java-jline')

  cd ${srcdir}

  install -dm755 ${pkgdir}/usr/bin
  install -m755 rhino rhino-debugger rhino-jsc ${pkgdir}/usr/bin/
  install -dm755 ${pkgdir}/usr/share/man/man1
  install -m755 rhino.1 rhino-debugger.1 rhino-jsc.1 ${pkgdir}/usr/share/man/man1/
}

package_rhino-javadoc() {
  pkgdesc="Open-source implementation of JavaScript written entirely in Java - Javadoc"

  cd ${srcdir}/${pkgbase}${pkgver/./_}/build/${pkgbase}${pkgver/./_}
  install -m755 -d ${pkgdir}/usr/share/${pkgbase}
  cp -r javadoc ${pkgdir}/usr/share/${pkgbase}
}