# -*- 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

PortSystem              1.0

name                    sleepwatcher
version                 2.2.1
revision                0
checksums               rmd160  d42350573650e6424d1ce9e2ad0c139f346c451e \
                        sha256  4bf1656702167871141fbc119a844d1363d89994e1a67027f0e773023ae9643e \
                        size    42659

categories              sysutils
platforms               macosx
maintainers             {ryandesign @ryandesign} openmaintainer
license                 GPL-3+
homepage                https://www.bernhard-baehr.de
master_sites            ${homepage}
distname                ${name}_${version}
extract.suffix          .tgz

description             monitors sleep, wakeup and idleness of a Mac

long_description        SleepWatcher monitors sleep, wakeup and idleness of \
                        a Mac. It can be used to execute a Unix command \
                        when the Mac or the display of the Mac goes to sleep \
                        mode or wakes up or after a given time without user \
                        interaction. It also can send the Mac to sleep mode \
                        or retrieve the time since last user activity.

if {${os.major} < 9} {
    known_fail          yes
    pre-fetch {
        ui_error "${name} ${version} requires Mac OS X 10.5 or greater."
        return -code error "incompatible Mac OS X version"
    }
}

patchfiles              Makefile.patch

use_configure           no

variant universal {}

build.dir               ${worksrcpath}/sources
build.target            ${name}
build.args              CC=${configure.cc} \
                        CFLAGS="${configure.cflags} [get_canonical_archflags cc]"

destroot.args           BINDIR=${destroot}${prefix}/sbin \
                        MANDIR=${destroot}${prefix}/share/man

post-destroot {
    xinstall -m 0755 -W ${worksrcpath}/config rc.sleep rc.wakeup ${destroot}${prefix}/etc
    set docdir ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${docdir}
    xinstall -m 0644 -W ${worksrcpath} ReadMe.rtf ${docdir}
}

startupitem.create      yes
startupitem.executable  ${prefix}/sbin/sleepwatcher \
                        --verbose \
                        --sleep ${prefix}/etc/rc.sleep \
                        --wakeup ${prefix}/etc/rc.wakeup

livecheck.type          regex
livecheck.regex         (?i)>${name} (\[0-9.\]+)<

notes "\
The included system-wide launchd plist starts a ${name} daemon which calls\
the scripts \".sleep\" and \".wakeup\" in your home directory when the\
computer goes to sleep and wakes up, respectively.\
For more control, and to be able to respond to display sleep, idle, and\
power manager events, ignore the system-wide launchd plist and write your\
own user-specific plist.\
Consult the manpage for the full range of possibilities.\
"
