# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0
PortGroup           cmake 1.1
PortGroup           muniversal 1.0

name                lpcnetfreedv
platforms           darwin macosx
categories          audio
license             BSD
maintainers         {ra1nb0w @ra1nb0w} openmaintainer

description         Experimental Neural Net speech coding for FreeDV
long_description    Experimental version of LPCNet being developed \
    for over the air Digital Voice experiments with FreeDV.

github.setup        drowe67 LPCNet 0.5 v
checksums           rmd160  f7cba418c62f1542ec303c5af501efda46688b09 \
                    sha256  9a9c4358c0bd5053f6ad7274e15aabbe5d8f81f364e27055777b23f4eb02d01a \
                    size    5233452
revision            0
epoch               2

# lpcnet_freedv_internal.h:3: error: redefinition of typedef ‘LPCNetState’
compiler.blacklist-append \
                    *gcc-4.*

# disable AVX and AVX2 for compatibility
configure.args-append \
    -DDISABLE_CPU_OPTIMIZATION=ON

# https://github.com/drowe67/LPCNet/pull/57
patchfiles-append   0001-Do-not-break-build-when-DISABLE_CPU_OPTIMIZATION-ON-.patch \
                    0002-Add-optimization-opts-for-PowerPC.patch

# enable optimization on all supported hardwares
if {${universal_possible} && [variant_isset universal]} {
    set merger_configure_args(x86_64) -DAVX=ON
    set merger_configure_cflags(i386) [list -DSSE=ON -mssse3 -msse4.1]
    set merger_configure_cflags(arm64) -DNEON=ON
    set merger_configure_cflags(ppc) -DPPC_OPTS=ON
    set merger_configure_cflags(ppc64) -DPPC_OPTS=ON
} else {
    switch -- ${configure.build_arch} {
        x86_64 { configure.args-append -DAVX=ON }
        i386 { configure.cflags-append -DSSE=ON -mssse3 -msse4.1 }
        arm64 { configure.cflags-append -DNEON=ON }
        ppc { configure.cflags-append -DPPC_OPTS=ON }
        ppc64 { configure.cflags-append -DPPC_OPTS=ON }
    }
}

# select native cpu flags
variant native description {Enable auto selection of cpu flags like avx/avx2/neon} {
    configure.args-delete -DDISABLE_CPU_OPTIMIZATION=ON
}

test.run            yes
