# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

pkgname=squashfs-tools
pkgver=4.7
pkgrel=1
pkgdesc='Tools for squashfs, a highly compressed read-only filesystem for Linux'
arch=(i686 x86_64)
url='https://github.com/plougher/squashfs-tools'
license=(spdx:GPL-2.0-or-later)
depends=(
  gcc-libs
  liblz4
  liblzo2
  liblzma
  zlib
  libzstd
)
makedepends=(
  gcc
  make
  liblz4-devel
  liblzo2-devel
  liblzma-devel
  zlib-devel
  libzstd-devel
  help2man
)
source=("https://github.com/plougher/squashfs-tools/archive/$pkgver/$pkgname-$pkgver.tar.gz"
        "0001-fix-cygwin.patch")
sha256sums=('f1605ef720aa0b23939a49ef4491f6e734333ccc4bda4324d330da647e105328'
            '9947c28d2745be50e762c3472c54cdac972da9d37dfe9ec2eec1c70c9cb4eb0f')

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

  patch -p1 -i "$srcdir/0001-fix-cygwin.patch"
}

build() {
  local make_options=(
    GZIP_SUPPORT=1
    LZ4_SUPPORT=1
    LZMA_XZ_SUPPORT=1
    LZO_SUPPORT=1
    XATTR_SUPPORT=1
    XZ_SUPPORT=1
    ZSTD_SUPPORT=1
    -C $pkgname-$pkgver/$pkgname
  )

  make "${make_options[@]}"
}

package() {
  local make_options=(
    INSTALL_PREFIX="$pkgdir/usr"
    INSTALL_MANPAGES_DIR='$(INSTALL_PREFIX)/share/man/man1'
    install
    -C "$pkgname-$pkgver/$pkgname"
  )

  make "${make_options[@]}"
  install -vDm 644 "$pkgname-$pkgver/Documentation/${pkgver}"/* -t "$pkgdir/usr/share/doc/$pkgname/"
}
