# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer:
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: Aaron Griffin <aaron@archlinux.org>

pkgname=fakechroot
pkgver=2.20.1
pkgrel=4
pkgdesc="Gives a fake chroot environment"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://github.com/dex4er/fakechroot/wiki"
license=('LGPL')
depends=('sh' 'perl')
source=($pkgname-$pkgver.tar.gz::https://github.com/dex4er/fakechroot/archive/${pkgver}.tar.gz
	statx.patch
	$pkgname-2.patch::https://github.com/dex4er/fakechroot/pull/80.patch
	$pkgname-3.patch::https://github.com/dex4er/fakechroot/pull/100.patch
	$pkgname-4.patch::https://github.com/dex4er/fakechroot/pull/104.patch
	$pkgname-5.patch::https://github.com/dex4er/fakechroot/pull/93.patch)
md5sums=('69612efa06636e79a56898512222b0fc'
         '755d2beaa0c09b508020d49566c38964'
         '23c2444ee9dbe9934ce8a6ce49ae5b1a'
         'f1fa6a0561ed6771785be74cee99e93a'
         '5348ae303bfb6a9ee7f64ecef6c29797'
         'ec930b912a9e48166591ac8e4668fdce')
sha512sums=('50f96d10de52eab32319746798396b972c021fb2e30679a2697214e01a974afbb4e0205dc51d5d9c7b57ac462d1a6fd14fd46ca9a92eefd20beef0d65ea76e0f'
            'd611d1e6ca7a95ba64ab7001e552d6f8e3fa0468e08fdb6af1b9bff979d8ddd9b9e0eab50a7c5198d5b273450787dd67bb51d714dcd79abc0bc92b947d6f018c'
            '7715c50ff332ee727afb834cd0f4b13f727d8152cff86ee0b8bebb286431b820f2a4e30a16655cf1e9f23c38cc31993a8563ca3aa08f10fa779894f282d20d51'
            '655f3c589d0c1958df0573b5d86e5541d0a31743d50e35347099679d41574f00ac5c6f13e74629073ebc1bbe138b6ac513abd47590d780adebe1d04c8c8c5194'
            '6545570c70c42e4753561687ea9eafb301aa6c7ad1f669212629232bd70275a90cc19129d0824a729884b1055e5155920bbd5b521b54fd450031bb25258d2970'
            '6a176a6a123efe5ff554b22dc0492a819f71581bdc38bc14a45ff61f163b8f2c6536bd1d559e2554bb08d4b7a59b87889bc99315995bfc8e2da1b28cf92c8def')

prepare() {
  cd $pkgname-$pkgver
  # Apply patches similiar to Fedora https://src.fedoraproject.org/rpms/fakechroot/blob/rawhide/f/fakechroot.spec#_8
  patch -Np1 -i "${srcdir}/statx.patch"
  for i in {2..5}; do
    patch -Np1 -i "${srcdir}/${pkgname}-${i}.patch"
  done

  autoreconf -vfi
}

build() {
  cd $pkgname-$pkgver
  ./configure --prefix=/usr --sbindir=/usr/bin \
    --libdir=/usr/lib/libfakeroot --sysconfdir=/etc
  make
}

check() {
  cd $pkgname-$pkgver

  # t/fts.t fails when building on BTRFS...  (really!)
  make -k check
}
  
package() {
  cd $pkgname-$pkgver
  make DESTDIR="${pkgdir}" install
  
  install -dm755 "${pkgdir}"/etc/ld.so.conf.d/
  echo '/usr/lib/libfakeroot/fakechroot/' > "${pkgdir}"/etc/ld.so.conf.d/fakechroot.conf
}
