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

pkgname=groff
pkgver=1.23.0
pkgrel=8
pkgdesc='GNU troff text-formatting system'
arch=('x86_64' 'aarch64')
url='https://www.gnu.org/software/groff/groff.html'
license=('GPL-3.0-or-later')
depends=(
  glibc
  libgcc
  libstdc++
  perl
)
makedepends=(
  git
  netpbm
  psutils
  libxaw
  perl-file-homedir
)
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=(
  git+https://https.git.savannah.gnu.org/git/groff.git?signed#tag=${pkgver}
  display-utc-times.patch
  site.tmac
)
b2sums=('cd1d24a5d477d6ee0e6f9061bc76124937b3c166d118325d77df7e0f4346b66887ff267bbaa4b3d61f3ec55449cdd963d3fcdb62a1c62208eb3fe4be0b16edce'
        '4dde80520ac3b222f39ebaf5aa9966aacdd9a232a733c150114c826063dcba5285b14aeb821c0edf931f90df625e57dabb8a0b8bf4671ed8972d06866ad0df2a'
        '39087d04a2af011820e9428c3c01da4be63cd34125bb087097b4e56865806e33e3e20a666885110ab71d36eeafdbfb01202ca4ee45d6cdeed8ab71d83852341b')

prepare() {
  cd "${pkgname}"
  ./bootstrap
  # 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 "${pkgname}"

  ./configure \
    --prefix=/usr \
    --with-x \
    --with-appresdir=/usr/share/X11/app-defaults
  make
}

check() {
  cd "${pkgname}"
  make check
}

package() {
  cd "${pkgname}"
  make DESTDIR="$pkgdir" install
  
  # add compatibility symlinks
  ln -s eqn "${pkgdir}"/usr/bin/geqn
  ln -s tbl "${pkgdir}"/usr/bin/gtbl
  ln -s soelim "${pkgdir}"/usr/bin/zsoelim

  cat "${srcdir}"/site.tmac >> \
  "${pkgdir}"/usr/share/groff/site-tmac/man.local
  cat "$srcdir"/site.tmac >> \
  "${pkgdir}"/usr/share/groff/site-tmac/mdoc.local
}
