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

name                libgsm
version             1.0.22
revision            0
license             public-domain

categories          audio
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer
description         library and tools to convert to/frm gsm audio format
long_description    {*}${description}

homepage            https://www.quut.com/gsm
distname            gsm-${version}
master_sites        ${homepage}
checksums           rmd160  f941151dc3bcf27ccb393bb1fdcdedabe80d6c34 \
                    sha256  f0072e91f6bb85a878b2f6dbf4a0b7c850c4deb8049d554c65340b3bf69df0ac \
                    size    66583

worksrcdir          gsm-1.0-pl22

patchfiles-append   patch-makefile.diff

post-patch {
    reinplace "s|@@VERSION@@|${version}|g" ${worksrcpath}/Makefile
}

variant universal   {}
use_parallel_build  no

destroot.env        INSTALL_ROOT=${destroot}${prefix}

post-destroot {
    move ${worksrcpath}/lib/libgsm.${version}.dylib ${destroot}${prefix}/lib
    move ${worksrcpath}/lib/libgsm.1.dylib ${destroot}${prefix}/lib
    move ${worksrcpath}/lib/libgsm.dylib ${destroot}${prefix}/lib

    system -W ${destroot}${prefix} \
        "install_name_tool -id  ${prefix}/lib/libgsm.${version}.dylib ./lib/libgsm.${version}.dylib"
    system -W ${destroot}${prefix} \
        "install_name_tool -change ./lib/libgsm.${version}.dylib  ${prefix}/lib/libgsm.${version}.dylib ./bin/tcat"
    system -W ${destroot}${prefix} \
        "install_name_tool -change ./lib/libgsm.${version}.dylib  ${prefix}/lib/libgsm.${version}.dylib ./bin/toast"
    system -W ${destroot}${prefix} \
        "install_name_tool -change ./lib/libgsm.${version}.dylib  ${prefix}/lib/libgsm.${version}.dylib ./bin/untoast"

    # Rename tcat to gsm-tcat
    # https://trac.macports.org/ticket/67865
    move ${destroot}${prefix}/bin/tcat ${destroot}${prefix}/bin/gsm-tcat
}

# this is only a partial test of the software's adding algorithm
#test.run            yes
#test.target         addtst
#test.args           ${build.args}

# to test the encoding and decoding, see <https://ccrma.stanford.edu/~fujishim/199/gsm_survey.html>
# to convert samples to gsm for testing, see <https://convertio.co/wav-gsm/>

notes "
tcat has been installed as gsm-tcat
"

livecheck.type      regex
livecheck.url       ${master_sites}
livecheck.regex     gsm-(\\d+(?:\\.\\d+)*)${extract.suffix}
