# -*- 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                   github 1.0

name                        zstd

subport ${name} {
    PortGroup               clang_dependency 1.0
    PortGroup               makefile 1.0
    PortGroup               muniversal 1.1

}

subport zstdConfig.cmake {
    PortGroup               cmake 1.1

}

github.setup                facebook zstd 1.5.7 v
github.tarball_from         archive
revision                    0

checksums                   rmd160  f2c3cae0c30dba96f59f5f19523c1d85961b27f6 \
                            sha256  37d7284556b20954e56e1ca85b80226768902e2edabd3b649e9e72c0c9012ee3 \
                            size    2451884

categories                  archivers devel
license                     {BSD GPL-2}

maintainers                 {mcalhoun @MarcusCalhoun-Lopez} openmaintainer

subport ${name} {
    description             Zstandard - Fast real-time compression algorithm
    long_description        Zstd, short for Zstandard, is a fast lossless compression \
                            algorithm, targeting real-time compression scenarios at \
                            zlib-level and better compression ratios.
}

subport zstdConfig.cmake {
    description             CMake files for zstd
    long_description        Installs {*}${description}.
}

patchfiles                  patch-zstd-tiger-no-backtrace.diff \
                            flags.patch

# Fix upgrade from previous version because -I flags are in the wrong order.
configure.cppflags-replace  -I${prefix}/include -isystem${prefix}/include

subport ${name} {
    depends_lib-append      port:lz4 \
                            port:xz \
                            port:zlib

    # libzstd.dylib links to libSystem.B.dylib only. Dependencies like lz4 are
    # linked by CLI tools in ${prefix}/bin only.
    license_noconflict      lz4 xz zlib

    platform darwin 8 {
        depends_build-append port:gmake
        build.cmd           ${prefix}/bin/gmake
    }

    build.target            allmost
    build.args              V=1

    test.run                yes
    test.args               {*}${build.args}

    # Exclude pre-release candidates
    github.livecheck.regex  {([0-9.]+)}
}

subport zstdConfig.cmake {
    depends_lib-append      port:${name}

    cmake.source_dir        ${worksrcpath}/build/cmake

    supported_archs         noarch
    platforms               any
    installs_libs           no

    post-destroot {
        delete              ${destroot}${prefix}/bin \
                            ${destroot}${prefix}/share \
                            ${destroot}${prefix}/include \
                            ${destroot}${prefix}/lib/pkgconfig \
                            {*}[glob ${destroot}${prefix}/lib/lib*]
    }
}
