# -*- 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 78270 2011-05-01 02:08:15Z ecronin@macports.org $

PortSystem          1.0

name                hdhomerun
version             20110323
revision            1
set firm_version    ${version}
categories          net multimedia
platforms           darwin

maintainers         ecronin openmaintainer
description         HDHomeRun Software and Firmware
long_description    ${description}
homepage            http://www.silicondust.com/

master_sites        http://download.silicondust.com/hdhomerun
distname            lib${name}_${version}
patchfiles          Makefile-universal.diff Makefile-libpath.diff
patch.args          -p1
extract.suffix      .tgz
distfiles-append    ${name}_atsc_firmware_${firm_version}.bin \
                    ${name}_dvbt_firmware_${firm_version}.bin
extract.only        ${distname}${extract.suffix}
worksrcdir          lib${name}
checksums           ${distname}${extract.suffix} \
                        sha1    8b70bb0f86e3298a7961f3bf5330df48ba709a63 \
                        rmd160  163dac6b479f3f3aa6a14da19e830cf213c7e31f \
                    ${name}_atsc_firmware_${firm_version}.bin \
                        sha1    80caf663779d6485c0c587dad67923ecea1dcc7b \
                        rmd160  ce37c889f749f726ab579f0697a227d027fa4e21 \
                    ${name}_dvbt_firmware_${firm_version}.bin \
                        sha1 474c187a9cd514d59f62ccaaa3512f87f5c3ada3 \
                        rmd160 9234758b0435a273256813f19dd828d9ba98b970
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}/
    xinstall -m 0644 ${distpath}/${name}_atsc_firmware_${firm_version}.bin \
        ${destroot}${prefix}/share/${name}/${name}_atsc_firmware_${firm_version}.bin
    xinstall -m 0644 ${distpath}/${name}_dvbt_firmware_${firm_version}.bin \
        ${destroot}${prefix}/share/${name}/${name}_dvbt_firmware_${firm_version}.bin
    xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}/
    xinstall -m 0644 ${worksrcpath}/README \
        ${destroot}${prefix}/share/doc/${name}/README
}

notes   "
To upgrade device to newest firmware run:
    hdhomerun_config <id> upgrade ${prefix}/share/${name}/<firmware>
where <firmware> is ${name}_atsc_firmware_${firm_version}.bin for US/CA or
${name}_dvbt_firmware_${firm_version}.bin for EU/AU/NZ.
"

