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

platform darwin {
    if {${os.major} <= 22} {
        set apple_version   498
    } else {
        set apple_version   501
    }
}

github.setup        apple-oss-distributions xar ${apple_version} xar-
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             1.8.0.${apple_version}
revision            0

categories          archivers sysutils
license             BSD
description         xar is the eXtensible ARchiver
long_description    {*}${description}
maintainers         {mps @Schamschula} openmaintainer

distname            ${name}-${apple_version}

worksrcdir          ${distname}/xar

platform darwin {
    if {${os.major} <= 22} {
        checksums   rmd160  0471deb9e01c91658feb4ea120772f7478f5c350 \
                    sha256  34f2e97c6786d2994af30fd72447ff1ac53f4052391a1030424da291f26c44f4 \
                    size    224456

        # see: https://trac.macports.org/ticket/64837
        patchfiles  patch-src-xar_internal.h.old.diff
    } else {
        checksums   rmd160  9a30fb4730de5bb8d70ff2692d7276d7f586ef50 \
                    sha256  6a9257017243c78d37e3788717259e53ffd33d93c740c12754e8527943fe892d \
                    size    224936

        # see: https://trac.macports.org/ticket/64837
        patchfiles  patch-src-xar_internal.h.diff
    }
}

depends_build       port:pkgconfig \
                    port:automake

depends_lib         path:lib/libssl.dylib:openssl \
                    port:bzip2 \
                    port:libxml2 \
                    port:zlib

# from Debian: restore *ssl support, etc
patchfiles-append   xar-1.8-Add-OpenSSL-To-Configuration.patch \
                    xar-1.8-openssl-1.1.patch \
                    xar-1.8-arm-ppc.patch \
                    xar-1.8-safe_dirname.patch

# don't use CommonCrypto, fix header path, etc
patchfiles-append   patch-tpoechtrager.diff \
                    patch-lib-archive.h.diff \
                    patch-lib-hash.c.diff \
                    patch-src-xar.c.diff

# add --to-stdout
patchfiles-append   patch-stdout.diff

# deal with 'os/availability.h' file not found
# see: https://trac.macports.org/ticket/64826
patchfiles-append   patch-include-xar.h.in.diff

# see: https://trac.macports.org/ticket/65128
patchfiles-append   patch-lib-filetree.c.diff

# see: https://trac.macports.org/ticket/65839
patchfiles-append   dont-overlink-to-libxml2.patch

# see: https://trac.macports.org/ticket/71270
configure.args-append \
                    ac_cv_header_ext2fs_ext2_fs_h=no

post-patch {
    set automake_dirs [glob -directory ${prefix}/share automake-*]
    set automake_dir [lindex [lsort -command vercmp $automake_dirs] end]
    copy -force ${automake_dir}/config.guess ${worksrcpath}
    copy -force ${automake_dir}/config.sub ${worksrcpath}
}

use_autoconf        yes
