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

PortSystem          1.0

name                hdhomerun
version             20150826
categories          net multimedia
platforms           darwin
supported_archs     i386 x86_64
license             LGPL-3+
maintainers         ctreleaven openmaintainer
description         HDHomeRun configuration utility
homepage            http://www.silicondust.com/

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

if {${name} eq ${subport}} {
    set firm_version    20150826
    conflicts           ${name}-devel
    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}
    # older models no longer receiving firmware upgrades
    distfiles-append    ${name}_atsc_firmware_20150604.bin \
                        ${name}_dvbt_firmware_20150604.bin \
                        ${name}3_atsc_firmware_20150604.bin \
                        ${name}3_dvbt_firmware_20150604.bin \
                        ${name}3_dvbtc_firmware_20150604.bin \
                        ${name}3_dvbc_firmware_${firm_version}.bin \
                        ${name}3_cablecard_firmware_${firm_version}.bin \
                        ${name}tc_atsc_firmware_${firm_version}.bin \
                        ${name}4_atsc_firmware_${firm_version}.bin \
                        ${name}4_dvbt_firmware_${firm_version}.bin
	checksums           libhdhomerun_20150826.tgz \
						rmd160  c9a9e796e09cb98a3630ae504960c1a87a47a277 \
						sha256  907dfbd1eb82aebd8b09e7c00c21a02433e6baaacf4a4f99aa2511b1d5244baf \
						hdhomerun_atsc_firmware_20150604.bin \
						rmd160  af2594974cf4a00f238220797e4e8086ad16eda7 \
						sha256  737d8da48daaa1ef375f755a3bbc28ba6e232f47142bc4e2a160387bb89dd6f8 \
						hdhomerun_dvbt_firmware_20150604.bin \
						rmd160  4bf2f563c40c07f0b64fa037e16a4d55f8beb277 \
						sha256  d611f0c124c5e5aa4d5a99f1fda181675efb6f84c6ebe958e2615d742b7aa785 \
						hdhomerun3_atsc_firmware_20150604.bin \
						rmd160  6045ae5e5d62c5edcac904594aa619c90d4a449c \
						sha256  79926ace9a6526b4d29cbb4cd5c144dcb136eed97e8700f323a15d10c0a9d6c7 \
						hdhomerun3_dvbt_firmware_20150604.bin \
						rmd160  58785678b432b239725fc02685c11377afbdcb44 \
						sha256  6d71626e6bf352e2f84400a59af39e3e59a323796e1a4efbe56dca6a9f55d953 \
						hdhomerun3_dvbtc_firmware_20150604.bin \
						rmd160  0ee2a6288fc67745227b889ff352329289d8c6b3 \
						sha256  9f33df383de44df0a828f6c9912446baa0e8a4de16cc1d071e94fa45227e0605 \
						hdhomerun3_dvbc_firmware_20150826.bin \
						rmd160  880a08167db93c95726dc58c3094285f3060ea09 \
						sha256  338f36f332d69f27c6326f83023234fed32e5da19b1150d185fb118458a4e046 \
						hdhomerun3_cablecard_firmware_20150826.bin \
						rmd160  ba795d7c705aa2a65860b12eda55748b16920951 \
						sha256  e4975283c2c48a93ecb23394d0cc3033a9bbcfa7705ca2d51abcdb47d2fe55a9 \
						hdhomeruntc_atsc_firmware_20150826.bin \
						rmd160  eb9aa12eac7e9b67bd213489cc8e76156fbdb5a7 \
						sha256  dbbc8667fa8ce19a40c99c176ede74b88374d236d674595294b128d795edb26d \
						hdhomerun4_atsc_firmware_20150826.bin \
						rmd160  441ecf2297c0498c2ccb23f9d90052bf750923fa \
						sha256  563c676dfe09daad961d8fc90cbaa24fdc2ca349035abd95fb09f7b74ef80a83 \
						hdhomerun4_dvbt_firmware_20150826.bin \
						rmd160  83e9e313746f64c559849eb96ac2343a6c85bc35 \
						sha256  51108d0d0429e96a6c0424b0360c1e7c13ed105e31dba3251a8b0c32a58246db

    patchfiles          patch-01-Makefile-libpath.diff patch-02-Makefile-universal.diff
    patch.args          -p1
    post-patch {
        reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/Makefile
    }

    use_configure       no
    
    build.args-append   CC=${configure.cc} \
                        CXX=${configure.cxx} \
                        CPP=${configure.cpp}
    if {[variant_isset universal]} {
        build.args-append   CFLAGS="${configure.universal_cflags}"
    } else {
        build.args-append   CFLAGS="${configure.cc_archflags}"
    }
    
    destroot {
        xinstall -m 0755 ${worksrcpath}/hdhomerun_config \
            ${destroot}${prefix}/bin/hdhomerun_config
        xinstall -m 0755 ${worksrcpath}/libhdhomerun.dylib \
            ${destroot}${prefix}/lib/libhdhomerun.dylib
        xinstall -m 0644 -W ${worksrcpath} \
                hdhomerun.h hdhomerun_os.h hdhomerun_os_posix.h \
                hdhomerun_types.h hdhomerun_pkt.h hdhomerun_sock.h \
                hdhomerun_debug.h hdhomerun_discover.h hdhomerun_control.h \
                hdhomerun_video.h hdhomerun_channels.h hdhomerun_channelscan.h \
                hdhomerun_device.h hdhomerun_device_selector.h \
            ${destroot}${prefix}/include/
        xinstall -d -m 0755 ${destroot}${prefix}/share/${name}/
        foreach firm [glob ${distpath}/${name}*firmware_*.bin] {
            set firm [lindex [split ${firm} /] end]
            xinstall -m 0644 ${distpath}/${firm} ${destroot}${prefix}/share/${name}/${firm}
        }
        xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}/
        xinstall -m 0644 ${worksrcpath}/README \
            ${destroot}${prefix}/share/doc/${name}/README
    }
    livecheck.type      regex
    livecheck.url       http://www.silicondust.com/support/hdhomerun/downloads/
    livecheck.regex     Current release: (\[0-9\]+)
}

subport ${name}-devel {
    replaced_by         hdhomerun
    PortGroup           obsolete 1.0
    
    version             20150319beta1
    set firm_version    20150323beta2

}

notes   "
Documentation available at: http://www.silicondust.com/hdhomerun/hdhomerun_development.pdf
To upgrade device to newest firmware run:
    hdhomerun_config <id> upgrade ${prefix}/share/${name}/<firmware>
Choose the correct <firmware> based on your model of HDHomerun device:
HDHR-US (hdhomerun_atsc_firmware_20150604.bin)
HDHR-EU (hdhomerun_dvbt_firmware_20150604.bin)
HDHR3-US (hdhomerun3_atsc_firmware_20150604.bin)
HDHR3-DT (hdhomerun3_dvbt_firmware_20150604.bin)
HDHR4-2DT (hdhomerun4_dvbt_firmware_${firm_version}.bin
HDHR3-EU (hdhomerun3_dvbtc_firmware_20150604.bin)
HDHR3-CC (hdhomerun3_cablecard_firmware_${firm_version}.bin)
HDHR3-4DC (hdhomerun3_dvbc_firmware_${firm_version}.bin)
HDTC-2US (hdhomeruntc_atsc_firmware_${firm_version}.bin)
HDHR4-2US (hdhomrun4_atsc_firmware_${firm_version}.bin)
"