# Maintainer: AndyRTR <andyrtr@archlinux.org>
# Contributor: Mantas Mikulėnas <grawity@gmail.com>

pkgname=gssproxy
pkgver=0.9.2
pkgrel=2
pkgdesc="GSSAPI Proxy"
arch=(x86_64 aarch64)
url="https://github.com/gssapi/gssproxy"
license=('custom: MIT')
depends=('libverto-module-base' 'popt' 'ding-libs' 'systemd-libs'
         'krb5' 'glibc')
makedepends=('libxslt' 'systemd' 'docbook-xsl' 'doxygen'  'po4a')
options=('emptydirs' 'makeflags')
backup=(etc/gssproxy/{gssproxy,24-nfs-server,80-httpd,99-network-fs-clients}.conf
        etc/gss/mech.d/proxymech.conf)
source=(https://github.com/gssapi/gssproxy/releases/download/v$pkgver/$pkgname-$pkgver.tar.gz
        0001-Fix-various-issues-detected-by-static-analysis.patch)
# https://github.com/gssapi/gssproxy/releases/download/v0.9.2/gssproxy-0.9.2.tar.gz.sha512sum.txt
sha512sums=('6de484c9c1715e8b845106e1b16e1c29805e4104db296eb44ea15e6b6973fd1df0b043d2cdc2798f04c7a0ce66279e356a285684bc3573ef847532ab2b87aca3'
            'f2777d08ae7df74a25bc007227bdea250ca9e9931e145235f2778c4838fbf5deaf11f296d4eb0e2f2d5e568189987003d0f8ad37d0210d20f8e6e9587e6ba906')

prepare() {
  cd "$srcdir/gssproxy-$pkgver"
  patch -Np1 -i ../0001-Fix-various-issues-detected-by-static-analysis.patch

  autoreconf -vfi
}

build() {
  CFLAGS+=" -std=gnu17" #fix build with gcc-15

  cd gssproxy-$pkgver
  ./configure --prefix=/usr \
    --sysconfdir=/etc  \
    --with-pubconf-path=/etc/gssproxy \
    --sbindir=/usr/bin \
    --localstatedir=/var \
    --without-selinux \
    --with-initscript=systemd \
    --with-gpp-default-behavior=REMOTE_FIRST
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

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


package() {
  cd gssproxy-$pkgver
  make DESTDIR=$pkgdir install
  
  # cleanup empty directories
  rm -rf "$pkgdir"/usr/include
  rm -rf "$pkgdir"/usr/share/doc

  # install default config files
  install -m644 examples/gssproxy.conf "$pkgdir"/etc/gssproxy/gssproxy.conf
  # nfs services
  install -m644 examples/24-nfs-server.conf "$pkgdir"/etc/gssproxy/24-nfs-server.conf
  install -m644 examples/99-network-fs-clients.conf "$pkgdir"/etc/gssproxy/99-network-fs-clients.conf
  # httpd service / use Arch UID/GID http/33 (by pkg filesystem)
  install -m644 examples/80-httpd.conf "$pkgdir"/etc/gssproxy/80-httpd.conf
  sed -i -e "s:euid = apache:euid = http:" "$pkgdir"/etc/gssproxy/80-httpd.conf

#  install -Dm644 examples/mech  "$pkgdir"/etc/gss/mech.d/gssproxy.conf
  
  # FS#51574
  install -m700 -d ${pkgdir}/var/lib/gssproxy/rcache

  install -m755 -d ${pkgdir}/usr/share/licenses/$pkgname
  install -m644 COPYING ${pkgdir}/usr/share/licenses/$pkgname/
}
