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

name                lame
version             4.0
revision            0
set branch          [join [lrange [split ${version} .] 0 1] .]
categories          audio
license             LGPL-2.1+
platforms           darwin freebsd
maintainers         nomaintainer

description         Lame Ain't an MP3 Encoder
long_description    LAME is an educational tool to be used for learning \
                    about MP3 encoding. The goal of the LAME project is to use \
                    the open source model to improve the psycho acoustics, \
                    noise shaping and speed of MP3.

homepage            https://lame.sourceforge.net
master_sites        sourceforge:project/lame/lame/${branch}

checksums           rmd160  a1b6b0180b8864f758303e3170c32c55719abcaa \
                    sha256  3df5124d5ad3a98312ffd7ba6a9b36230e4f8a3e66d3ce0f425e336c32d216eb \
                    size    1496810

depends_build-append \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:libiconv \
                    port:mpg123 \
                    port:ncurses

patchfiles-append   allow-deprecated.patch \
                    patch-parse.c.diff \
                    strnlen.patch

configure.args      --disable-gtktest

variant simd description "Optimize for the arch via SIMD" {
# https://tmkk.undo.jp/lame/index_e.html
# Updated PPC version from: https://github.com/classilla/lamevmx
    if {${configure.build_arch} in [list arm arm64]} {
        patchfiles-append \
                    lame-3.100-neon-20230418.diff
    } elseif {${configure.build_arch} in [list i386 x86_64]} {
        patchfiles-append \
                    lame-3.100-sse-20171014.diff
        depends_build-append \
                    port:nasm
        configure.args-append \
                    --enable-nasm
    } elseif {${configure.build_arch} in [list ppc ppc64]} {
        patchfiles-append \
                    lame-4.0-altivec-20260802.diff
        patchfiles-delete \
                    patch-parse.c.diff
        if {${os.platform} eq "darwin" && ${os.major} == 10} {
            # This is for Rosetta:
            configure.args-append \
                    --build=powerpc-apple-darwin${os.major}.${os.minor}
        }
        # https://github.com/classilla/lamevmx/issues/1
        configure.cflags-append -faltivec
    }
}

if {![variant_isset universal] && ${os.arch} in [list arm powerpc i386]} {
    default_variants +simd
}

livecheck.regex     /${name}-(\\d+(?:\\.\\d+)+)${extract.suffix}
