# Maintainer: Laurent Carlier <lordheavym@gmail.com>
# Contributor: Lone_Wolf <lonewolf at xs4all dot nl>
# Contributor: Moritz Lipp <mlq@pwmt.org>

_pkgbasename=libunwind
pkgname=lib32-libunwind
pkgver=1.5.0
pkgrel=1
pkgdesc="Portable and efficient C programming interface (API) to determine the call-chain of a program (32-bit)"
arch=('x86_64')
url="https://www.nongnu.org/libunwind/"
license=('GPL')
makedepends=('gcc-multilib')
depends=('lib32-gcc-libs' 'libunwind' 'lib32-xz')
source=(https://download.savannah.gnu.org/releases/$_pkgbasename/$_pkgbasename-$pkgver.tar.gz{,.sig})
sha512sums=('1df20ca7a8cee2f2e61294fa9b677e88fec52e9d5a329f88d05c2671c69fa462f6c18808c97ca9ff664ef57292537a844f00b18d142b1938c9da701ca95a4bab'
            'SKIP')
validpgpkeys=('1675C8DA2EF907FB116EB709EC52B396E6874AF2')  # Dave Watson <davejwatson@fb.com> , project admin for unwind
validpgpkeys+=('75D2CFC56CC2E935A4143297015A268A17D55FA4') # Dave Watson

build() {
  export CC="gcc -m32"
  export CXX="g++ -m32"
  
  cd $_pkgbasename-$pkgver
  ./configure \
    --build=i686-pc-linux-gnu \
    --host=i686-pc-linux-gnu \
    --prefix=/usr \
    --libdir=/usr/lib32 \
    --disable-documentation 
  make

}

check() {
  cd "$srcdir/$_pkgbasename-$pkgver"
  # This function is ``supposed'' to fail. Upstream know, but haven't fixed it.
  make check || :
}

package_lib32-libunwind() {
  cd $_pkgbasename-$pkgver
  make DESTDIR="$pkgdir" install
  
  # this build only provides multilib binary for x86 on x86_64 , remove all includes for other architectures
  find $pkgdir/usr/include/*.h -not -name "*x86*" -exec rm -f {} \;
}
