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

# _faccessat, _clock_gettime
legacysupport.newest_darwin_requires_legacy 15

name                hamclock
version             4.20
revision            0
categories          x11
license             MIT
maintainers         nomaintainer
description         Handy clock with features for amateur radio operators
long_description    HamClock is a kiosk-style application that provides \
                    real time space weather, radio propagation models, \
                    operating events and other information particularly \
                    useful to the radio amateur.

homepage            https://www.clearskyinstitute.com/ham/HamClock
master_sites        ${homepage}/
distname            ESPHamClock-V${version}
extract.suffix      .tgz
checksums           rmd160  b580cb6e5f10b1aa000291c8243ab7a90a8602d2 \
                    sha256  a4670e452b6472e916a0fb1343a8c61998d8420287fbd404725cd8357f4ce9ee \
                    size    1966954

worksrcdir          ESPHamClock

post-patch {
    # Respect build environment:
    reinplace "s|CXXFLAGS =|CXXFLAGS +=|" ${worksrcpath}/Makefile
    reinplace "s|LIBS =|LIBS +=|" ${worksrcpath}/Makefile
    reinplace "s|CXX =|CXX ?=|" ${worksrcpath}/ArduinoLib/Makefile
    # Fix X11 paths:
    reinplace "s|/opt/X11|${prefix}|g" ${worksrcpath}/Makefile
}

depends_lib-append  port:xorg-libX11

depends_run-append  port:desktop-file-utils

compiler.cxx_standard   2017

configure.cxxflags-append \
                        -DNO_UPGRADE

# If desired, there are targets for other sizes.
build.target            hamclock-1600x960

if {${os.platform} eq "darwin" && ${os.major} < 16} {
    build.env-append    LIBS=-lMacportsLegacySupport
}

destroot {
    copy ${worksrcpath}/${build.target} ${destroot}${prefix}/bin
    # Make a symlink, so that it can be invoked with ${name}
    ln -s ${build.target} ${destroot}${prefix}/bin/${name}
    xinstall -d ${destroot}${prefix}/share/applications
    xinstall -d ${destroot}${prefix}/share/icons/hicolor/48x48/apps
    copy ${worksrcpath}/${name}.desktop ${destroot}${prefix}/share/applications
    copy ${worksrcpath}/${name}.png ${destroot}${prefix}/share/icons/hicolor/48x48/apps
}

# Only run this for applications, not icons, to avoid GTK dependency:
post-activate {
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
}
