# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: Guillaume ALAUX <guillaume@archlinux.org>
# Contributor: Andreas Radke <andyrtr@archlinux.org>

pkgbase=icedtea-web
pkgname=('icedtea-web' 'icedtea-web-doc')
pkgver=1.8.8
pkgrel=1
pkgdesc='Additional components for OpenJDK - Browser plug-in and Web Start implementation'
url='https://github.com/AdoptOpenJDK/IcedTea-Web'
arch=('x86_64')
license=('GPL2')
makedepends=('java-environment=8' 'zip' 'libxtst' 'npapi-sdk' 'rhino' 'junit'
             'firefox' 'epiphany' 'rust' 'bc')
optdepends=('rhino: for using proxy auto config files')
source=(https://github.com/AdoptOpenJDK/IcedTea-Web/archive/${pkgbase}-${pkgver}.tar.gz
        compiler-flags.patch)
sha256sums=('f4203a605a3c9c50acdcc6eef4a366b9fdd36d95edcd76bcbfede01107cb5fe6'
            '4db38a59012bf4c3dc857f340924ecbc796d89f15521abdc367bc39301be7a19')
sha512sums=('99f246ce603e3edd4357a2c4d280f1ef92e1f760ca5d843eaccf7ca60950a47defec64eed87dac26c5c2e9776bed2f3e53f2c8793dabd47e1b5fc82823190dcc'
            '0689abbe5fa5b616a3c71caf038a42bc69a4950e923cce3c658c15a85a140f5d2e19a96429fc82cfe38c42fdc7bca4a305fd613e3483a8f98a6ee3daaf0a8304')

prepare() {
  cd IcedTea-Web-${pkgbase}-${pkgver}
  patch -Np0 < "${srcdir}/compiler-flags.patch"
  autoreconf -fiv
}

build() {
  cd IcedTea-Web-${pkgbase}-${pkgver}
  ./configure \
      --prefix=/usr/share/${pkgbase} \
      --datarootdir=/usr/share \
      --with-jdk-home=/usr/lib/jvm/default \
      --with-jre-home=/usr/lib/jvm/default-runtime \
      --with-java=/usr/bin/java \
      --with-browser-tests \
      --with-firefox=/usr/bin/firefox \
      --with-epiphany=/usr/bin/epiphany \
      --with-itw-libs=DISTRIBUTION
   make
}

check() {
  cd IcedTea-Web-${pkgbase}-${pkgver}
  make -k check
}


package_icedtea-web() {
  depends=('java-runtime-openjdk' 'desktop-file-utils')
  provides=('java-web-start')

  cd IcedTea-Web-${pkgbase}-${pkgver}
  make DESTDIR="${pkgdir}" install

  # Install desktop files
  install -Dm 644 javaws.png -t "${pkgdir}"/usr/share/pixmaps
  install -Dm 644 *.desktop -t "${pkgdir}"/usr/share/applications

  ## link binaries into /usr/bin + jre/bin
  install -m 755 -d "${pkgdir}"/usr/bin
  for file in "${pkgdir}/usr/share/${pkgbase}/bin/"*; do
    ln -sf "/usr/share/${pkgbase}/bin/$(basename "${file}")" "${pkgdir}"/usr/bin
  done

  ## link the mozilla-plugin - test it here http://www.java.com/en/download/help/testvm.xml
  install -m 755 -d "${pkgdir}"/usr/lib/mozilla/plugins/
  ln -sf /usr/share/${pkgbase}/lib/IcedTeaPlugin.so "${pkgdir}"/usr/lib/mozilla/plugins/

  # remove splitted doc files
  rm -rf "${pkgdir}"/usr/share/doc
}

package_icedtea-web-doc() {
  pkgdesc+=' (documentation)'

  cd IcedTea-Web-${pkgbase}-${pkgver}
  make DESTDIR="${pkgdir}" install-data-local
  # remove javaws about and man page
  rm -rf "${pkgdir}"/usr/lib
  rm -rf "${pkgdir}"/usr/share/man
  rm -rf "${pkgdir}"/usr/share/icedtea-web
}

# vim: ts=2 sw=2 et:
