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

pkgname=jna
pkgver=4.2.2
pkgrel=1.1
pkgdesc="Access native libraries with pure Java code."
arch=('any')
url='https://github.com/java-native-access/jna'
license=('LGPL' 'custom:ASL')
depends=('java-runtime')
makedepends=('apache-ant' 'jh')
source=("https://github.com/java-native-access/${pkgname}/archive/${pkgver}.tar.gz"
        'jna-disable_full_jar.patch')
sha1sums=('970f797cc76b42adcddcb3e1e4212366d01b07cf'
          '1a5fcf4c7765c0968c3496dea0c89146d8d97211')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  rm -rv {dist,lib,www}
  rm -rv native/libffi
  rm -v w32ce-test.lnk
  patch -Np1 -i "${srcdir}/jna-disable_full_jar.patch"
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  ant jar javadoc contrib-jars \
    -Dmaven-release=true
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  # Install license file
  install -Dm644 ASL2.0 "${pkgdir}/usr/share/licenses/${pkgname}/ASL2.0.txt"
  install -Dm644 LGPL2.1 "${pkgdir}/usr/share/licenses/${pkgname}/LGPL2.1.txt"

  # Install documentation
  install -d "${pkgdir}/usr/share/doc/${pkgname}"
  cp -r doc/javadoc "${pkgdir}/usr/share/doc/${pkgname}"

  # Install Maven artifacts
  export DESTDIR=${pkgdir}
  jh mvn-install "net.java.dev.${pkgname}" ${pkgname} ${pkgver} \
    "pom-${pkgname}.xml" \
    "build/${pkgname}.jar" \
    "${pkgname}-${pkgver}.jar"
  jh mvn-install "net.java.dev.${pkgname}" "${pkgname}-platform" ${pkgver} \
    "pom-${pkgname}-platform.xml" \
    "contrib/platform/dist/${pkgname}-platform.jar" \
    "${pkgname}-platform-${pkgver}.jar"

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