# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Sébastien Luttringer
# Contributor: Lawrence Lee <valheru@facticius.net>
# Contributor: Phillip Marvin <phillip.marvin@gmail.com>
# Contributor: keystone <phillip.marvin@gmail.com>

pkgname=libunwind
pkgver=1.8.2
pkgrel=1
pkgdesc="Determine and manipulate the call-chain of a program"
url="https://www.nongnu.org/libunwind/"
arch=(x86_64 aarch64)
license=(MIT)
depends=(
  glibc
  xz
  zlib
)
makedepends=(texlive-binextra)
provides=(
  libunwind-{coredump,ptrace,setjmp}.so
  libunwind.so
)
provides_x86_64=(libunwind-x86_64.so)
provides_aarch64=(libunwind-aarch64.so)

source=(
  https://github.com/libunwind/libunwind/releases/download/v$pkgver/libunwind-$pkgver.tar.gz{,.asc}
  https://github.com/libunwind/libunwind/commit/b67d508a.patch
)
b2sums=('b198b186c616adf1302d153a12949ceab07608f8133e42454e6b10bdf9518a514ef15d5ba52ef75b11e5f73fa330205accd415cfc30e6fa3ddd9724cbb088737'
        'SKIP'
        '756ced55c34a33d55cc11f61c32230de820aede55d562aa94143c2f5adb7f408ed2f2d5c48642b035ec4d3ebc59175e6f4b889f712db2556b80a8002d91aa036')
validpgpkeys=(
  F86EB09F72717426F20D36470A0FF845B7DB3427  # Stephen M. Webb <stephen.webb@bregmasoft.ca>
)

prepare() {
  cd libunwind-$pkgver
  patch -p1 -i ../b67d508a.patch # Fix build with GCC 15
}

build() {
  local configure_options=(
    --prefix=/usr
    --sysconfdir=/etc
    --localstatedir=/var
  )

  [ $CARCH = aarch64 ] && CFLAGS="$CFLAGS -mno-outline-atomics"

  cd libunwind-$pkgver
  ./configure "${configure_options[@]}"
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

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

package() {
  cd libunwind-$pkgver
  make DESTDIR="$pkgdir" install
  install -Dm 644 COPYING -t "$pkgdir"/usr/share/licenses/$pkgname
  rm -r "$pkgdir"/usr/libexec
}

# vim:set sw=2 sts=-1 et:
