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

pkgname=squashfs-tools
pkgver=4.7.4
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)
msys2_references=(
  'anitya: 4879'
  'archlinux: squashfs-tools'
  'cpe: cpe:2.3:a:squashfs_project:squashfs'
  'gentoo: sys-fs/squashfs-tools'
)
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=('91c49f9a1ed972ad00688a38222119e2baf49ba74cf5fda05729a79d7d59d335'
            'a1c3c7851fcafe74af594a637af918f5b9e776a330d8f1018c2b94c29c28f7dc')

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/"
}
