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

name                hdhomerun
version             20230303
revision            0
categories          net multimedia
platforms           darwin
supported_archs     x86_64 arm64
license             LGPL-3+
maintainers         nomaintainer
description         HDHomeRun device configuration utility
homepage            https://www.silicondust.com/

master_sites        http://download.silicondust.com/hdhomerun

if {${name} eq ${subport}} {
    long_description    Provides a library and utility program to access, configure and test \
                        HDHomeRun network tuner devices from SiliconDust.  May also be used to \
                        upgrade firmware. Command line-driven and scriptable.

    distname            lib${name}_${version}
    extract.suffix      .tgz
    extract.only        ${distname}${extract.suffix}
    worksrcdir          lib${name}
    checksums           rmd160  cb1231ffe66177e17a4eb0cebd22c242af9eb394 \
                        sha256  7e872558f42818b1cd2f0ba0a0c6613315c4656b484fd2906d0b8f3ce7e0711a \
                        size    62682
    universal_variant   yes

    patchfiles          patch-01-Makefile.diff
    patch.pre_args-replace  -p0 -p1

    post-patch {
        reinplace -locale C "s|@PREFIX@|${prefix}|g" ${worksrcpath}/Makefile
    }

    use_configure       no

    build.args-append   CC=${configure.cc} \
                        VERBOSE=1

    if {![info exists universal_possible]} {
        set universal_possible [expr {${os.universal_supported} && [llength ${configure.universal_archs}] >= 2}]
    }
    if {${universal_possible} && [variant_isset universal]} {
        build.args-append \
                        TARGET="[portconfigure::configure_get_universal_archflags]"
    } else {
        build.args-append \
                        TARGET="[get_canonical_archflags cc]"
    }

    destroot {
        xinstall -m 0755 ${worksrcpath}/hdhomerun_config \
            ${destroot}${prefix}/bin/hdhomerun_config
        xinstall -m 0755 ${worksrcpath}/libhdhomerun.dylib \
            ${destroot}${prefix}/lib/libhdhomerun.dylib
        xinstall -d -m 0755 ${destroot}${prefix}/include/libhdhomerun/
        xinstall -m 0644 -W ${worksrcpath} \
                hdhomerun.h hdhomerun_channels.h hdhomerun_channelscan.h \
                hdhomerun_control.h hdhomerun_debug.h hdhomerun_device.h \
                hdhomerun_device_selector.h hdhomerun_discover.h hdhomerun_os.h \
                hdhomerun_os_posix.h hdhomerun_pkt.h hdhomerun_sock.h \
                hdhomerun_types.h hdhomerun_video.h \
            ${destroot}${prefix}/include/libhdhomerun/
        xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}/
        xinstall -m 0644 ${worksrcpath}/README.md \
            ${destroot}${prefix}/share/doc/${name}/README.md
    }
    livecheck.type      regex
    livecheck.url       http://www.silicondust.com/support/hdhomerun/downloads/
    livecheck.regex     Current release: (\[0-9\]+)
}

notes "Up to date device firmware is available from:\n\
\thttps://www.silicondust.com/support/linux/"
