# -*- 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                xinit
version             1.4.1
revision            1
categories          x11
platforms           darwin
maintainers         {jeremyhu @jeremyhu} openmaintainer
license             MIT
description         X11 startup script processor
long_description    xinit is responsible for configuring the initial environment \
                    when X11 starts up.

homepage            https://www.x.org
master_sites        xorg:individual/app/

checksums           rmd160  e393a9a41f9582b955a7f174f3b1b10ece0fa92b \
                    sha256  de9b8f617b68a70f6caf87da01fcf0ebd2b75690cdcba9c921d0ef54fa54abb9 \
                    size    176206

use_bzip2           yes
use_parallel_build  yes

depends_run         bin:xauth:xauth \
                    bin:xset:xset \
                    bin:xrdb:xrdb \
                    port:mkfontscale

depends_build       port:pkgconfig \
                    port:xorg-util-macros \
                    port:tradcpp

depends_lib         port:xorg-libX11

if {[vercmp ${os.version} 10.3.0] < 0} {
    patchfiles-append disable-launchagent.patch
}

# libdispatch is unsupported on powerpc, despite possibly present headers (ex. Rosetta).
# Run the test on non-powerpc systems only.
patchfiles-append   patch-no-libdispatch-ppc.diff

patch.pre_args-replace  -p0 -p1

use_autoreconf  yes
autoreconf.args -fvi

configure.args      --disable-silent-rules \
                    --with-launchd-id-prefix=org.macports

configure.args-append   RAWCPP=${prefix}/bin/tradcpp

post-destroot {
    xinstall -d ${destroot}${prefix}/etc/X11/xinit/xinitrc.d
    xinstall -m 755 {*}[glob ${filespath}/xinitrc.d/*.sh] ${destroot}${prefix}/etc/X11/xinit/xinitrc.d
    xinstall -m 755 ${filespath}/font_cache.sh ${destroot}${prefix}/bin/font_cache

    reinplace "s|__PREFIX__|${prefix}|g" \
        {*}[glob ${destroot}${prefix}/etc/X11/xinit/xinitrc.d/*.sh] \
        ${destroot}${prefix}/bin/font_cache
}

platform darwin {
    if {${os.major} > 9} {
        # OS X 10.6.3 was the first version whose native X11 allowed the modern socket naming
        # for better X11 server coexistence, so we require it for installing the LaunchAgent
        if {[vercmp ${os.version} 10.3.0] < 0} {
            notes {
                To use MacPorts' X11 as the default server, install\
                xorg-server, load the LaunchAgent with the following\
                command, log out, and log back in.

                    $ launchctl load -w /Library/LaunchAgents/org.macports.startx.plist

                This will be remembered across port updates on Snow\
                Leopard and later. Note that doing this may cause the\
                Apple-provided X11 to fail to launch.}
        } else {
            notes {
                To use MacPorts' X11 as the default server, install\
                xorg-server, log out, and log back in.}
        }
    }

    post-activate {
        system "launchctl load /Library/LaunchDaemons/org.macports.privileged_startx.plist"
    }

    pre-deactivate {
        system "launchctl unload /Library/LaunchDaemons/org.macports.privileged_startx.plist"
    }
}

install.asroot      yes

livecheck.type      regex
livecheck.regex     ${name}-(\[\\d.\]+)${extract.suffix}
livecheck.url       https://xorg.freedesktop.org/archive/individual/app/?C=M&O=D