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

_realname=scdoc
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.11.4
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=('f8950bbef5213a89746185d5ed29fbee2502235632db883afaaac515dc87c60559bc1a39e2a3ea3bb019675e6039bd2d3b5c5d117a0ad022b61c958fb9407877'
            '9fb4201a01bdf1c194921e89c93beabdb13178acca852dec48bc4c46a09397030f7ce45bccdbed6563899d88479fd7bee0b2c06bd362566e6cb03777072fe531')

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}"
}
