# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Anatol Pomozov <anatol.pomozov@gmail.com>
# Contributor: Filip Brcic <brcha@gna.org>
# Contributor: Mika Fischer <mika.fischer@zoopnet.de>
# Contributor: Gergely Imreh <imrehgATgmailDOTcom>

pkgname=ninja
pkgver=1.12.1
pkgrel=1.2
pkgdesc='Small build system with a focus on speed'
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url='https://ninja-build.org/'
license=(Apache-2.0)
depends=(gcc-libs)
makedepends=(cmake python re2c emacs-nox)
checkdepends=(gtest)
source=($pkgname-$pkgver.zip::https://github.com/ninja-build/ninja/archive/v$pkgver.zip)
sha1sums=('ebdc7b4e92dd25fa91d7801ad150bd4b7a4990ce')
sha256sums=('40db6f6c77045efc817209fa72c3f92a399b7e39cf8e4cddfe7e65df2dd5dcbe')

build() {
  cd ninja-$pkgver

  cmake -Bbuild-cmake
  cmake --build build-cmake
  emacs -Q --batch -f batch-byte-compile misc/ninja-mode.el
}

check() {
  cd ninja-$pkgver
  ./build-cmake/ninja_test
}

package() {
  cd ninja-$pkgver

  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  install -m755 -D build-cmake/ninja "$pkgdir/usr/bin/ninja"
  install -m644 -D doc/manual.asciidoc "$pkgdir/usr/share/doc/ninja/manual.asciidoc"
  install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"

  install -m644 -D misc/ninja-mode.el "$pkgdir/usr/share/emacs/site-lisp/ninja-mode.el"
  install -m644 -D misc/ninja-mode.elc "$pkgdir/usr/share/emacs/site-lisp/ninja-mode.elc"
  install -m644 -D misc/ninja.vim "$pkgdir/usr/share/vim/vimfiles/syntax/ninja.vim"
  install -m644 -D misc/ninja_syntax.py "$pkgdir/$site_packages/ninja_syntax.py"

  install -m644 -D misc/bash-completion "$pkgdir/usr/share/bash-completion/completions/ninja"
  install -m644 -D misc/zsh-completion "$pkgdir/usr/share/zsh/site-functions/_ninja"
}
