# $Id: Portfile 117991 2014-03-18 15:53:02Z macsforever2000@macports.org $

PortSystem 1.0

name            lirc
version         0.9.0
categories      sysutils net
license         GPL-2+
maintainers     ecronin openmaintainer
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           rmd160  d8f1cf3a03573be36787e87adc71beba3e678a37 \
                    sha256  6323afae6ad498d4369675f77ec3dbb680fe661bea586aa296e67f2e2daba4ff

livecheck.distname  LIRC

patchfiles          patch-osx_patches.diff

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

# Build fails with clang
# see bug report at: https://sourceforge.net/apps/mantisbt/lirc/view.php?id=1
compiler.blacklist-append *clang*

variant iguanaIR \
    description {Use IguanaIR USB device} {
    configure.args-replace    --with-driver=udp --with-driver=iguanaIR
    depends_lib-append        port:iguanaIR
    patchfiles-append         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"

notes "
After installing you must configure an IR device for lirc to use. Most\
hardware devices are not supported on Mac OS X (known exceptions: IguanaIR).\
Network sources (remote lircd, HD Homerun, etc) are fully supported.

Please edit ${prefix}/etc/LaunchDaemons/org.macports.${name}/${name}.wrapper\
and specify a valid driver or remote lircd to connect to. Examples for\
network, UDP, and IguanaIR are commented out.

Any clients of lirc must be able to read and write the pipe at\
${prefix}/var/run/lircd
"
