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

name                lame
version             3.100
revision            3
checksums           rmd160  e467c1f9458ca6878cd46e89fffce8970b9ea936 \
                    sha256  ddfe36cab873794038ae2c1210557ad34857a4b6bdc515785d1da9e175b1da1e \
                    size    1524133

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            http://lame.sourceforge.net/
master_sites        sourceforge:project/lame/lame/${branch}

depends_lib         port:ncurses \
                    port:libiconv

# Should be addressed in next upstream release
patchfiles          patch-avoid_undefined_symbols_error.diff

patchfiles-append   allow-deprecated.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 {${build_arch} in [list arm arm64]} {
        patchfiles-append \
                    lame-${version}-neon-20230418.diff
    } elseif {${build_arch} in [list i386 x86_64]} {
        patchfiles-append \
                    lame-${version}-sse-20171014.diff
    } elseif {${build_arch} in [list ppc ppc64]} {
        patchfiles-append \
                    lame-${version}-altivec-20171217.diff
        post-patch {
            reinplace "s|@SYSROOT@|${developer_dir}/SDKs/MacOSX${macosx_sdk_version}.sdk|" \
                ${worksrcpath}/configure
            if {${build_arch} eq "ppc64"} {
                reinplace "s|-arch ppc750 -arch ppc7400 -arch ppc970|-arch ppc970|" \
                    ${worksrcpath}/configure
            } elseif {${build_arch} eq "ppc"} {
                # If building for ppc natively, a specific arch may be chosen here:
                reinplace "s|-arch ppc750 -arch ppc7400 -arch ppc970|-arch ppc|" \
                    ${worksrcpath}/configure
            }
        }
        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}