# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=scdoc
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.11.3
pkgrel=1
license=('spdx:MIT')
pkgdesc='Tool for generating roff manual pages (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://git.sr.ht/~sircmpwn/scdoc/'
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=("${_realname}-$pkgver.tar.gz"::"https://git.sr.ht/~sircmpwn/${_realname}/archive/$pkgver.tar.gz"
        parsedate.patch)
sha512sums=('fbecc505b44c396890c53c05183d34336160dbd02993ee120421fc6e2a3ec78ba349747e8acfe97af956a0081c923309290ff97fb7babafbc3ca8addc9ec92f9'
            '564019dbc2f4dd07ac7758294da4c051eec3f8bf7c595591a99ed9e76a2fd807d016c646c2eca1ab60abdbfc2b332fdfd287c1ee18211443b6b71404e7ad4665')

prepare() {
  cd "$srcdir/${_realname}-$pkgver"
  patch -Np1 -i "${srcdir}"/parsedate.patch
  rm -rf "$srcdir/build-${MSYSTEM}"
  cp -r "$srcdir/${_realname}-$pkgver" "$srcdir/build-${MSYSTEM}"
}

build() {
  cd $srcdir/"build-${MSYSTEM}"
  # Upstream purposefully does not honor the user's LDFLAGS in order to keep
  # scdoc static. As we gain no benefit to statically linking and, in fact,
  # lose standard Arch practices (such as RELRO and PIE), we must override
  # LDFLAGS
  make PREFIX="${MINGW_PREFIX}" LDFLAGS="${LDFLAGS}"
}

check() {
  cd $srcdir/"build-${MSYSTEM}"
  make check
}

package() {
  cd $srcdir/"build-${MSYSTEM}"
  make PREFIX="${MINGW_PREFIX}" DESTDIR="${pkgdir}" install
  install -Dm644 COPYING -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
