# Maintainer: Matthias Aßhauer <mha1993@live.de>

_realname=antiword
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.37
pkgrel=3
pkgdesc="Convert MS Word 2.0-2003 documents to plain text or PostScript (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=('GPL3+')
url="http://www.winfield.demon.nl/"
msys2_references=(
  "cpe: cpe:/a:antiword_project:antiword"
)
source=("http://www.winfield.demon.nl/linux/${_realname}-${pkgver}.tar.gz"
        "0001-Make-antiword.exe-relocatable-on-Windows.patch")
sha256sums=('8e2c000fcbc6d641b0e6ff95e13c846da3ff31097801e86702124a206888f5ac'
            '11dee5957ffbe78537058274ef7fdacc0827080286f0cc21b1a76bca516cd89b')
provides=("${_realname}")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
noextract=("${_realname}-${pkgver}.tar.gz")

prepare(){
  tar xzf "${_realname}-${pkgver}.tar.gz" || tar xzf "${_realname}-${pkgver}.tar.gz"
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-Make-antiword.exe-relocatable-on-Windows.patch"
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make -f Makefile.Linux clean
  make -f Makefile.Linux ${_realname} CC=cc LD=cc
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  install -D -m755 ${_realname}.exe "${pkgdir}"${MINGW_PREFIX}/bin/${_realname}.exe
  install -D -m755 Resources/8859-1.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-1.txt
  install -D -m755 Resources/8859-2.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-2.txt
  install -D -m755 Resources/8859-3.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-3.txt
  install -D -m755 Resources/8859-4.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-4.txt
  install -D -m755 Resources/8859-5.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-5.txt
  install -D -m755 Resources/8859-6.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-6.txt
  install -D -m755 Resources/8859-7.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-7.txt
  install -D -m755 Resources/8859-8.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-8.txt
  install -D -m755 Resources/8859-9.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-9.txt
  install -D -m755 Resources/8859-10.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-10.txt
  install -D -m755 Resources/8859-11.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-11.txt
  install -D -m755 Resources/8859-13.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-13.txt
  install -D -m755 Resources/8859-14.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-14.txt
  install -D -m755 Resources/8859-15.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-15.txt
  install -D -m755 Resources/8859-16.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/8859-16.txt
  install -D -m755 Resources/cp437.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/cp437.txt
  install -D -m755 Resources/cp850.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/cp850.txt
  install -D -m755 Resources/cp852.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/cp852.txt
  install -D -m755 Resources/cp862.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/cp862.txt
  install -D -m755 Resources/cp864.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/cp864.txt
  install -D -m755 Resources/cp866.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/cp866.txt
  install -D -m755 Resources/cp1250.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/cp1250.txt
  install -D -m755 Resources/cp1251.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/cp1251.txt
  install -D -m755 Resources/cp1252.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/cp1252.txt
  install -D -m755 Resources/koi8-r.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/koi8-r.txt
  install -D -m755 Resources/koi8-u.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/koi8-u.txt
  install -D -m755 Resources/MacCyrillic.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/MacCyrillic.txt
  install -D -m755 Resources/MacRoman.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/MacRoman.txt
  install -D -m755 Resources/roman.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/roman.txt
  install -D -m755 Resources/UTF-8.txt "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/UTF-8.txt
  install -D -m755 Resources/fontnames "${pkgdir}"${MINGW_PREFIX}/share/${_realname}/fontnames
}
