# Maintainer: suacayipkisi <konuki8523@gmail.com>
# The source is the v$pkgver tag's archive on GitHub. For a new release: bump pkgver (and the
# metadata: `makepkg --printsrcinfo > .SRCINFO`), push the tag, then run
# packaging/aur/update-checksum.sh, which puts that archive's sha256 here and in .SRCINFO.
# packaging/build.sh cannot catch a stale checksum: it builds from the working tree's tarball and
# replaces the checksum with that one's.
pkgbase=t-code-ide
pkgname=('t-code-ide' 't-code-matlab' 't-code-octave')
pkgver=0.5.1
pkgrel=1
pkgdesc='Lightweight C/C++ IDE: file tree, editor tabs with clangd and a shell'
arch=('x86_64')
url='https://github.com/suacayipkisi/t-code'
license=('MIT')
depends=('glib2' 'gtk4' 'gtksourceview5' 'json-glib' 'vte4' 'md4c' 'clang' 'git'
         'ttf-cascadia-code' 'hicolor-icon-theme' 'librsvg')
makedepends=('pkgconf')
conflicts=('t-code')
optdepends=('ripgrep: faster Search panel (falls back to grep)'
            'gdb: the debugger (F5)'
            'mercurial: Source Control in Mercurial repositories'
            'subversion: Source Control in Subversion working copies')
source=("t-code-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz")
sha256sums=('c88fc737a54a88f535da798b36bf8920af9b2904954115fc1e86112d20f1f5f1')

build() {
  cd "t-code-$pkgver"
  make build/t-code
}

check() {
  cd "t-code-$pkgver"
  build/t-code --version | grep -qx "t-code $pkgver"
  # The other tests open windows and need a display.
  make build/test-searchmatch build/test-detect build/test-linediff
  build/test-searchmatch
  build/test-detect
  build/test-linediff
}

package_t-code-ide() {
  cd "t-code-$pkgver"
  make DESTDIR="$pkgdir" PREFIX=/usr install
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm644 THIRD-PARTY.md "$pkgdir/usr/share/licenses/$pkgname/THIRD-PARTY.md"
}

package_t-code-matlab() {
  pkgdesc='MATLAB plugin for t-code: run .m files in a MATLAB session (MATLAB not included)'
  arch=('any')
  depends=("t-code-ide=$pkgver" 'python')
  optdepends=()
  conflicts=()
  cd "t-code-$pkgver"
  make DESTDIR="$pkgdir" PREFIX=/usr install-plugin PLUGIN=matlab
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_t-code-octave() {
  pkgdesc='GNU Octave plugin for t-code: run .m files in an Octave session'
  arch=('any')
  depends=("t-code-ide=$pkgver" 'python')
  optdepends=('octave: the Octave it runs')
  conflicts=()
  cd "t-code-$pkgver"
  make DESTDIR="$pkgdir" PREFIX=/usr install-plugin PLUGIN=octave
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
