# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem           1.0
PortGroup            cmake 1.1
PortGroup            github 1.0
PortGroup            cxx11 1.1

github.setup         RJVB afsctool 1.7.0

name                 afscompress
categories           sysutils
platforms            darwin
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.

checksums            sha256  911ae33960560e36d854753cca1fcb83bb4674123b83f04b5642980670bc747d \
                     rmd160  b2ec4858164723532bee7d3b00f796d42aefbaea \
                     size    110026

depends_build-append port:pkgconfig

depends_lib-append   port:sparsehash \
                     port:zlib

universal_variant    yes

pre-fetch {
    if {${os.platform} eq "darwin" && ${os.major} < 10} {
        ui_error "${name} is only compatible with Mac OS X 10.6 or later; earlier versions lack support for HFS compression."
        return -code error "incompatible Mac OS X version"
    }
}


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
}