# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>

pkgname=rz-ghidra
_gitcommit=8df3bf7a6c392e3839dae005e3887ce953b5dabf
_gitcutter=8d4c86069055f7bc70af8845f7de3069193f6be3
pkgver=0.2.1
pkgrel=2
pkgdesc='Deep ghidra decompiler integration for rizin and rz-cutter'
url='https://github.com/rizinorg/rz-ghidra'
arch=('x86_64')
license=('LGPL3')
depends=('rizin' 'glibc')
makedepends=('git' 'cmake' 'qt5-base')
source=("git+${url}#commit=${_gitcommit}"
        "git+https://github.com/rizinorg/cutter#commit=${_gitcutter}"
        rizin-ghidra::git+https://github.com/rizinorg/ghidra.git
        git+https://github.com/zeux/pugixml.git)
sha512sums=('SKIP'
            'SKIP'
            'SKIP'
            'SKIP')

pkgver() {
  cd ${pkgname}
  git tag -d rz-0.2.0 >/dev/null
  git describe --tags --match 'rz-*' | sed 's/^rz-//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd ${pkgname}
  git submodule init
  git config submodule."third-party/pugixml".url "${srcdir}/pugixml"
  git config submodule."ghidra/ghidra".url "${srcdir}/rizin-ghidra"
  git submodule update --recursive
}

build() {
  cd ${pkgname}
  cmake \
    -B build \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=None \
    -DBUILD_CUTTER_PLUGIN=ON \
    -DBUILD_SLASPECS=ON \
    -DCUTTER_SOURCE_DIR="${srcdir}/cutter"
  make -C build VERBOSE=1
}

package() {
  cd ${pkgname}
  make -C build -j1 DESTDIR="${pkgdir}" install
  # move shared library into RZ_LIBR_PLUGINS
  rzversion=$(rizin -version|grep rizin|sed -E 's/rizin ([0-9\.]+) .*/\1/')
  install -d "${pkgdir}/usr/lib/rizin/${rzversion}"
  mv "${pkgdir}/usr/share/rizin/plugins"/*.so "${pkgdir}/usr/lib/rizin/${rzversion}"
  ln -s /usr/lib/rizin/${rzversion} "${pkgdir}/usr/lib/rizin/last"
}

# vim: ts=2 sw=2 et:
