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

name                    bzip2
version                 1.0.8
revision                0
checksums               rmd160  a593488c5c0240bcfceb292c9fa95fb7ad42cb27 \
                        sha256  ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269 \
                        size    810029

platforms               darwin freebsd linux sunos
categories              archivers sysutils
maintainers             {ryandesign @ryandesign} openmaintainer
license                 BSD

description             compression library and tools

long_description        ${name} is a freely available, patent free, \
                        high-quality data compressor.

# Development of bzip2 1.1.x is at https://gitlab.com/federicomenaquintero/bzip2
homepage                https://sourceware.org/bzip2/
master_sites            https://sourceware.org/pub/bzip2/

patchfiles              patch-Makefile-man.diff \
                        patch-Makefile-links.diff \
                        patch-Makefile-so.diff

use_configure           no

use_parallel_build      yes

variant universal {}

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    # Having the stdlib set to libc++ on 10.6 causes a dependency on a
    # macports-clang compiler to be added, which would be a dep cycle.
    configure.cxx_stdlib
}

build.args              CC="${configure.cc} [get_canonical_archflags cc]" \
                        PREFIX=${prefix}

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

platform darwin {
    patchfiles-replace  patch-Makefile-so.diff patch-Makefile-dylib.diff

    post-patch {
        reinplace "s|__MacPorts_Version__|${version}|g" ${worksrcpath}/Makefile
        reinplace "s|__MacPorts_Compatibility_Version__|[join [lrange [split ${version} .] 0 1] .]|g" ${worksrcpath}/Makefile
    }

    post-destroot {
        ln -s libbz2.${version}.dylib ${destroot}${prefix}/lib/libbz2.[join [lrange [split ${version} .] 0 1] .].dylib
        ln -s libbz2.${version}.dylib ${destroot}${prefix}/lib/libbz2.[join [lrange [split ${version} .] 0 0] .].dylib
        ln -s libbz2.${version}.dylib ${destroot}${prefix}/lib/libbz2.dylib
    }
}

livecheck.type          regex
livecheck.url           [lindex ${master_sites} 0]
livecheck.regex         ${name}-(\\d+(?:\.\\d+)+)
