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

set modname         s98
name                lib${modname}
github.setup        TTK-qmmp qmmp-${modname} dfcc3d1ae93c88a82a2b3544c96a727c9da7939f
version             20251217
revision            0
categories          audio
license             GPL-3
maintainers         nomaintainer
description         Input plugin for qmmp to play ${modname} modules
long_description    {*}${description}
checksums           rmd160  1146c4a1740094c24797193ecb70541e3a062bb8 \
                    sha256  a5a974b21ca6180403505038c2a451ad11e5d03028834e5efd5dfbc6b87c72bf \
                    size    559780
github.tarball_from archive

post-extract {
    copy ${filespath}/Makefile ${worksrcpath}/
}

post-patch {
    # Old Xcode gcc neither need nor support this flag:
    if {[string match *gcc-4.* ${configure.compiler}]} {
        reinplace "s|@extra_flag@||" ${worksrcpath}/Makefile
    } else {
        reinplace "s|@extra_flag@|-Wno-incompatible-pointer-types|" ${worksrcpath}/Makefile
    }
}

depends_lib-append  port:zlib

destroot {
    copy ${worksrcpath}/${name}.dylib ${destroot}${prefix}/lib/
    set incdir ${destroot}${prefix}/include/${name}
    xinstall -d ${incdir}
    copy ${worksrcpath}/${name}/${modname}.h ${incdir}/
    copy ${worksrcpath}/${name}/tchar.h ${incdir}/
    # Okay, this is ugly, I know.
    # We need to install headers, preserving directory hierarchy...
    fs-traverse f ${worksrcpath}/${name}/device {
        if {[file isfile ${f}] && ([file extension ${f}] eq ".c" || [file extension ${f}] == ".cpp" \
            || [file extension ${f}] eq ".o" || [file extension ${f}] == ".txt")} {
            delete ${f}
        }
    }
    copy ${worksrcpath}/${name}/device ${incdir}/
}
