# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           legacysupport 1.1
PortGroup           makefile 1.0
PortGroup           github 1.0

# strnlen, clock_gettime
legacysupport.newest_darwin_requires_legacy 15

name                pihpsdr
categories          science comms
platforms           darwin macosx
license             GPL-3
maintainers         {ra1nb0w @ra1nb0w} openmaintainer
description         piHPSDR is an HPSDR application designed for low power boards, like Raspberry.
long_description    {*}${description}

github.setup        dl1ycf pihpsdr a5992fe8f83669561eb162d018c41787c360d341
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             20230516-[string range ${github.version} 0 7]
checksums           rmd160  ced4a947f136996cf61d780519b84b3c348a5bf5 \
                    sha256  f3f6c41d97ebc6e7918e82c9261fc3e2540e49dcb3b8aea95a1870298bc6af7d \
                    size    119067573
revision            0

compiler.c_standard 1999

depends_build-append \
    port:pkgconfig

depends_lib-append \
    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
    path:lib/pkgconfig/pango.pc:pango \
    port:atk \
    path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
    path:lib/pkgconfig/glib-2.0.pc:glib2 \
    port:gettext \
    port:portaudio \
    port:fftw-3 \
    port:wdsp \
    port:curl

use_configure       no
makefile.override   CFLAGS LDFLAGS

build.args-append \
    GPIO_INCLUDE= \
    LOCALCW_INCLUDE= \
    STEMLAB_DISCOVERY=STEMLAB_DISCOVERY_NOAVAHI

pre-configure {
    # fix image path
    reinplace "s|\"hpsdr\\.png\"|\"${prefix}/share/pihpsdr/hpsdr.png\"|g" \
        ${worksrcpath}/main.c
}

variant soapysdr description "Enable SoapySDR support" {
    depends_lib-append \
        port:SoapySDR

    build.args-append \
        SOAPYSDR_INCLUDE=SOAPYSDR
}

variant window1440x900 description "Enable 1440x900 resolution on the main window" {
    patchfiles-append \
       largewindow-1440x900.patch
}

variant native description "Native CPU flags" {
    configure.cflags-append -march=native
}

variant localcw description "Enable local CW iambic" {
    build.args-replace \
        LOCALCW_INCLUDE= \
        LOCALCW_INCLUDE=LOCALCW
}

destroot {
    xinstall -d -m 0755 ${destroot}${applications_dir}/piHPSDR.app/Contents
    xinstall -d -m 0755 ${destroot}${applications_dir}/piHPSDR.app/Contents/MacOS
    xinstall -d -m 0755 ${destroot}${applications_dir}/piHPSDR.app/Contents/Resources
    xinstall -m 0644 ${filespath}/pihpsdr.icns \
        ${destroot}${applications_dir}/piHPSDR.app/Contents/Resources/piHPSDR.icns
    xinstall -m 0755 ${worksrcpath}/pihpsdr \
        ${destroot}${applications_dir}/piHPSDR.app/Contents/MacOS/piHPSDR
    xinstall -m 0644 ${filespath}/info.plist \
        ${destroot}${applications_dir}/piHPSDR.app/Contents/Info.plist
    reinplace "s|_VERSION_|${version}|g" \
        ${destroot}${applications_dir}/piHPSDR.app/Contents/Info.plist
    ln -s ${applications_dir}/piHPSDR.app/Contents/MacOS/piHPSDR \
        ${destroot}${prefix}/bin/pihpsdr

    # always needed
     xinstall -m 755 -d ${destroot}/${prefix}/share/pihpsdr
     xinstall -m 644 ${worksrcpath}/release/pihpsdr/hpsdr.png \
         ${destroot}/${prefix}/share/pihpsdr
}
