# -*- 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 994fb651a4045b221e33703fc3d665c3a34784e1
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
# commit contains build fixes
version             7.3.3
revision            1
categories          devel
supported_archs     x86_64
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  95409bbe4a4ea4f358cc717459094eb9dec7a95c \
                    sha256  c9fc0fe380f3816aa1f063213eb7bc27f18285e3367c2144b091ed89a1f6daf0 \
                    size    29060773

depends_build       port:groff \
                    port: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}
