pkgname=ninja
pkgver=1.13.1
pkgdesc='Small build system with a focus on speed'
arch=(x86_64)
homepage='https://ninja-build.org/'
license=(Apache-2.0)
sources=("${pkgname}-${pkgver}.tar.gz")
urls=("https://github.com/ninja-build/ninja/archive/v${pkgver}/${sources[0]}")
md5sums=("c35f8f55f4cf60f1a916068d8f45a0f8")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  sed -i '/int Guess/a \
  int   j = 0;\
  char* jobs = getenv( "NINJAJOBS" );\
  if ( jobs != NULL ) j = atoi( jobs );\
  if ( j > 0 ) return j;\
' src/ninja.cc
}

src_build() {
  python3 configure.py --bootstrap --verbose
}

src_install() {
  install -d -v -m755 ${pkgdir}/usr/bin/
  install -vm755 ninja ${pkgdir}/usr/bin/
  install -vDm644 misc/bash-completion ${pkgdir}/usr/share/bash-completion/completions/ninja
  install -vDm644 misc/zsh-completion  ${pkgdir}/usr/share/zsh/site-functions/_ninja
}
