# -*- 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: Portfile 117338 2014-02-22 19:51:10Z macsforever2000@macports.org $

PortSystem          1.0

name                hdhomerun
version             20140121
set firm_version    ${version}
categories          net multimedia
platforms           darwin
license             LGPL-3+
maintainers         nomaintainer
description         HDHomeRun configuration utility
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-drive and scriptable.
homepage            http://www.silicondust.com/

master_sites        http://download.silicondust.com/hdhomerun
distname            lib${name}_${version}
patchfiles          patch-01-Makefile-libpath.diff patch-02-Makefile-universal.diff
patch.args          -p1
extract.suffix      .tgz
distfiles-append    ${name}_atsc_firmware_${firm_version}.bin \
                    ${name}_dvbt_firmware_${firm_version}.bin \
                    ${name}3_atsc_firmware_${firm_version}.bin \
                    ${name}3_dvbt_firmware_${firm_version}.bin \
                    ${name}3_dvbtc_firmware_${firm_version}.bin \
                    ${name}3_dvbc_firmware_${firm_version}.bin \
                    ${name}3_cablecard_firmware_${firm_version}.bin \
                    ${name}tc_atsc_firmware_${firm_version}.bin
                    
extract.only        ${distname}${extract.suffix}
worksrcdir          lib${name}
checksums           libhdhomerun_20140121.tgz \
                    rmd160  adbcd4df9f2c47a866a989263370710910538c75 \
                    sha256  a86308e7145c0cecb226ee913e7ce44258ef24fcba979d1f32dcff89022f9809 \
                    hdhomerun_atsc_firmware_20140121.bin \
                    rmd160  2974d6948a95f9fe78f6b71721dd719d547a1b82 \
                    sha256  5a9fe681121aca02d00715adf3c8719ce446a3469a0e893342ae3ccf06e427cb \
                    hdhomerun_dvbt_firmware_20140121.bin \
                    rmd160  4139dc8b2abf5fce4a90d951503de259cd832a43 \
                    sha256  ecf423152668e0c89f7e1def44695a501103016e3dbcffb0dd2d9c2bbda43d7c \
                    hdhomerun3_atsc_firmware_20140121.bin \
                    rmd160  36ca8b46ec1fd2189b95eaf9954474cd879cc1d3 \
                    sha256  f8f808d6b08abc7fe0c25ade2988bed47d924ba08b946bdb7af076d7b7432061 \
                    hdhomerun3_dvbt_firmware_20140121.bin \
                    rmd160  24dd64141ab84f274e59d7b961041d31e3fc8dda \
                    sha256  4d911ae08a510be8b94598af561db454891bfa8d9149c1419c70b7cbcf658ae0 \
                    hdhomerun3_dvbtc_firmware_20140121.bin \
                    rmd160  d5699eaf9e76bcc47e349f1968da14d1b05c63ed \
                    sha256  be64d4d6de06231a162cd222289a8d9d6b73e8cfd7f4ad232496fa4cd2fc3a63 \
                    hdhomerun3_dvbc_firmware_20140121.bin \
                    rmd160  7ac240926d29204aaebeb0f175bd912a04846b65 \
                    sha256  f1d3928cac3a63691b012aed70c7eac438c30bbf8822554de2d105089cce795d \
                    hdhomerun3_cablecard_firmware_20140121.bin \
                    rmd160  08f2b118635adaf77beb42f9173429f71e62feaf \
                    sha256  262b002b6d0ab72160cb41f83d0400c8b3b2bb2bc4b2976a0a6b757d70f83824 \
                    hdhomeruntc_atsc_firmware_20140121.bin \
                    rmd160  a65ea2c067c5e7975238c0c28d6a0598f1d5daf7 \
                    sha256  6e6e0ab54ec6528434672e8af4d0c716633b6e5f26376f24e5fb4f5687233ca4

livecheck.type      regex
livecheck.url       http://www.silicondust.com/support/hdhomerun/downloads/
livecheck.regex     Current release: (\[0-9\]+)

use_configure       no

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

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_${firm_version}.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
}

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_${firm_version}.bin)
HDHR-EU (hdhomerun_dvbt_firmware_${firm_version}.bin)
HDHR3-US (hdhomerun3_atsc_firmware_${firm_version}.bin)
HDHR3-DT (hdhomerun3_dvbt_firmware_${firm_version}.bin)
HDHR3-EU (hdhomerun3_dvbtc_firmware_${firm_version}.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)
"
