PortSystem          1.0

name                lirc
version             0.9.4d
revision            4
categories          sysutils net
license             {GPL-2+ OpenSSLException}
maintainers         {ctreleaven @ctreleaven} openmaintainer
platforms           darwin
description         Linux Infrared Remote Control
long_description \
    LIRC enables receiving and/or sending infra-red remote controls signals.\
    The only hardware is known to work (on the Mac operating system) includes the\
    IR receiver in older HDHomerun tuner boxes and the Sony Vaio PCVA-IR5U receiver.\
    Other hardware _could_ work but is untested.  Lirc does not currently work with\
    the IR receiver built into various Mac models.\
    Lirc on OSX can also receive signals relayed from another Lirc server.

homepage            http://www.lirc.org
master_sites        sourceforge
#use_bzip2           yes
checksums           rmd160  998a726823a90ad79bde50fce3bd0417c950ab59 \
                    sha256  e225c8a6ed004ee0b3180d9bc8d8129dbc2b9ac3e0daccc2ca5e61ca16aae8d3

livecheck.distname  LIRC

set lircuser        _lirc
set pythonbranch    3.6
set pythonver       python${pythonbranch}
set pythonbin       ${prefix}/bin/${pythonver}
set pymodver        py36

compiler.cxx_standard 2011

use_autoreconf      yes
autoreconf.cmd      ./autogen.sh
# setting autoreconf.cmd means that autotools build dependencies are not added

depends_build-append \
                    port:autoconf \
                    port:automake \
                    port:gsed \
                    port:libtool \
                    port:pkgconfig \
                    port:doxygen \
                    port:man \
                    port:${pymodver}-yaml

depends_lib         port:libusb \
                    port:libusb-compat \
                    port:libftdi1 \
                    port:portaudio

patchfiles          patch-commandir_support.diff

if {${os.platform} eq "darwin" && ${os.major} < 12} {
    # https://trac.macports.org/ticket/53314
    patchfiles-append   old-scandir.diff
}
if {${os.platform} eq "darwin" && ${os.major} < 11} {
    # https://trac.macports.org/ticket/58950
    patchfiles-append   patch-nodocs-snowleopard.diff
}

post-patch {
    reinplace -locale C "s|@PREFIX@|${prefix}|g" ${worksrcpath}/lirc_options.conf
    reinplace -locale C "s|#!/usr/bin/env python3\$|#!${pythonbin}|" \
        ${worksrcpath}/doc/data2hwdb \
        ${worksrcpath}/doc/data2table \
        ${worksrcpath}/doc/make_rel_symlink.py \
        ${worksrcpath}/tools/check_configs.py \
        ${worksrcpath}/tools/irdb-get \
        ${worksrcpath}/tools/lirc-setup/lirc-setup \
        ${worksrcpath}/tools/lircd-setup \
        ${worksrcpath}/tools/make_rel_symlink.py \
        ${worksrcpath}/tools/pronto2lirc
}

configure.env-append \
                    PYTHON=${pythonbin}

# consider variant for X programs (irxevent xmode2)
configure.args      --without-x --disable-silent-rules

post-destroot {
    xinstall -m 777 -d ${destroot}${prefix}/var/log/${name}
    xinstall -m 777 -d ${destroot}${prefix}/var/run/${name}
    destroot.keepdirs ${destroot}${prefix}/var/log/${name} \
        ${destroot}${prefix}/var/run/${name}
    move ${destroot}${prefix}/etc/lirc/lirc_options.conf \
        ${destroot}${prefix}/etc/lirc/lirc_options.conf.template
    if {![variant_isset gui]} {
        delete ${destroot}${prefix}/bin/lirc-setup
        delete ${destroot}${prefix}/lib/python3.4
    }
}

post-activate {
    if {![file exists ${prefix}/etc/lirc/lirc_options.conf]} {
        copy ${prefix}/etc/lirc/lirc_options.conf.template \
            ${prefix}/etc/lirc/lirc_options.conf
    }
}

variant gui description { include experimental gui tools } {
    depends_run-append  port:gtk3 \
                        port:${pymodver}-gobject3 \
                        port:${pymodver}-yaml \
                        port:vte
    configure.args-replace --without-x --with-x
}

add_users ${lircuser} group=${lircuser} realname=LIRC\ user

startupitem.create        yes
startupitem.executable    ${prefix}/sbin/lircd \
                          --nodaemon --logfile=${prefix}/var/log/${name}/lircd.log \
                          --effective-user=${lircuser}

notes "
Before starting the lircd background process, two configuration steps need to be\
completed.  First, edit ${prefix}/etc/lirc/lirc_options.conf to specify the driver\
and device being used.  Second, add at least one remote configuration file to\
${prefix}/etc/lirc/lircd.conf.d so lirc can interpret the infrared pulses that your remote\
sends.  The script irdb-get can help find existing remote configuration files or the\
program irrecord can help create a configuration file for a particular remote.

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