#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobcore/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=libcap
pkgver=2.69
pkgrel=03
pkgdesc='POSIX 1003.1e capabilities'
url="https://sites.google.com/site/fullycapable/"
depends=(glibc pam gcc-libs)
makedepends=('linux-api-headers' 'go')
provides=('libcap.so' 'libpsx.so')
#options=(debug)  ## removed 20230206 by arch as an option
source=(https://kernel.org/pub/linux/libs/security/linux-privs/${pkgname}2/$pkgname-$pkgver.tar.{xz,sign}
  libcap-2.68-cgo_flags.patch)  # provide flags to go build (sent upstream)

prepare() {
  patch -Np1 -d $pkgname-$pkgver -i ../libcap-2.68-cgo_flags.patch
}

build() {
  export CGO_CPPFLAGS="$CPPFLAGS"
  export CGO_CFLAGS="$CFLAGS"
  export CGO_CXXFLAGS="$CXXFLAGS"
  export CGO_LDFLAGS="$LDFLAGS"
  export CGO_REQUIRED="1"
  export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"

  local make_options=(
    CGO_CPPFLAGS="$CPPFLAGS"
    CGO_CFLAGS="$CFLAGS"
    CGO_CXXFLAGS="$CXXFLAGS"
    CGO_LDFLAGS="$LDFLAGS"
    CGO_REQUIRED="1"
    GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"
    DYNAMIC=yes
    KERNEL_HEADERS=/usr/include
    lib=lib
    prefix=/usr
    sbindir=bin
    -C $pkgname-$pkgver
  )

  make "${make_options[@]}"
}

## 2.68  some test fails on chroot comment this out and rerun makepkg with out -f
##
#check() {
#  make test -k -C $pkgname-$pkgver
#}
##
##

package() {
  local make_options=(
    DESTDIR="$pkgdir"
    RAISE_SETFCAP=no
    lib=lib
    prefix=/usr
    sbindir=bin
    install
    -C $pkgname-$pkgver
  )

  make "${make_options[@]}"
  install -vDm 644 $pkgname-$pkgver/{CHANGELOG,README} -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 644 $pkgname-$pkgver/pam_cap/capability.conf -t "$pkgdir/usr/share/doc/$pkgname/examples/"
  install -vDm 644 $pkgname-$pkgver/License -t "$pkgdir/usr/share/licenses/$pkgname/"
}

#---- arch license gpg-key & sha256sums ----

arch=(x86_64)

license=('BSD-3-Clause OR GPL-2.0-only')

validpgpkeys=(38A644698C69787344E954CE29EE848AE2CCF3F4) # Andrew G. Morgan <morgan@kernel.org>

sha256sums=(f311f8f3dad84699d0566d1d6f7ec943a9298b28f714cae3c931dfd57492d7eb  # libcap-2.69.tar.xz
	40407278583f276879e9e0e36ad37ab3cac235910fad74037c5113d1aa943849  # libcap-2.69.tar.sign
	1fcf9739cb0a6e9811680e4ead34f37ff50e9367a398802e89cb824b24e3cbba) # libcap-2.68-cgo_flags.patch

##  62fced6085127808d38a6741294464fd73bd0206f4e774d179f32baf1214a494  libcap-2.69-03-x86_64.pkg.tar.lz

