# -*- 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 ffmpeg and ffmpeg-devel whenever
# dav1d's version is updated.
version             0.9.2
revision            0
categories          multimedia
platforms           darwin
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}

checksums           rmd160  92ce76083f287df70f01374816af7cb7ec653720 \
                    sha256  d9bbdbf54923b19199162f6357da2932ee7caed7dbefb0d37626b6669bc50e57 \
                    size    834322

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} < 11} {
    patchfiles-append   patch-dav1d-workaround-no-pthread-setname-Leopard.diff
    # files ppc/types.h collides with system header on PPC darwin
    patchfiles-append   0002-dav1d-move-ppc-types.h-to-ppc-dav1d_types.h.patch
    post-patch {
        move ${worksrcpath}/src/ppc/types.h \
             ${worksrcpath}/src/ppc/dav1d_types.h
    }
}

# 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*

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 {![info exists universal_possible]} {
    set universal_possible [expr {${os.universal_supported} && [llength ${configure.universal_archs}] >= 2}]
}
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.]+)/<}
