# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=asciidoc
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
conflicts=("${MINGW_PACKAGE_PREFIX}-asciidoc-py3-git")
provides=("${MINGW_PACKAGE_PREFIX}-asciidoc-py3-git")
pkgver=9.1.0
pkgrel=1
pkgdesc="AsciiDoc is a text document format for writing notes, documentation, articles, books, ebooks, slideshows, web pages, man pages and blogs (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/asciidoc/asciidoc-py3"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-libxslt"
         "${MINGW_PACKAGE_PREFIX}-docbook-xsl")
options=('staticlibs' 'strip')
source=(https://github.com/asciidoc/asciidoc-py3/releases/download/${pkgver}/asciidoc-${pkgver}.tar.gz
        0001-W32-confdir.mingw.patch
        asciidoc.bat)
sha256sums=('fd499fcf51317b1aaf27336fb5e919c44c1f867f1ae6681ee197365d3065238b'
            'e44d1f3a98ef7e06102323843054d7443d833f421bfba55382b961fa9e4691b2'
            '526ef4f839b01f493539b27fa4cb538c130767b3b37e51037a8c0326938953d8')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/0001-W32-confdir.mingw.patch
  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  cp -rf ${_realname}-${pkgver} build-${MINGW_CHOST}
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/asciidoc.bat" "${pkgdir}${MINGW_PREFIX}/bin/asciidoc.bat"

  install -Dm644 COPYRIGHT  ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYRIGHT
}
