# -*- 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.2
revision                0

checksums               rmd160  cd854d2095374e34e1225e6188b9b16409aabbc9 \
                        sha256  d7a0654783a4da529d1bb793b7ad9c3318020af77667bcae35f95d0e42a792f3 \
                        size    1320064

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   {9 3.1}
# Needs vsnprintf for full functionality
compiler.c_standard     1999
if {[string match *gcc-4.* ${configure.compiler}]} {
    configure.cflags-append -std=gnu99
}

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
}
