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

github.setup        bitkeeper-scm bitkeeper 0524ffb3f6f15ae8d3922b28da581f334475fe61
github.tarball_from archive
# commit contains build fixes
version             7.3.3
revision            2
categories          devel
license             Apache-2
maintainers         {l2dy @l2dy} openmaintainer
description         BitKeeper is a fast, enterprise-ready, distributed SCM \
                    that scales up to very large projects and down to tiny ones.
long_description    {*}${description}
homepage            https://www.bitkeeper.org/
#master_sites        https://www.bitkeeper.org/downloads/${version}/
#distname            bk-${version}
#extract.suffix      .src.tar.gz

checksums           rmd160  fd2a23123d5e2ef5a827a0a80ed13cd1b1596605 \
                    sha256  4b5db38c5364d55407f53d5b87f432da6a5b7d3b935e36ae44640151ca24b219 \
                    size    29081820

depends_build       port:groff \
                    path:bin/pkg-config:pkgconfig

depends_lib         port:libtomcrypt \
                    port:libtommath \
                    port:lz4 \
                    port:pcre \
                    port:zlib

patchfiles          patch-Makefile.diff \
                    patch-src-conf.mk.local.diff \
                    patch-src-gui-tcltk-Makefile.diff

post-patch {
    reinplace "s|@@PREFIX@@|${prefix}|g" ${worksrcpath}/src/conf.mk.local
}

use_configure       no

build.args-append   CC=${configure.cc} \
                    CXX=${configure.cxx} \
                    CPP=${configure.cpp} \
                    CFLAGS="${configure.cflags}" \
                    CXXFLAGS="${configure.cxxflags}" \
                    LDFLAGS="${configure.ldflags}"

destroot.args       BINDIR=${prefix}/libexec/${name}

post-destroot {
    # Fix permissions
    fs-traverse f ${destroot}${prefix}/libexec/${name} {
        file attributes ${f} -owner root -group wheel
        if {[file isdirectory ${f}]} {
            file attributes ${f} -permissions 0755
        }
    }

    ln -s ${prefix}/libexec/${name}/bk ${destroot}${prefix}/bin/bk
    foreach manpage [glob -tails -directory ${destroot}${prefix}/libexec/${name}/man/man1 bk.1 bk-*] {
        move ${destroot}${prefix}/libexec/${name}/man/man1/${manpage} ${destroot}${prefix}/share/man/man1/${manpage}
    }
    delete ${destroot}${prefix}/libexec/${name}/man
}

livecheck.type      regex
livecheck.url       https://www.bitkeeper.org/downloads/latest/
livecheck.regex     bk-(\\d+(?:\\.\\d+)*(?:ce)?)${extract.suffix}
