# Maintainer: Tobias Powalowski <tpowa@archlinux.org>

pkgname=groff
pkgver=1.23.0
pkgrel=5.1
pkgdesc='GNU troff text-formatting system'
url='https://www.gnu.org/software/groff/groff.html'
license=('GPL')
ncxfab_makedepends=('base-devel' 'perl' 'gcc' 'make' 'sh' 'crosspacman' 'coreutils' 'patch' 'groff')
ncxfat_makedepends=('binutils' 'gcc-libs' 'glibc')
#ncxfab_makedepends=('netpbm' 'psutils'  'libxaw' 'perl-file-homedir')
# ncxfah_optdepends=('netpbm: for use together with man -H command interaction in browsers'
#             'psutils: for use together with man -H command interaction in browsers'
#             'libxaw: for gxditview'
#             'perl-file-homedir: for use with glilypond')
options=('!docs' '!emptydirs' '!makeflags')
validpgpkeys=('2D0C08D2B0AD0D3D8626670272D23FBAC99D4E75') # Bertrand Garrigues <bertrand.garrigues@laposte.net>
source=("https://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.gz"{,.sig}
        display-utc-times.patch
	site.tmac)
sha256sums=('6b9757f592b7518b4902eb6af7e54570bdccba37a871fddb2d30ae3863511c13'
            'SKIP'
            '489bb32bbd1c7bced33bf187611219527914ae46ce05238fe80dc11c4b1bb909'
            'cbcfe19bc1271b91e2c3bb8864813118863a3d8d10e6ca341f82c0ca5dc37dff')

prepare() {
  cd groff-$pkgver
  # always use UTC times for display - using localtime is problematic for reproducible builds
  # fixes FS#69123 - patch taken from Debian
  patch -Np1 -i ../display-utc-times.patch
}  

build() {
  cd groff-$pkgver

  ./configure \
    --prefix=$MPKG_USRPATH \
    --build=$MPKG_BUILDMACHINE \
    --host=$MPKG_TARGETMACHINE
    # --with-x \
    # --with-appresdir=/usr/share/X11/app-defaults
  make -j3 GROFFBIN=$(which groff) GROFF_BIN_PATH=$(dirname $(realpath $(which groff)))

}

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

package() {
  ncxfah_optdepends=('perl')
  ncxfat_depends=('gcc-libs' 'glibc')
  cd groff-$pkgver
  make DESTDIR="$pkgdir" install
  
  # add compatibility symlinks
  ln -s eqn "$pkgdir"$MPKG_USRPATH/bin/geqn
  ln -s tbl "$pkgdir"$MPKG_USRPATH/bin/gtbl
  ln -s soelim "$pkgdir"$MPKG_USRPATH/bin/zsoelim

  cat "$srcdir"/site.tmac >> \
  "$pkgdir"$MPKG_USRPATH/share/groff/site-tmac/man.local
  cat "$srcdir"/site.tmac >> \
  "$pkgdir"$MPKG_USRPATH/share/groff/site-tmac/mdoc.local
}
sha256sums=('6b9757f592b7518b4902eb6af7e54570bdccba37a871fddb2d30ae3863511c13'
            'SKIP'
            '489bb32bbd1c7bced33bf187611219527914ae46ce05238fe80dc11c4b1bb909'
            '94f28b32775bcfebf1a50231a2df9791a194d571c1651b465d4875bdea181f96')
