# This was copied from the arch linux PKGBUILD.
# GNU Enscript is more or less feature complete, so it's a drop in file.

pkgname=enscript
pkgver=1.6.6
pkgrel=2
pkgdesc="Convert ASCII files to PostScript suitable for printing"
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/enscript/"
msys2_references=(
  "anitya: 699"
  "cpe: cpe:/a:gnu:enscript"
)
license=('sdpx:GPL-3.0-or-later')
depends=('perl' 'libintl' 'libiconv')
makedepends=('autotools' 'gcc' 'gettext-devel' 'libiconv-devel')
optdepends=('cygutils: Send the output to a physical printer instead of stdout.')
source=(
        "https://ftp.gnu.org/gnu/$pkgname/$pkgname-$pkgver.tar.gz"
        "300ecf85a8fe166a39f9dd818945c7b8a970db39.patch"::"https://git.savannah.gnu.org/cgit/enscript.git/patch/?id=300ecf85a8fe166a39f9dd818945c7b8a970db39"
        "enscript-EXEEXT.patch")
sha256sums=('6d56bada6934d055b34b6c90399aa85975e66457ac5bf513427ae7fc77f5c0bb'
            '53705eb99a11fbc4277140534331813fff526e5380f5d5a2046484ae92900186'
            'adba69a58e184c63fe3ac6dc7487967ce019af4bfb0313325a8a8765eee09b1a')
#public key 38734D7787901452 has been revoked
#validpgpkeys=('0862E74AAD81B2F26170064438734D7787901452')

# To avoid a mess with lpr, the config file will be patched to send to stdout by default.
prepare() {
  cd $pkgname-$pkgver
  sed -i '52s/DefaultOutputMethod: printer/DefaultOutputMethod: stdout/' lib/enscript.cfg.in

  # Also, tiny additional modification to fix issue with compilation warning fixed in the upstream git, but not stable tarball yet.
  patch -Nbp1 -i "${srcdir}/300ecf85a8fe166a39f9dd818945c7b8a970db39.patch"

  # Patch tests for .exe extension, from Cygwin
  patch -Nbp2 -i "${srcdir}/enscript-EXEEXT.patch"
}

build() {
  cd $pkgname-$pkgver
  local CYGWIN_CHOST="${CHOST/-msys/-cygwin}"
  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc/enscript \
    --build=${CYGWIN_CHOST}
  make
}

check() {
  cd $pkgname-$pkgver
  make check
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  # There is a conflict between the gettext locale.alias and the enscript supplied one.
  # The elinks PKGBUILD script for example, removes the installed one from the tarball, I'll do the same.
  rm -f "$pkgdir/usr/share/locale/locale.alias"
  # Also this one as well, can't hurt.
  rm -f "$pkgdir/usr/lib/charset.alias"
}
