# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=c99-to-c89
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=r169.b3d496d
pkgrel=1
pkgdesc="Tool to convert C99 code to MSVC-compatible C89 (git) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/libav/c99-to-c89.git"
license=('Apache License 2.0')
depends=("${MINGW_PACKAGE_PREFIX}-clang")
makedepends=('git')
#options=('!strip' 'debug')
source=("${_realname}"::"git+https://github.com/libav/c99-to-c89.git#branch=master"
        "0001-Less-of-the-silly-nonsense.patch"
        "0002-Ignore-trailing-cr-and-spaces-in-tests.patch")
sha256sums=('SKIP'
            '89a170a4355e86099dc04cf97cdf82fd929d9fce1a86272ab143f5f5ae3ee7a5'
            '1d9af0d12d20f756ffa98c15e107e9858f1775b0557ed16be89660097fa91b76')

pkgver() {
  cd "${srcdir}"/${_realname}
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}"/${_realname}
  git am --committer-date-is-author-date "${srcdir}"/0001-Less-of-the-silly-nonsense.patch
  git am --committer-date-is-author-date "${srcdir}"/0002-Ignore-trailing-cr-and-spaces-in-tests.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mv "${srcdir}"/${_realname} "${srcdir}"/build-${CARCH}
  cd "${srcdir}"/build-${CARCH}

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make test1 test2 test3
}

package() {
  cd "${srcdir}"/build-${CARCH}
  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin
  install -Dm755 c99wrap.exe "${pkgdir}"${MINGW_PREFIX}/bin/c99wrap.exe
  install -Dm755 c99conv.exe "${pkgdir}"${MINGW_PREFIX}/bin/c99conv.exe
  install -Dm644 LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
