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

name                fldigi
version             4.2.13
revision            1
# same sources but with different version
set version_flarq   4.3.9
categories          science
platforms           darwin macosx
license             GPL-3
maintainers         {ra1nb0w @ra1nb0w} openmaintainer

description         Fast Light Digital Modem Application
long_description    Fldigi (Fast Light Digital Modem Application), is a \
    cross-platform modem program that supports most of the peer-to-peer \
    (live keyboard) digital modes used on the amateur radio bands.
homepage            http://www.w1hkj.com
master_sites        sourceforge:project/fldigi/${name}

checksums           rmd160  f10c3c7703bb4db346d21ba23f4c1b8aba85803c \
                    sha256  a1e8d990359ce9c0cce3ceb5116fd0cf72c95528969766898640ca6ca2dba8d4 \
                    size    5244946

depends_build-append \
    port:pkgconfig \
    port:asciidoc

depends_lib-append \
    path:lib/libfltk.dylib:fltk \
    path:lib/libhamlib.dylib:hamlib \
    port:libpng \
    port:libsamplerate \
    port:libsndfile \
    port:portaudio

configure.args-append \
    --without-pulseaudio \
    --with-asciidoc

# build fix: remove -no-stack-check on macOS < 10.10
if {${os.platform} eq "darwin" && ${os.major} <= 13} {
    patchfiles-append \
        remove_no-stack-check.patch
}

# We put this into a pre-configure block so it can be evaluated _after_ platform selection.
pre-configure {

    # enable optimization on all Intel hardwares
    if {[variant_exists universal] && [variant_isset universal]} {
        set merger_configure_args(x86_64) configure.args-append --enable-optimizations=x86-64
        set merger_configure_args(i386)   configure.args-append --enable-optimizations=i686
    } elseif {[variant_isset native]} {
        if {${configure.build_arch} eq "arm64"} {
            notes-append {
+native is no longer avilable on MacOS ARM64 due to compiler 
changes.  The option remains so your upgrades won't fail
but it does nothing.

To remove this notice, reinstall without the "+native" option
}
        } else {
            configure.args-append --enable-optimizations=native
        }
    } else {
        switch -- ${configure.build_arch} {
            x86_64 { configure.args-append --enable-optimizations=x86-64 }
            i386   { configure.args-append --enable-optimizations=i686 }
        }
    }

    # Fix building for older macOS versions via MACOSX_DEPLOYMENT_TARGET
    # from http://www.w1hkj.com/doku/doku.php?id=howto:building_on_os_x
    if {${os.platform} eq "darwin" && [vercmp $macosx_deployment_target 10.12] < 0} {
        configure.args-append \
            --without-clock_gettime
        configure.env-append \
            MACOSX_DEPLOYMENT_TARGET=${macosx_deployment_target}
    }
}

variant bundle description {Enable the optional macOS bundle of fldigi/flarq} {
    patchfiles-append \
        patch-mkappbundle.sh.diff
    build.target    appbundle
    post-destroot {
        xinstall -d -m 0755 ${destroot}${applications_dir}
        copy ${workpath}/${name}-${version}/src/${name}-${version}/${name}-${version}.app ${destroot}${applications_dir}/${name}.app
        copy ${workpath}/${name}-${version}/src/${name}-${version}/flarq-${version_flarq}.app ${destroot}${applications_dir}/flarq.app
    }
}

variant pulseaudio description {Build fldigi with pulseaudio support} {
    configure.args-delete --without-pulseaudio
    configure.args-append --with-pulseaudio
    depends_lib-append \
        port:pulseaudio
}

variant native conflicts universal description {Enable native cpu flags optimization} {
    # check pre-configure
}

default_variants-append +bundle

livecheck.type      regex
livecheck.url       ${master_sites}
livecheck.regex     ${name}-(\[0-9.\]+)${extract.suffix}

test.run            yes
test.cmd            ./src/fldigi --version

