#!/bin/sh

#shellcheck disable=SC2034
#shellcheck disable=SC2154
#shellcheck disable=SC2086

#ebs.formulae
ebsver=1

pkgname=libarchive
pkgver=3.8.9
pkgsrc=https://github.com/libarchive/libarchive/releases/download/v$pkgver/libarchive-$pkgver.tar.xz
pkgchecksum=sha256:888c934f9d95648ecb9163dc8e23ab80a476ecb81a8f1154704a227b5b676dde
pkgdesc="multi-format archive and compression library"
pkgmaintainer="juanvel400 <me@juanvel400.com>"
pkglicense="BSD-2-Clause"
pkghomepage="https://libarchive.org"
pkgdeps="musl,zstd,bzip2,xz,zlib,openssl"
pkgprovides="bsdtar,bsdcpio,bsdunzip,cpio,unzip,tar"
pkgcheck=true

build() {
    ./configure ${CONFIGUREFLAGS:-} \
        --prefix=/usr \
        --enable-year2038 \
        --disable-static \
        --enable-shared \
        --without-iconv \
        --without-xml2 \
        --with-zlib \
        --with-bz2lib \
        --with-lzma \
        --with-zstd \
        --with-openssl \
        --without-lz4 \
        --without-expat \
        --without-libb2 \
        --without-nettle \
        --disable-acl \
        --disable-xattr

    make
}

check() {
    make check
}

package() {
    "${1:-fakeroot}" make install DESTDIR="$pkgdir"

    ln -sf bsdunzip "$pkgdir/usr/bin/unzip"
    ln -sf bsdunzip.1 "$pkgdir/usr/share/man/man1/unzip.1"

    ln -sf bsdcpio "$pkgdir/usr/bin/cpio"
    ln -sf bsdcpio.1 "$pkgdir/usr/share/man/man1/cpio.1"

    ln -sf bsdtar "$pkgdir/usr/bin/tar"
    ln -sf bsdtar.1 "$pkgdir/usr/share/man/man1/tar.1"
}
