# Maintainer: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Maintainer: Dan McGee <dan@archlinux.org>

pkgname=libarchive
pkgver=3.6.1
pkgrel=5
pkgdesc='Multi-format archive and compression library'
arch=('x86_64')
url='https://libarchive.org/'
license=('BSD')
depends=('acl' 'libacl.so' 'bzip2' 'expat' 'lz4' 'openssl' 'libcrypto.so' 'xz'
         'zlib' 'zstd')
provides=('libarchive.so')
options=('debug')
validpgpkeys=('A5A45B12AD92D964B89EEE2DEC560C81CEC2276E') # Martin Matuska <mm@FreeBSD.org>
source=("https://github.com/${pkgname}/${pkgname}/releases/download/v${pkgver}/${pkgname}-${pkgver}.tar.xz"{,.asc}
        '0001-libarchive-Handle-a-calloc-returning-NULL-fixes-1754.patch'
        '0002-Validate-entry_bytes_remaining-in-pax_attribute.patch'
        '0003-libarchive-Do-not-include-sys-mount.h-when-linux-fs..patch')
sha256sums=('5a411aceb978f43e626f0c2d1812ddd8807b645ed892453acabd532376c148e6'
            'SKIP'
            'bc52b2b2b99915894b436c97872d5d50e94c8c7483865a028fad9a710c837fa7'
            '38c8d9b00f3259558e67e6fdf790ccbf8ecbba2de101476c2416d87b1679bcb9'
            '99c85a9b8e6c16131cefaf1040d5fa15cd565ecf8c71c1f644c8fa47fe1306dc')

prepare() {
  cd "${pkgname}-${pkgver}"

  patch -Np1 < ../0001-libarchive-Handle-a-calloc-returning-NULL-fixes-1754.patch
  patch -Np1 < ../0002-Validate-entry_bytes_remaining-in-pax_attribute.patch
  patch -Np1 < ../0003-libarchive-Do-not-include-sys-mount.h-when-linux-fs..patch
}

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

  ./configure \
      --prefix=/usr \
      --without-xml2 \
      --without-nettle \
      --disable-static
  make
}

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

  make check
}

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

  make DESTDIR="$pkgdir" install
  install -Dm0644 COPYING "$pkgdir/usr/share/licenses/libarchive/COPYING"
}
