# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=texinfo
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=7.2
pkgrel=1
pkgdesc="GNU documentation system for on-line information and printed output (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64' 'mingw32')
url="https://www.gnu.org/software/texinfo/"
msys2_repository_url="https://git.savannah.gnu.org/cgit/texinfo.git"
msys2_references=(
  "anitya: 4958"
  "cpe: cpe:/a:gnu:texinfo"
)
license=('spdx:GPL-3.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-libiconv"
  "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-gettext-tools"
)
source=("https://ftp.gnu.org/pub/gnu/${_realname}/${_realname}-${pkgver}.tar.xz"{,.sig}
        "texinfo-install.hook.in"
        "texinfo-remove.hook.in")
sha256sums=('0329d7788fbef113fa82cb80889ca197a344ce0df7646fe000974c5d714363a6'
            'SKIP'
            'd367fe9dfa09385408cd2e2240f95738258d727449cb3b29e685925210c2a1d9'
            'ef6e404ee6a45f18957e413d2d83a7699a486bebfde28eb8d515a5f14736d948')
validpgpkeys=('EAF669B31E31E1DECBD11513DDBC579DAB37FBA9') # Gavin Smith (Texinfo maintainer) <GavinSmith0123@gmail.com>

build() {
  mkdir -p "build-${MSYSTEM}" && cd "build-${MSYSTEM}"

  ../"${_realname}-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}"

  make
}

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

  make install DESTDIR="${pkgdir}"

  for hook in texinfo-install texinfo-remove; do
    local hook_path="${srcdir}/${MINGW_PACKAGE_PREFIX}-${hook}.hook";
    cp "${srcdir}/${hook}.hook.in" "${hook_path}"
    sed -s "s|@MINGW_HOOK_TARGET_PREFIX@|${MINGW_PREFIX:1}|g" -i "${hook_path}"
    sed -s "s|@MINGW_PREFIX@|${MINGW_PREFIX}|g" -i "${hook_path}"
    install -Dt "$pkgdir/usr/share/libalpm/hooks" -m644 "${hook_path}"
  done

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
