# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           python 1.0

name                borgbackup
version             1.4.2
revision            1

categories          sysutils
license             BSD
maintainers         {judaew @judaew} openmaintainer

description         Deduplicating backup program
long_description    BorgBackup (short: Borg) is a deduplicating backup \
                    program. Optionally, it supports compression and \
                    authenticated encryption. Main goal of Borg is to provide \
                    an efficient and secure way to backup data. The data \
                    deduplication technique used makes Borg suitable for \
                    daily backups since only changes are stored. The \
                    authenticated encryption technique makes it suitable for \
                    backups to not fully trusted targets.

homepage            https://www.borgbackup.org/

checksums           rmd160  ffc182e1818133216640edfd5e6a374adf6424d2 \
                    sha256  8923f5e953205d81138d1d7276c8a1c864215e230994d620c397635568ed376f \
                    size    3932875

patchfiles          patch-accept-newer-msgpack.diff \
                    patch-docs-use-sphinx_rtd_theme.diff

python.default_version  313

depends_build-append \
                    port:py${python.version}-cython \
                    port:py${python.version}-pkgconfig \
                    port:py${python.version}-setuptools_scm \
                    port:py${python.version}-sphinx \
                    port:py${python.version}-sphinx_rtd_theme

depends_lib-append  path:lib/libssl.dylib:openssl \
                    port:libb2 \
                    port:lz4 \
                    port:py${python.version}-brotlicffi \
                    port:xxhash \
                    port:zstd

depends_run-append  port:py${python.version}-msgpack \
                    port:py${python.version}-packaging

# Run tests, but skip test_unix_socket, since it will fail because the path is
# longer than the maximum length of a unix socket name when run in a MacPorts
# build.
depends_test-append port:py${python.version}-pytest-xdist \
                    port:py${python.version}-pytest-benchmark

test.run            yes
test.args-append    -k 'not test_unix_socket' \
                    -n ${build.jobs} \
                    --pyargs borg.testsuite

post-build {
    system "make -C [shellescape ${worksrcpath}/docs] man singlehtml SPHINXBUILD=[shellescape sphinx-build-${python.branch}]"
}

post-destroot {
    set docdir ${destroot}${prefix}/share/doc/${name}/html
    xinstall -d ${docdir}

    xinstall -m 0644 ${worksrcpath}/docs/_build/man/borg.1 \
        ${destroot}${prefix}/share/man/man1/
    file copy {*}[glob ${workpath}/${distname}/docs/_build/singlehtml/*] ${docdir}

    # bash completion
    set bash_compl_path ${prefix}/share/bash-completion/completions
    xinstall -d ${destroot}${bash_compl_path}
    xinstall -m 0644 ${worksrcpath}/scripts/shell_completions/bash/borg \
        ${destroot}${bash_compl_path}

    # zsh completion
    set zsh_compl_path ${prefix}/share/zsh/site-functions
    xinstall -d ${destroot}${zsh_compl_path}
    xinstall -m 0644 ${worksrcpath}/scripts/shell_completions/zsh/_borg \
        ${destroot}${zsh_compl_path}

    # fish completion
    set fish_compl_path ${prefix}/share/fish/vendor_completions.d
    xinstall -d ${destroot}${fish_compl_path}
    xinstall -m 0644 ${worksrcpath}/scripts/shell_completions/fish/borg.fish \
        ${destroot}${fish_compl_path}
}

variant fuse description {Add FUSE mounting support} {
    depends_lib-append  port:py${python.version}-llfuse
}

platform darwin {
    if {${os.major} < 19} {
        default_variants +fuse
    }
}
