# Maintainer:
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: Aaron Griffin <aaron@archlinux.org>

pkgname=fakechroot
pkgver=2.20.1
pkgrel=4.2
pkgdesc="Gives a fake chroot environment"
arch=('x86_64' 'aarch64')
url="https://github.com/dex4er/fakechroot/wiki"
license=('LGPL')
depends=('sh' 'perl')
# Patches from these PR's
# https://github.com/dex4er/fakechroot/pull/80
# https://github.com/dex4er/fakechroot/pull/100
# https://github.com/dex4er/fakechroot/pull/104
# https://github.com/dex4er/fakechroot/pull/93
source=($pkgname-$pkgver.tar.gz::https://github.com/dex4er/fakechroot/archive/${pkgver}.tar.gz
	statx.patch
	$pkgname-2.patch
	$pkgname-3.patch
	$pkgname-4.patch 
	$pkgname-5.patch)
md5sums=('69612efa06636e79a56898512222b0fc'
         '755d2beaa0c09b508020d49566c38964'
         '23c2444ee9dbe9934ce8a6ce49ae5b1a'
         'f1fa6a0561ed6771785be74cee99e93a'
         '4320f938ee3613a49c82b312021441cd'
         'ec930b912a9e48166591ac8e4668fdce')
sha512sums=('50f96d10de52eab32319746798396b972c021fb2e30679a2697214e01a974afbb4e0205dc51d5d9c7b57ac462d1a6fd14fd46ca9a92eefd20beef0d65ea76e0f'
            'd611d1e6ca7a95ba64ab7001e552d6f8e3fa0468e08fdb6af1b9bff979d8ddd9b9e0eab50a7c5198d5b273450787dd67bb51d714dcd79abc0bc92b947d6f018c'
            '7715c50ff332ee727afb834cd0f4b13f727d8152cff86ee0b8bebb286431b820f2a4e30a16655cf1e9f23c38cc31993a8563ca3aa08f10fa779894f282d20d51'
            '655f3c589d0c1958df0573b5d86e5541d0a31743d50e35347099679d41574f00ac5c6f13e74629073ebc1bbe138b6ac513abd47590d780adebe1d04c8c8c5194'
            '36e2dcb54f58054b59e1eb7d5928fcdf712583dd5db0c67ce3c756b8bb63bbb38529f264cb4d5cbd61cb894114d24ab0bebf312fa98263d4a958af46e607b048'
            '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
}
