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

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  988cbdc2a5697cb0b10e062644e26575db4e8bdc \
                    sha256  c54c45155643fa66fed7f9ff2d134ea0a58d0ac197c18781ddc2fb236bf6ed29 \
                    size    3798511

python.default_version  312

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:lz4 \
                    port:libb2 \
                    port:xxhash \
                    port:zstd

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

post-build {
    reinplace "s|sphinx-build|sphinx-build-${python.branch}|g" \
        ${worksrcpath}/docs/Makefile
    reinplace "s|guzzle_sphinx_theme|sphinx_rtd_theme|g" \
        ${worksrcpath}/docs/conf.py
    reinplace "s|sphinx_rtd_theme.html_theme_path()|sphinx_rtd_theme.get_html_theme_path()|g" \
        ${worksrcpath}/docs/conf.py
    system "make -C ${worksrcpath}/docs man singlehtml"
}

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
    }
}