# Maintainer: Kevin Yue <k3vinyue@gmail.com>

_pkgname_prefix=globalprotect-openconnect
pkgname="${_pkgname_prefix}-git"
pkgver=3.3.1.r623.g4085368
pkgrel=1
pkgdesc="A GUI client for GlobalProtect VPN, based on OpenConnect, supports the SSO authentication method."
arch=(x86_64 aarch64)
url="https://github.com/yuezk/GlobalProtect-openconnect"
license=('GPL3')

makedepends=(git pkg-config make autoconf automake gettext libtool patch curl wget file appmenu-gtk-module librsvg cargo)
depends=(webkit2gtk-4.1 libappindicator-gtk3 libsecret libxml2 zlib lz4 gnutls libp11-kit nettle libhogweed.so gmp shared-mime-info desktop-file-utils xdg-utils)
optdepends=('wmctrl: for window management')

conflicts=('globalprotect-openconnect')
provides=('globalprotect-openconnect' 'gpclient' 'gpservice' 'gpauth' 'gpgui')

install=gp.install

source=("${_pkgname_prefix}::git+https://github.com/yuezk/GlobalProtect-openconnect.git#branch=main")

sha256sums=("SKIP")

# GCC LTO objects from native dependencies cannot be linked by Rust's LLD.
options=('!strip' '!lto')

pkgver() {
  cd "${_pkgname_prefix}"

  local version
  version="$(awk -F '"' '
    /^\[workspace.package\]$/ { in_workspace = 1; next }
    in_workspace && /^version = / { print $2; exit }
  ' Cargo.toml)"
  printf '%s.r%s.g%s\n' "$version" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${_pkgname_prefix}"
  git submodule update --init --recursive

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_pkgname_prefix}"
  cargo build --frozen --release
}

package() {
  cd "${_pkgname_prefix}"

  DESTDIR="$pkgdir" make install
}
