summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 1fd615978e96614dfa7ea59842ce0ad2472b0496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Maintainer: Aaron McDaniel (mcd1992) <'aur' at the domain 'fgthou.se'>

pkgname=kaitai-struct-compiler-git
pkgver=0.8.r56.g078d45b
pkgrel=1
pkgdesc='Kaitai Struct Compiler: Compiler for the Kaitai declarative binary format parsing language'
url='http://kaitai.io'
arch=('x86_64')
license=('GPL')
depends=('scala' 'java-runtime')
makedepends=('git' 'sbt' 'unzip')
optdepends=()
backup=()
source=("${pkgname}::git+https://github.com/kaitai-io/kaitai_struct.git")
md5sums=('SKIP')
provides=('kaitai-struct-compiler')
conflicts=('kaitai-struct-compiler')

pkgver() {
  cd ${pkgname}
  # Remove 'v' prefix on tags; prefix revision with 'r'; replace all '-' with '.'
  git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd ${pkgname}

  # Pull in compiler and example formats submodules
  git submodule update --init compiler/ formats/
}

build() {
  # Build the kaitai-compiler
  cd "${srcdir}/${pkgname}/compiler"
  sbt compilerJVM/universal:packageBin
}

package() {
  cd "${pkgdir}"
  mkdir -p "usr/share/${pkgname}/"

  # Unzip the compiler universal .zip into a temporary directory
  unzip "${srcdir}/${pkgname}/compiler/jvm/target/universal/kaitai-struct-compiler-*.zip" -d compiler-unzip

  # Copy all files out of the unzip directory into compiler-tmp/
  mkdir -p compiler-tmp/
  cp -a compiler-unzip/kaitai-struct-compiler-*/* "compiler-tmp/"

  # Install ksy files into usr/share
  mv "compiler-tmp/formats" "usr/share/${pkgname}/"

  # Install java jar / classes
  mkdir -p "${pkgdir}/usr/share/java/kaitai-struct-compiler/"
  mv compiler-tmp/lib/*.jar "${pkgdir}/usr/share/java/kaitai-struct-compiler/"

  # Install binaries
  mkdir -p "${pkgdir}/usr/bin/"
  mv compiler-tmp/bin/* "${pkgdir}/usr/bin/"

  # Patch kaitai-struct-compiler binary to point to system lib instead of installdir lib
  sed -ir 's/^declare -r lib_dir=.*/declare -r lib_dir="\/usr\/share\/java\/kaitai-struct-compiler"/' "${pkgdir}/usr/bin/kaitai-struct-compiler"

  # Remove temporary directories
  rm -rf "${pkgdir}/compiler-unzip"
  rm -rf "${pkgdir}/compiler-tmp"

  # Cleanup unused files
  find "${pkgdir}" -type f -iname "*.bat" -delete
}