# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>

pkgname=jlex
pkgver=1.2.6
pkgrel=1.parabola2
pkgdesc="Lex-style lexical analyser generator for Java"
arch=('any')
license=('custom')
url="http://www.cs.princeton.edu/~appel/modern/java/JLex/"
depends=('java-runtime')
makedepends=('java-environment' 'jh')
source=("http://www.cs.princeton.edu/~appel/modern/java/JLex/Archive/1.2.6/Main.java"
        "http://www.cs.princeton.edu/~appel/modern/java/JLex/current/sample.lex"
        "jlex.sh")
md5sums=('fe0cff5db3e2f0f5d67a153cf6c783af'
         'ae887758b2657981d023a72a165da830'
         '902c30f6d3c2c8f6cb52b11c56e0bedf')

prepare() {
  cd ${srcdir}
  mkdir -p build/classes
  head -167 Main.java | tail -21 > LICENSE.txt
}

build() {
  cd ${srcdir}
  javac -d "build/classes" Main.java
  javadoc -d "build/javadoc" Main.java

  jar -cvfe JLex.jar JLex.Main -C "build/classes" .
}

package() {
  cd ${srcdir}

  # Install license file
  install -Dm644 LICENSE.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE.txt"

  # Install documentation
  install -d "${pkgdir}/usr/share/doc/${pkgname}"
  cp -r "build/javadoc" "${pkgdir}/usr/share/doc/${pkgname}"
  cp -r "sample.lex" "${pkgdir}/usr/share/doc/${pkgname}/examples"

  # Install jar file
  install -Dm644 JLex.jar "${pkgdir}/usr/share/java/JLex.jar"

  ln -s "/usr/share/java/JLex.jar" \
    "${pkgdir}/usr/share/java/JLex-${pkgver}.jar"

  install -Dm755 "${pkgname}.sh" "${pkgdir}/usr/bin/${pkgname}"
}
