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

name                    zlib
version                 1.3.1
revision                0

checksums               rmd160  7511a449069f0b02f5c691b9ae63d1e996f45700 \
                        sha256  38ef96b8dfe510d42707d9c781877914792541133e1870841463bfa73f883e32 \
                        size    1305740

categories              archivers
maintainers             {ryandesign @ryandesign} openmaintainer
license                 zlib
homepage                https://www.zlib.net/
platforms               darwin freebsd

description             zlib lossless data-compression library

long_description        zlib is designed to be a free, general-purpose, \
                        legally unencumbered, lossless data-compression \
                        library for use on virtually any computer hardware \
                        and operating system.

master_sites            ${homepage}
if {${os.platform} eq "darwin" && ${os.major} < 11 && ${configure.cxx_stdlib} eq "libc++"} {
    # This port is used by clang-3.4 to bootstrap libcxx, which is
    # indirectly used by the normal xz port.
    depends_extract     port:xz-bootstrap
    depends_skip_archcheck-append   xz-bootstrap
    extract.suffix      .tar.xz
    extract.cmd         ${prefix}/libexec/xz-bootstrap/bin/xz
    # Doesn't actually use C++, and having the stdlib set to libc++
    # on 10.6 causes a macports-clang compiler to be selected.
    configure.cxx_stdlib
} else {
    use_xz              yes
}

minimum_xcodeversions   {8 2.4.1 9 3.1}

configure.universal_args

use_parallel_build      yes

test.run                yes

destroot.destdir        prefix=${destroot}${prefix}

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

    post-destroot {
        platform darwin {
            foreach {neededfile} "${prefix}/lib/libz.dylib" {
                if {![file exists ${destroot}${neededfile}]} {
                    ui_error "${neededfile} is not in the destroot. Please clean ${name} and try again."
                    return -code error "missing ${neededfile} in destroot"
                }
            }
        }

        set docdir ${prefix}/share/doc/${name}
        xinstall -d ${destroot}${docdir}
        xinstall -m 0644 -W ${worksrcpath} ChangeLog FAQ README zlib.3.pdf ${destroot}${docdir}

        set examplesdir ${prefix}/share/examples/${name}
        xinstall -d ${destroot}${examplesdir}
        xinstall -m 0644 {*}[glob ${worksrcpath}/example{.c,s/*}] ${destroot}${examplesdir}
    }

    livecheck.type      regex
    livecheck.url       ${homepage}
    livecheck.regex     ${name}-(\[0-9.\]+)\\.tar
} else {
    livecheck.type      none
}

subport minizip {
    revision            0

    description         Minizip zip file manipulation library
    long_description    ${description}

    worksrcdir          ${worksrcdir}/contrib/minizip

    depends_lib-append  port:zlib

    use_autoreconf      yes
    autoreconf.args     -fvi

    configure.args      --enable-demos
}
