PortSystem           1.0
PortGroup            cmake 1.1
PortGroup            github 1.0

github.setup         RJVB afsctool 1.7.3 v
revision             0
set lzfse_version    e634ca58b4821d9f3d560cdc6df5dec02ffc93fd

name                 afscompress
categories           sysutils
platforms            {darwin >= 10}
license              GPL-3
maintainers          {@ylluminarious orbitalimpact.com:georgedp} openmaintainer
description          A fork of brkirch's afsctool utility, featuring several improvements.
long_description     AFSC (Apple File System Compression) tool is a utility that can be used to \
    apply HFS+/APFS compression to file(s), decompress HFS+/APFS compressed file(s), \
    or get information about existing HFS+/APFS compressed file(s). macOS 10.6 or \
    later is required. This fork has several modifications, mostly concerning the \
    compression feature, including: improved error reporting, an attempt to reduce \
    memory pressure pressure compressing large files, support for multiple \
    files/folders specified on the commandline, a backup option while compressing \
    (that comes in addition to the existing undo if something went wrong), and \
    support for files that are read-only (and/or write-only) by changing their \
    permissions temporarily. No error checking is done for this feature\; failure \
    will lead to errors that are already caught. The main new feature that justifies \
    the version bump, however, is the parallel processing feature, allowing the user \
    to specify an arbitrary (though positive :)) number of threads that will \
    compress the specified files in parallel.

github.tarball_from  archive
master_sites-append  https://github.com/lzfse/lzfse/archive/:lzfse
distfiles-append     ${lzfse_version}.tar.gz:lzfse

checksums            afsctool-${version}.tar.gz \
                     sha256  5776ff5aaf05c513bead107536d9e98e6037019a0de8a1435cc9da89ea8d49b8 \
                     rmd160  73726e9e114443cfdc5daa373ded16b182d7d020 \
                     size    111816 \
                     ${lzfse_version}.tar.gz \
                     sha256  ca98aa6644d44500e3315858daa747ce15bd06d49e3edb12a5458e5525e8ebdb \
                     rmd160  2a571ba71473d3e46b3e82f2c212d2867a207c63 \
                     size    50694

depends_build-append port:pkgconfig

depends_lib-append   port:sparsehash \
                     port:zlib

post-extract {
    file delete -force ${worksrcpath}/src/private/lzfse
    ln -s ${workpath}/lzfse-${lzfse_version} ${worksrcpath}/src/private/lzfse
}

patchfiles           version.patch

compiler.cxx_standard  2011

configure.args-append \
    -DCMAKE_STRIP:PATH=/bin/echo

cmake.save_configure_cmd

post-destroot {
    if {[variant_isset original_name]} {
        xinstall -m 755 ${build.dir}/zfsctool ${destroot}${prefix}/bin/zfsctool
    } else {
        xinstall -m 755 ${build.dir}/zfscompress ${destroot}${prefix}/bin/zfscompress
    }
}

variant {original_name} description {Install the program as "afsctool" instead of "afscompress"} {}

if {[variant_isset original_name]} {
    configure.args-append \
        -DNEW_DRIVER_NAMES=OFF
} else {
    configure.args-append \
        -DNEW_DRIVER_NAMES=ON
}