# Maintainer: Jaroslav Lichtblau <svetlemodry@archlinux.org>
# Contributor: TDY <tdy@gmx.com>
# Contributor: Martin Dünkelmann <nc-duenkekl3 at netcologne.de>

pkgname=moneymanagerex
pkgver=1.5.5
_commit=ffcd1abb7ecfa226b3ca96e7f9320e21ba2e2cd1
pkgrel=1
pkgdesc="An easy-to-use personal finance suite"
arch=('x86_64')
url="https://github.com/moneymanagerex/moneymanagerex"
license=('GPL')
depends=('wxgtk3' 'webkit2gtk')
makedepends=('cmake' 'lsb-release' 'ccache' 'lua' 'git')
source=($pkgname::git+https://github.com/$pkgname/$pkgname#commit=$_commit)
sha256sums=('SKIP')

pkgver() {
  cd $pkgname
  git describe --abbrev=0 | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd $pkgname

## clone all submodules
  git submodule update --init

  mkdir -p build

# TODO Workaround: https://github.com/moneymanagerex/moneymanagerex/issues/2685
  sed -i "s/luaL_checkint(/luaL_checkinteger(/g" ./3rd/LuaGlue/include/LuaGlue/LuaGlueApplyTuple.h
}

build() {
  cd $pkgname/build

  cmake .. \
    -DCMAKE_BUILD_TYPE=Release \
    -DwxWidgets_CONFIG_EXECUTABLE=/usr/bin/wx-config-gtk3

  cmake --build . --target package
}

package() {
  cd $pkgname/build

  make DESTDIR="${pkgdir}" install
}
