#!/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 |---------------------------------------

pkgbase=elfutils
pkgname=(debuginfod elfutils libelf)
pkgver=0.187
pkgrel=02
pkgdesc="Handle ELF object files and DWARF debugging information"
arch=(x86_64)
url="https://sourceware.org/elfutils/"
makedepends=(bzip2 curl gcc-libs libarchive libmicrohttpd sqlite xz zlib zstd)
#options=(debug staticlibs)
options=(staticlibs)
source=(https://sourceware.org/$pkgbase/ftp/$pkgver/$pkgbase-$pkgver.tar.bz2{,.sig})

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

prepare() {
  (
  cd $pkgbase-$pkgver
  autoreconf -fiv
  )

  cp -av $pkgbase-$pkgver $pkgbase-test-$pkgver

}

build() {
  (
  # fat-lto-objects is required for non-mangled .a files in libelf
  CFLAGS+=" -ffat-lto-objects"
  cd $pkgbase-$pkgver
  ./configure --prefix=/usr \
              --sysconfdir=/etc \
              --program-prefix="eu-" \
              --enable-deterministic-archives
  make
  )
  (
  cd $pkgbase-test-$pkgver
  # debugging information is required for test-suite
  CFLAGS+=" -g"
  # fat-lto-objects is required for non-mangled .a files in libelf
  CFLAGS+=" -ffat-lto-objects"
  ./configure --prefix=/usr \
              --sysconfdir=/etc \
              --program-prefix="eu-" \
              --enable-deterministic-archives
  make
  )
}

# a few tests fail on this 0187 build, they didn't on last 0186 but do try them on your
# machine and environment and report if your build didn't fail, otherwise we will try again on next build
#
#check() {
#  make check -C $pkgbase-test-$pkgver
#}

package_debuginfod() {
  pkgdesc+=" (debuginfod)"
  depends=(gcc-libs glibc libarchive.so libelf=$pkgver libmicrohttpd.so sqlite)
  optdepends=("elfutils=$pkgver: for translations")

  make DESTDIR="$pkgdir" install -C $pkgbase-$pkgver
  install -vDm 644 $pkgbase-$pkgver/{AUTHORS,ChangeLog,NEWS,NOTES,README} -t "$pkgdir/usr/share/doc/$pkgname/"

  # set the default DEBUGINFOD_URLS environment variable to the distribution's debuginfod URL
  printf "https://debuginfod.archlinux.org\n" > "$pkgdir/etc/debuginfod/archlinux.urls"

  (
    cd "$pkgdir"

    _pick libelf usr/{include,lib}
    _pick elfutils usr/bin/eu-*
    _pick elfutils usr/share/locale
    _pick elfutils usr/share/man/man1/eu-*
    _pick elfutils usr/share/man/man3/elf_*
  )

}

package_elfutils() {
  pkgdesc+=" (utilities)"
  depends=(gcc-libs glibc libelf=$pkgver)

  mv -v elfutils/* "$pkgdir"
  install -vDm 644 $pkgbase-$pkgver/{AUTHORS,ChangeLog,NEWS,NOTES,README} -t "$pkgdir/usr/share/doc/$pkgname/"
}

package_libelf() {
  pkgdesc+=" (libraries)"
  depends=(gcc-libs libbz2.so libcurl.so xz zlib zstd)
  # NOTE: the shared objects can not be added to provides as they are not versioned

  mv -v libelf/* "$pkgdir"
  install -vDm 644 $pkgbase-$pkgver/{AUTHORS,ChangeLog,NEWS,NOTES,README} -t "$pkgdir/usr/share/doc/$pkgname/"
}

#---- license gpg-key sha256sums ----

license=(LGPL3 GPL3)

validpgpkeys=(47CC0331081B8BC6D0FD4DA08370665B57816A6A  # Mark J. Wielaard <mark@klomp.org>
	EC3CFE88F6CA0788774F5C1D1AA44BE649DE760A)  # Mark Wielaard <mjw@gnu.org>

sha256sums=(e70b0dfbe610f90c4d1fe0d71af142a4e25c3c4ef9ebab8d2d72b65159d454c8 # elfutils-0.187.tar.bz2
	93a9568f7fd4c3b29a94709abcaad2213d5bcf7e89bdd40350f222141f2d41f0) # elfutils-0.187.tar.bz2.sig

