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

# pthread_setname_np and llmath fixes
legacysupport.newest_darwin_requires_legacy 10

name                    aom
version                 3.13.1
revision                0
categories              multimedia
maintainers             {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
license                 BSD

description             AV1 Codec Library
long_description        {*}${description}

homepage                https://aomedia.googlesource.com/aom

# use git fetch rather than downloading a snapshot tarball
# which delivers a different checksum and size on each download
# see https://github.com/google/gitiles/issues/84
fetch.type              git
git.url                 https://aomedia.googlesource.com/aom.git
git.branch              v${version}
#master_sites            https://aomedia.googlesource.com/aom/+archive
#distname                v${version}

# see build/cmake/aom_configure.cmake
# Update: Build actually now uses c++17
compiler.cxx_standard   2017
compiler.c_standard     2011

set pyver               3.13
set python_version      [string index ${pyver} 0][string range ${pyver} 2 end]

depends_build-append    port:git \
                        port:perl5 \
                        port:python${python_version}

configure.args-append   -DBUILD_SHARED_LIBS=ON \
                        -DENABLE_EXAMPLES=ON \
                        -DENABLE_TESTS=OFF \
                        -DENABLE_DOCS=OFF \
                        -DGIT_EXECUTABLE=${prefix}/bin/git \
                        -DPERL_EXECUTABLE=${prefix}/bin/perl \
                        -DPYTHON_EXECUTABLE=${prefix}/bin/python${pyver}

# a `native` variant is not needed since aom does runtime CPU detection
# see https://github.com/macports/macports-ports/commit/6a1f839833a71be9b6c69d7e6ddca7a039d46673#commitcomment-49053438

# ensure all AVX2 functions are defined
# see https://trac.macports.org/ticket/62608
compiler.blacklist-append           {clang < 800}
# Build requires c++14 and c++17 'extensions'
compiler.blacklist-append           {clang < 1300}

# possible values of AOM_TARGET_CPU: arm64 x86_64 x86 ppc generic
# see https://trac.macports.org/ticket/62611 for CONFIG_RUNTIME_CPU_DETECT
# PPC assembler and cpu detection are broken; use generic target until someone gets time to fix those.
set merger_configure_args(arm64)    "-DAOM_TARGET_CPU=arm64 -DCONFIG_RUNTIME_CPU_DETECT=OFF"
set merger_configure_args(x86_64)   -DAOM_TARGET_CPU=x86_64
set merger_configure_args(i386)     -DAOM_TARGET_CPU=x86
set merger_configure_args(ppc)      "-DAOM_TARGET_CPU=generic -DCONFIG_RUNTIME_CPU_DETECT=OFF"
set merger_configure_args(ppc64)    "-DAOM_TARGET_CPU=generic -DCONFIG_RUNTIME_CPU_DETECT=OFF"

if {${universal_possible} && [variant_isset universal]} {
    if {"x86_64" in ${configure.universal_archs} || "i386" in ${configure.universal_archs}} {
        depends_build-append        port:yasm
    }
} else {
    if {${configure.build_arch} in {i386 x86_64}} {
        depends_build-append        port:yasm
    }
    configure.args-append           {*}$merger_configure_args(${configure.build_arch})
}

livecheck.type          regex
livecheck.url           https://aomedia.googlesource.com/aom.git
livecheck.regex         ">v(\\d+(?:\\.\\d+)*)<"
