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

name                    welle.io
subport welle.io-devel  {}

categories              multimedia
platforms               darwin
maintainers             nomaintainer

description             DAB/DAB+ Software Radio
long_description        This is an open source DAB and DAB+ software defined radio (SDR)  \
                        with support for rtl-sdr (RTL2832U) and airspy. It supports  \
                        high DPI and touch displays and it runs even on cheap computers  \
                        like Raspberry Pi 2/3 and 100€ China Windows 10 tablets.

license                 GPL-3+
license_noconflict      openssl mpg123

homepage                https://www.welle.io/

depends_lib-append      port:faad2 \
                        port:fftw-3-single \
                        port:lame \
                        path:lib/pkgconfig/libusb-1.0.pc:libusb \
                        port:mpg123

default_variants        +rtlsdr +soapysdr +airspy

variant rtlsdr description {Add RTL-SDR support} {
    configure.pre_args-append \
        -DRTLSDR=ON
    depends_lib-append port:rtl-sdr
}

variant soapysdr description {Add SoapySDR support} {
    configure.pre_args-append \
        -DSOAPYSDR=ON
    depends_lib-append port:SoapySDR
}

variant airspy description {Add Airspy support} {
    configure.pre_args-append \
        -DAIRSPY=ON
    depends_lib-append port:airspy
}

variant cli description {Also compile welle-cli} {
    # mpg123 is licensed as LGPL-2.1 except for
    # file src/libout123/modules/coreaudio.c which is GPL-2
    # welle-cli relies on libout123 while the GUI does not.
    # In order to have binaries distributed for welle-io,
    # we enable only welle-gui by default. The user can enable
    # cli variant to build also welle-cli locally.

    configure.pre_args-replace -DBUILD_WELLE_CLI=OFF -DBUILD_WELLE_CLI=ON

    license_noconflict-delete   mpg123

    post-patch {
        reinplace "s!\"index.html\"!\"${applications_dir}/welle-io.app/Contents/Resources/welle-cli/index.html\"!" \
        ${worksrcpath}/src/welle-cli/webradiointerface.cpp
        reinplace "s!\"index.js\"!\"${applications_dir}/welle-io.app/Contents/Resources/welle-cli/index.js\"!" \
        ${worksrcpath}/src/welle-cli/webradiointerface.cpp
    }

    post-destroot {
        ln -s ${applications_dir}/welle-io.app/Contents/MacOS/welle-cli \
            ${destroot}${prefix}/bin/welle-cli
    }
}

variant profiling description {Enable profiling (see README.md)} {
    configure.pre_args-append \
        -DPROFILING=ON
}

variant kiss_fft description {Use KISS FFT instead of FFTW} {
    configure.pre_args-append \
        -DKISS_FFT=ON
    depends_lib-delete  port:fftw-3-single
}

if {${subport} eq ${name}} {
    # stable
    PortGroup               qt5 1.0

    github.setup            AlbrechtL welle.io 2.4 v
    github.tarball_from     archive
    epoch                   1
    revision                1

    conflicts               welle.io-devel

    checksums               rmd160  e0ae521ea2c9bc7becc1610bd616fb1f575059d3 \
                            sha256  7c2a2ff7b6e0780aee8a30a2beedfa831ce67683e1d076a73cebc897637d0202 \
                            size    6764741

    qt5.depends_component   qtcharts \
                            qtdeclarative \
                            qtmultimedia \
                            qtquickcontrols \
                            qtquickcontrols2
    qt5.min_version         5.10.0

    configure.pre_args-append \
        -DGIT_COMMIT_HASH=${version}
} else {
    # devel
    PortGroup               qt6 1.0

    github.setup            AlbrechtL welle.io 6b69a78c99df4b46ec2589093cd39f05c9ac4641
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from     tarball
    set githash             [string range ${github.version} 0 6]
    version                 20221214.git${githash}
    revision                0

    conflicts               welle.io

    checksums               rmd160  5fc4c3be4cc027f6491b142dc14963a0d776e84c \
                            sha256  4cadc5062a78819641a8a63425d0650be69b961c4958d1c4e51c0a0514386ee2 \
                            size    6721458

    qt6.depends_lib         qt5compat \
                            qtcharts \
                            qtdeclarative \
                            qtmultimedia

    qt6.blacklist           {< 6.2}

    configure.pre_args-append \
        -DGIT_COMMIT_HASH=${githash}
}

configure.pre_args-append \
    -DBUILD_WELLE_CLI=OFF \
    -DBUNDLE_INSTALL_DIR=${applications_dir} \
    -DGIT_DESCRIBE=${version} \
    -DWELLE-IO_VERSION=${version}

post-patch {
    reinplace "s/\$(PRODUCT_BUNDLE_IDENTIFIER)/@PRODUCT_BUNDLE_IDENTIFIER@/" ${worksrcpath}/welle-io.plist
}
