# -*- 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               cmake 1.1
PortGroup               github 1.0

github.setup            jmacd xdelta 3.2.2 v

categories              archivers
license                 Apache-2
homepage                https://jmacd.github.io/xdelta
maintainers             {sethm.id.au:dev @McDaMastR} \
                        openmaintainer

description             VCDIFF (RFC 3284) delta compression library and tool
long_description        Xdelta is a command-line tool and C library for \
                        differential compression: it computes and applies \
                        binary deltas between files using the VCDIFF/RFC 3284 \
                        format.  It is well suited to distributing updates, \
                        since a delta between two similar files is typically \
                        far smaller than the files themselves.

distname                ${name}3-${version}

checksums               rmd160  44ce8888f27ee7fb2a953615fbf007b9253ed025 \
                        sha256  d839ae8c1f1bf5d0abfd66f152ec089a65a20d56c1f6d8d36cb7716a6c766d0e \
                        size    225880

patchfiles              use-installed-blake3.diff

compiler.c_standard     1999
compiler.cxx_standard   2011

configure.args-append   -DBUILD_SHARED_LIBS=ON \
                        -DXD3_ARMOR=OFF \
                        -DXD3_BUILD_LIB=ON \
                        -DXD3_BUILD_TESTS=ON \
                        -DXD3_LARGESIZET=ON \
                        -DXD3_LIB_LZMA=OFF \
                        -DXD3_LZMA_FETCH=OFF \
                        -DXD3_LZMA_MODE=off \
                        -DXD3_SECONDARY_FGK=OFF

pre-test {
    # Library not loaded: @rpath/libxdelta3.3.dylib
    system "install_name_tool -add_rpath ${cmake.build_dir} ${cmake.build_dir}/${name}3_lib_smoke"
}

test.run                yes
test.cmd                ctest
test.target

post-destroot {
    set destdocdir  ${destroot}${prefix}/share/doc/${name}

    xinstall -d ${destdocdir}
    xinstall -W ${worksrcpath} -m 644 \
        LICENSE \
        NEWS \
        README.md \
        draft-korn-vcdiff.txt \
        ${destdocdir}
}

default_variants        +armor +lzma

variant armor \
        description {Support armor mode} {
    depends_lib-append      port:libblake3
    configure.args-replace  -DXD3_ARMOR=OFF -DXD3_ARMOR=ON
}

variant lzma \
        description {Support LZMA secondary compression} {
    depends_lib-append      port:xz
    configure.args-replace  -DXD3_LIB_LZMA=OFF -DXD3_LIB_LZMA=ON
    configure.args-replace  -DXD3_LZMA_MODE=off -DXD3_LZMA_MODE=on
}
