# Maintainer: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>

pkgname=flatpak-builder
pkgver=1.0.8
pkgrel=1
pkgdesc="Tool to build flatpaks from source"
url="https://flatpak.org"
arch=(x86_64)
license=(LGPL2.1)
depends=(flatpak binutils elfutils unzip tar git bzr patch rpmextract cpio appstream-glib)
makedepends=(intltool gobject-introspection git docbook-xsl xmlto libdwarf)
checkdepends=(python2 valgrind)
replaces=('flatpak<0.9.10')
_commit=199b31e0649e37f22c06d2c47644cf44d0aeb1a9  # tags/1.0.8^0
source=("git+https://github.com/flatpak/flatpak-builder#commit=$_commit"
        "git+https://gitlab.gnome.org/GNOME/libglnx.git")
sha256sums=('SKIP'
            'SKIP')

prepare() {
  cd $pkgname

  git submodule init
  git config --local submodule.libglnx.url "$srcdir/libglnx"
  git submodule update

  # https://github.com/flatpak/flatpak/issues/267
  sed -i '/locale\/C\./d' tests/make-test-runtime.sh

  NOCONFIGURE=1 ./autogen.sh
}

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/-/+/g'
}

build() {
  cd $pkgname

  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --sbindir=/usr/bin \
    --libexecdir=/usr/lib \
    --disable-static \
    --with-dwarf-header=/usr/include/libdwarf

  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool

  make
}

check() {
  cd $pkgname
  # Xattr tests fail on tmpfs
  make -k check || :
}

package() {
  cd $pkgname
  make DESTDIR="$pkgdir" install
}
