# -*- 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           meson 1.0
PortGroup           muniversal 1.0
PortGroup           compiler_blacklist_versions 1.0
PortGroup           legacysupport 1.1

# posix_memalign
legacysupport.newest_darwin_requires_legacy 9

name                dav1d
# Please increase the revision of libheif, ffmpeg and ffmpeg-devel whenever
# dav1d's version is updated.
version             1.5.1
revision            0

checksums           rmd160  994a0255e3349d67fbb9ad26969764736218c559 \
                    sha256  26fc5f693be85c8311ef67ce0e479be37bff5142db313b38c7e2b5ef3891f1f0 \
                    size    1215218

categories          multimedia
license             BSD
maintainers         {ctreleaven @ctreleaven} openmaintainer

description         small and fast AV1 decoder
long_description    dav1d is an AV1 decoder that is open-source, cross-platform and \
                    focused on speed, size and correctness.

homepage            https://www.videolan.org/projects/dav1d.html
master_sites        https://code.videolan.org/videolan/dav1d/-/archive/${version}/
distname            ${name}_${version}
# extracted directory contains a hash
if {[exists extract.rename]} {
extract.rename      yes
}

use_bzip2           yes

# see https://trac.macports.org/ticket/62618
# patch can be applied always, but limit to < darwin 10 so no chance of troubles
if {${os.platform} eq "darwin" && ${os.major} < 10} {
    patchfiles-append   patch-dav1d-workaround-no-pthread-setname-Leopard.diff
}

# nasm is not needed on arm64 platforms
if { ${build_arch} in "i386 x86_64" || [variant_isset universal] } {
    depends_build-append  port:nasm
}

# workaround meson change that causes configure to fail on older OS X versions
# see https://github.com/mesonbuild/meson/issues/8307
compiler.blacklist-append *gcc-3.* *gcc-4.*
compiler.blacklist-append { clang < 700 } macports-clang-3.3 macports-clang-3.4

configure.args-append \
                    -Denable_tests=false

variant test description {enable tests} {
    configure.args-replace  -Denable_tests=false -Denable_tests=true
    test.run                yes
    test.target             test
}

if {${universal_possible} && [variant_isset universal]} {
    lappend merger_configure_env(i386)      LDFLAGS=-Wl,-read_only_relocs,suppress,-no_compact_unwind
} elseif {${configure.build_arch} eq "i386"} {
    configure.env-append                LDFLAGS=-Wl,-read_only_relocs,suppress,-no_compact_unwind
}

# developer docs are automatically built if doxygen and dot (graphviz) are present
# but are not installed

set docdir              ${prefix}/share/doc/${name}

post-destroot {
    xinstall -m 0755 -d ${destroot}${docdir}

    xinstall -m 0644 -W ${worksrcpath} \
        CONTRIBUTING.md \
        COPYING \
        doc/dav1d_logo.png \
        NEWS \
        README.md \
        THANKS.md \
        ${destroot}${docdir}
}

livecheck.url       https://download.videolan.org/pub/videolan/${name}/
livecheck.regex     {>([0-9.]+)/<}
