# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=gn
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=0.2131.85944ebc
pkgrel=1
pkgdesc='Meta-build system that generates build files for Ninja (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://gn.googlesource.com/gn/"
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-python"
             "git")
_commit=85944ebc24a90ec1e489e85a46fdc68542c3146f
source=(git+https://gn.googlesource.com/gn#commit=$_commit
        001-build-fixes.patch
        002-add-missing-header.patch
        003-remove-msvc-flags.patch
        004-add-arm64-arch.patch)
sha256sums=('SKIP'
            '8834b44cbf1a46fd4459ff41defe84b5d97d204ffb1464365a6bd3e0496bae57'
            'd41ea264f389a34b3030ab5fb39107475a0e913123802dee241a20e1e5ecb1a5'
            '5aec933502008cbe9baabcf57e7899e8153e29c1dea646a52ac71b8eb9306801'
            'f2b66b481336de86b237b5d6062784323e6f359313a8063a9d670d9356e742d6')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -p1 -i "${srcdir}/${_patch}"
  done
}

pkgver() {
  cd ${_realname}
  echo 0.$(git rev-list --count initial-commit..).$(git rev-parse --short=8 HEAD)
}

prepare() {
  cd ${_realname}

  apply_patch_with_msg \
  001-build-fixes.patch \
  002-add-missing-header.patch \
  003-remove-msvc-flags.patch \
  004-add-arm64-arch.patch
}

build() {
  cd ${_realname}
  ./build/gen.py --allow-warnings --no-static-libstdc++

  ${MINGW_PREFIX}/bin/ninja -C ./out
}

package() {
  cd ${_realname}

  install -Dm755 out/gn.exe "${pkgdir}${MINGW_PREFIX}/bin/gn.exe"
  install -Dm644 -t "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}" docs/*
  install -Dm644 -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}" LICENSE

  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/vim/vimfiles"
  cp -r misc/vim/{autoload,ftdetect,ftplugin,syntax} \
    "${pkgdir}${MINGW_PREFIX}/share/vim/vimfiles/"
  install -Dm644 -t "${pkgdir}${MINGW_PREFIX}/share/emacs/site-lisp" misc/emacs/gn-mode.el
}

# vim:set ts=2 sw=2 et:
