# -*- 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
PortGroup               github 1.0
PortGroup               makefile 1.0
PortGroup               xcodeversion 1.0

minimum_xcodeversions   {19 12.0}

github.setup            cmacrae spacebar 1.4.0 v
github.tarball_from     archive

categories              sysutils
maintainers             {@bashu gmail.com:bashu.was.here} openmaintainer
license                 MIT
description             A minimal status bar for macOS.
long_description        spacebar is a minimal status bar for macOS. \
                        Ideal for use with tiling window managers like yabai.

checksums               rmd160  0ecfd10f589154dfaa99a3b05154cc7a926fae55 \
                        sha256  80165fb20e2b6436cabb972f3bac1ccf25cc174edff78e47be5aaac9c9733f05 \
                        size    44938

patchfiles              patch-makefile.diff patch-src__event_loop.c.diff

post-extract {
    file copy ${filespath}/org.macports.${name}.plist ${worksrcpath}/org.macports.${name}.plist
}

post-patch {
    reinplace "s|@NAME@|${name}|g" ${worksrcpath}/org.macports.${name}.plist
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/org.macports.${name}.plist
}

post-destroot {
    # Copy manpage
    xinstall -m 0644 ${worksrcpath}/doc/spacebar.1 ${destroot}${prefix}/share/man/man1

    # Copy example files
    xinstall -m 0755 -d ${destroot}${prefix}/share/doc/${name}/examples
    copy {*}[glob ${worksrcpath}/examples/*] \
        ${destroot}${prefix}/share/doc/${name}/examples

    set launchd_dir ${prefix}/etc/${startupitem.location}/${startupitem.uniquename}/
    xinstall -m 0755 -d ${destroot}/${launchd_dir}
    xinstall -m 0644 ${worksrcpath}/${startupitem.plist} ${destroot}${launchd_dir}

    # install the plist, if startupitem.install is set
    if {[getuid] == 0  && ${startupitem.install}} {
        xinstall -m 0755 -d ${destroot}/Library/${startupitem.location}
        ln -sf ${launchd_dir}${startupitem.plist} ${destroot}/Library/${startupitem.location}
    } else {
        ln -sf ${launchd_dir}/${startupitem.plist} ${destroot}${prefix}/etc/${startupitem.location}
    }
}

notes "
Copy the example configuration into your home directory:

     cp ${prefix}/share/doc/${name}/examples/spacebarrc ~/.spacebarrc
"

startupitem.create      no
startupitem.autostart   no
startupitem.location    LaunchAgents
startupitem.executable  ${prefix}/bin/spacebar
