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

pkgname=pacman
pkgver=6.0.2
pkgrel=015
pkgdesc="A library-based package manager with dependency support modified for joborun from arch"
url="https://www.archlinux.org/pacman/"
groups=(base jobbot)
depends=('bash' 'glibc' 'libarchive' 'curl' 'gpgme' 'pacman-mirrorlist' 'jobo-mirror'
	'gawk' 'coreutils' 'gnupg' 'grep' 'archlinux-keyring'
	'obarun-keyring' 'joborun-keyring' 'lzip')

# NOTE: Joborun linux is switching default pkg compression to lzip at level -5
# which matches current xz compression ratio but at a fraction of RAM use
# and relatively even speed.  So lzip becomes a standard system dependency
# as it will also be used by pacman during installation.  Gradually all
# pkgs will be offered as *.pkg.tar.lz For a while there will be mixed.
makedepends=('meson' 'asciidoc' 'doxygen')
checkdepends=('python' 'fakechroot')
optdepends=('perl-locale-gettext: translation support in makepkg-template')
provides=('libalpm.so')
backup=(etc/pacman.conf
	etc/makepkg.conf)
#options=('strip' 'debug')
options=(strip)
source=(https://sources.archlinux.org/other/pacman/$pkgname-$pkgver.tar.xz{,.sig}
	pacman-always-create-directories-from-debugedit.patch::https://gitlab.archlinux.org/pacman/pacman/-/commit/efd0c24c07b86be014a4edb5a8ece021b87e3900.patch
	pacman-always-create-directories-from-debugedit-fixup.patch::https://gitlab.archlinux.org/pacman/pacman/-/commit/86981383a2f4380bda26311831be94cdc743649b.patch
	pacman-fix-unique-source-paths.patch::https://gitlab.archlinux.org/pacman/pacman/-/commit/478af273dfe24ded197ec54ae977ddc3719d74a0.patch
	pacman-strip-include-o-files-similar-to-kernel-modules.patch::https://gitlab.archlinux.org/pacman/pacman/-/commit/de11824527ec4e2561e161ac40a5714ec943543c.patch
	pacman-fix-compatibility-with-bash-5.2-patsub_replacement.patch::https://gitlab.archlinux.org/pacman/pacman/-/commit/0e938f188692c710be36f9dd9ea7b94381aed1b4.patch
	pacman-fix-order-of-fakechroot-fakeroot-nesting.patch::https://gitlab.archlinux.org/pacman/pacman/-/commit/05f283b5ad8f5b8f995076e93a27c8772076f872.patch
	pacman.conf
	makepkg.conf)

prepare() {
  cd "${pkgname}-${pkgver}"
  # we backport way too often in pacman
  # lets at least make it more convenient
  local src
  for src in "${source[@]}"; do
	src="${src%%::*}"
	src="${src##*/}"
	[[ $src = *.patch ]] || continue
	msg2 "Applying patch $src..."
	patch -Np1 < "../$src"
  done
}

build() {
  cd "$pkgname-$pkgver"

  meson --prefix=/usr \
	--buildtype=plain \
	-Ddoc=disabled \
	-Ddoxygen=enabled \
	-Dscriptlet-shell=/usr/bin/bash \
	-Dldconfig=/usr/bin/ldconfig \
	build

  meson compile -C build
}

check() {
  cd "$pkgname-$pkgver"

  meson test -C build
}

package() {
  cd "$pkgname-$pkgver"

  DESTDIR="$pkgdir" meson install -C build

  # install Arch specific stuff
  install -dm755 "$pkgdir/etc"
  install -m644 "$srcdir/pacman.conf" "$pkgdir/etc"
  install -m644 "$srcdir/makepkg.conf" "$pkgdir/etc"
#  rm -rf $pkgdir/usr/share/libalpm/hooks
}

#---- arch license gpg-key & sha256sums ----

arch=(x86_64)

license=('GPL')

validpgpkeys=('6645B0A8C7005E78DB1D7864F99FFE0FEAE999BD'  # Allan McRae <allan@archlinux.org>
	'B8151B117037781095514CA7BBDFFC92306B1121') # Andrew Gregory (pacman) <andrew@archlinux.org>

sha256sums=(7d8e3e8c5121aec0965df71f59bedf46052c6cf14f96365c4411ec3de0a4c1a5  # pacman-6.0.2.tar.xz
	e3b75fafa8f177752800b31b9d59c454694647ae39b02a8009384a6821ee3be3  # pacman-6.0.2.tar.xz.sig
	6fed94326b9ecfbb438ab17a4576b5e9d52ecc0f4574f29d46adfde3886dee03  # pacman-always-create-directories-from-debugedit.patch
	d2bc104788290e3de829a232590b66ad745cf5b4762a01acc1191ebf70fef114  # pacman-always-create-directories-from-debugedit-fixup.patch
	f3d4f39ef24e312f610cbb3439fb02bc6b8829e37bcf1a50ae50cd0a69bde5d0  # pacman-fix-unique-source-paths.patch
	d87d0c9957c613fda272553bee58140349d151ae399f346ddaf6d75ee5916312  # pacman-strip-include-o-files-similar-to-kernel-modules.patch
	8641d514ef4cae9e4d1867aadf4b9c850a9e8dc9792c6c559f9d2a0e1713a5a1  # pacman-fix-compatibility-with-bash-5.2-patsub_replacement.patch
	b11f62d4bd9557e9d3e7456bc95f63e9eabab5ecee1368f4a14a84bc94b1c8d1  # pacman-fix-order-of-fakechroot-fakeroot-nesting.patch
	6436e418557989586221d4d5c527666f18d98c6332126dbb6276581b9dce4f6d  # pacman.conf
	b7b3302848e12438b4767eafcc76e121b0f24717c37572e252ffcf4f36a5c4d9) # makepkg.conf

##  3e50b6c757dae445d65793aa2fb47f34102737613d5e67a7e12ba90f6e903b1f  pacman-6.0.2-015-x86_64.pkg.tar.lz

