# $Id: Portfile 64214 2010-02-26 05:34:38Z ecronin@macports.org $

PortSystem 1.0

name            lirc
version         0.8.3
revision        2
categories      sysutils net
maintainers     ecronin
platforms       darwin
description     Linux Infrared Remote Control
long_description \
    LIRC is a package that allows you to decode and send infra-red \
    signals of many (but not all) commonly used remote controls.

homepage        http://www.lirc.org
master_sites    sourceforge
use_bzip2       yes
checksums       md5 8e78eeded7b31e5ad02e328970437c0f \
                sha1 4b5aec19fa9ee15bafaeb1f87c154a0d4e045dcc \
                rmd160 8948efc3e9dc34426ea32a3c63da63c0efa7dce2
livecheck.distname  LIRC

configure.args  --with-driver=udp --with-devdir=${prefix}/var/run \
                --sysconfdir=${prefix}/etc --localstatedir=${prefix}/var \
                --mandir=${prefix}/share/man

notes \
    NOTE: After installing you must configure an IR device for lirc \n \
    to use.  Most hardware devices are not supported on Mac OS X \n \
    (known exceptions: IguanaIR)\; network sources (remote lircd, \n \
    HD Homerun, etc) are fully supported. \n \
    \n \
    Please edit: \n \
      '${prefix}/etc/LaunchDaemons/org.macports.${name}/${name}.wrapper' \n \
    and specify a valid driver or remote lircd to connect to.  Examples \n \
    for network, UDP, and IguanaIR are commented out.\n \
    \n \
    Any clients of lirc must be able to read and write the pipe at: \n \
    ${prefix}/var/run/lircd

variant iguanaIR \
    description {Use IguanaIR USB device} {
    configure.args-delete   --with-driver=udp
    configure.args-append   --with-driver=iguanaIR
    depends_lib-append  port:iguanaIR
    patchfiles-append \
        patch-daemons-hw_iguanaIR.c.diff \
        patch-drivers-lirc.h.diff
}

post-destroot {
    xinstall -m 644 ${worksrcpath}/contrib/lircd.conf \
        ${destroot}${prefix}/etc/lircd.conf.sample
    xinstall -m 644 ${worksrcpath}/contrib/lircmd.conf \
        ${destroot}${prefix}/etc/lircmd.conf.sample
    xinstall -m 644 ${worksrcpath}/contrib/lircrc \
        ${destroot}${prefix}/etc/lircrc.sample
    xinstall -m 755 -d ${destroot}${prefix}/var/log
    destroot.keepdirs ${destroot}${prefix}/var/log
}

startupitem.create  yes
startupitem.start   \
    "#device=\"--connect=example.org:port\"  # remote lircd" \
    "#device=\"--driver=udp --device=port\"  # UDP listener" \
    "#device=\"--driver=iguanaIR --device=/tmp/iguanaIR/0 --nodaemon\"  # iguanaIR" \
    "${prefix}/sbin/lircd --permission=0666 \$\{device\}" \
    "\[ -r ${prefix}/etc/lircmd.conf \] && \\" \
    "\t${prefix}/sbin/lircmd"
startupitem.stop    \
    "killall -TERM lircd" \
    "killall -TERM lircmd"
