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

github.setup        Dsplib libdspl-2.0 abe9dd1bfe16da498a7bf480523eae7e7791aa50
name                dspl
version             2025.08.27
revision            0
categories          science math
license             LGPL-3
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         Opensource cross-platform digital signal processing algorithm library
long_description    {*}${description}, written in C.
homepage            http://en.dsplib.org
checksums           rmd160  9da4ad40612f522c6c7fc1d1fecc44dcda0c11ef \
                    sha256  6bfef00c2ddd1dc28681988db99d6a1a08bb8ae4d9b14e5e95d279ae2bd2d3dd \
                    size    5960285
github.tarball_from archive

post-extract {
    # DOS to UNIX line endings so we can patch.
    reinplace -W ${worksrcpath}/dspl/src/dft "s|\r||g" fft_cmplx.c ifft_cmplx.c
}

patchfiles          0001-Fixes-for-Macports.patch

compilers.setup     require_fortran
compiler.blacklist-append \
                    {*gcc-[3-4].*} {clang < 400}

post-patch {
    reinplace "s,@CC@,${configure.cc}," ${worksrcpath}/make.inc
    reinplace "s,@FC@,${configure.fc}," ${worksrcpath}/make.inc
    reinplace "s,@PREFIX@,${prefix},g" ${worksrcpath}/make.inc
    reinplace "s,@PREFIX@,${prefix}," ${worksrcpath}/dspl/Makefile

    platform darwin 10 powerpc {
        # Hack for Rosetta:
        reinplace "s,-lquadmath,,g" ${worksrcpath}/make.inc
    }
}

destroot {
    copy ${worksrcpath}/_release/dspl.h ${destroot}${prefix}/include/
    if {${os.platform} eq "darwin"} {
        copy ${worksrcpath}/_release/libdspl.dylib ${destroot}${prefix}/lib/
        system "install_name_tool -id ${prefix}/lib/libdspl.dylib ${destroot}${prefix}/lib/libdspl.dylib"
    } else {
        copy ${worksrcpath}/_release/libdspl.so ${destroot}${prefix}/lib/
    }
    xinstall -d ${destroot}${prefix}/share/${name}
    copy ${worksrcpath}/_release/dspl.c ${destroot}${prefix}/share/${name}/
    xinstall -m 0644 -W ${worksrcpath} README.md LICENSE ${destroot}${prefix}/share/${name}/
}
