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

epoch           1
# 5.6.0 and 5.6.1 contained Linux-specific malware. 5.6.2 and later are OK.
# https://tukaani.org/xz-backdoor/
github.setup    tukaani-project xz 5.8.1 v
checksums       rmd160  71c4a3675fdde3302c5b7ddc9607549c6d204249 \
                sha256  5965c692c4c8800cd4b33ce6d0f6ac9ac9d6ab227b17c512b6561bce4f08d47e \
                size    1902964

categories      archivers
# some executables are GPL, libs and everything else are public domain
license         {public-domain GPL-2+}
maintainers     {ryandesign @ryandesign} openmaintainer

description     XZ Utils

long_description \
XZ utils consist of a few relatively separate submodules: \
\n* LZMA/XZ encoder/decoder command line tool similar to gzip/bzip2 \
\n* Scripts to ease grepping, diffing and viewing (lz*grep, lzdiff/lzcmp, lzmore/lzless)

homepage        https://tukaani.org/xz/
github.tarball_from \
                releases
master_sites-append \
                sourceforge:project/lzmautils

use_bzip2       yes

if {${subport} eq ${name}} {
    revision    0

    depends_build-append \
                port:gettext
    depends_lib-append \
                port:libiconv \
                port:gettext-runtime

    # document that we always need legacy symlinks now that "lzmautils" refers here
    configure.args-append --enable-lzma-links

    livecheck.url   https://api.github.com/repos/${github.author}/${github.project}/releases/latest
    livecheck.regex "\"tag_name\":\\s*\"${github.tag_prefix}(\[^\"\]+)\""
} else {
    livecheck.type  none
}

# This port is used by clang-3.4 to bootstrap libcxx
subport ${name}-bootstrap {
    revision                0

    # Avoid macports-clang dep (doesn't use C++ anyway)
    configure.cxx_stdlib
    compiler.whitelist      clang llvm-gcc-4.2 gcc-4.2 apple-gcc-4.2

    # sterilize MacPorts build environment; we want nothing picked up from MP prefix
    compiler.cpath
    compiler.library_path

    configure.ccache        no
    configure.distcc        no

    # sterilize PATH
    configure.env-append    PATH=/usr/bin:/bin:/usr/sbin:/sbin
    build.env-append        PATH=/usr/bin:/bin:/usr/sbin:/sbin

    prefix                  ${prefix}/libexec/xz-bootstrap
    configure.args          --disable-doc \
                            --disable-lzma-links \
                            --disable-lzmadec \
                            --disable-lzmainfo \
                            --disable-nls \
                            --disable-scripts \
                            --disable-static \
                            --disable-xzdec \
                            --without-libiconv-prefix \
                            --without-libintl-prefix

    # Don't install manpages
    destroot.args           dist_man_MANS=

}
if {${os.platform} eq "darwin" && ${os.major} < 11 && ${cxx_stdlib} eq "libc++"} {
    # This port is in the dependency chain for clang 3.7 and later
    clang_dependency.extra_versions 3.7
}

# the internal "check.h" header conflicts with port check's <check.h>
configure.cppflags -I${worksrcpath}/src/liblzma/check -I${prefix}/include

configure.checks.implicit_function_declaration.whitelist-append strchr
