# $Id: Portfile 111368 2013-09-19 16:30:29Z jeremyhu@macports.org $

PortSystem          1.0

name                xinit
version             1.3.3
revision            1
categories          x11
platforms           darwin
maintainers         jeremyhu openmaintainer
license             MIT
description         X11 startup script processor
long_description    xinit is responsible for configuring the initial environment \
		    when X11 starts up.

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

checksums           sha1    c3c01c8c6012317f995669894d9e7b2838b61e58 \
                    rmd160  3514c083aad625a2b331eb704114fc2c392c6441 \
                    sha256  74b2878de6e3d5b5948f1562a77e7f53b4e10621e505ddb278050c7f3cae00af

use_bzip2	    yes
use_parallel_build  yes

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

depends_build       port:pkgconfig

depends_lib         port:xorg-libX11

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

patch.pre_args -p1

configure.args --with-launchd-id-prefix=org.macports

configure.args-append   RAWCPP=${configure.cpp}

post-destroot {
    xinstall -d ${destroot}${prefix}/etc/X11/xinit/xinitrc.d
    eval 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

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

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

        if {${os.major} > 9} {
            ui_msg "###############################################################################"
            ui_msg "# To choose MacPorts' X11 as the default server, you must install xorg-server,"

            # 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} {
                ui_msg "# load the LaunchAgent, logout, and log back in.  To load the LaunchAgent,"
                ui_msg "# please execute the following:"
                ui_msg "# "
                ui_msg "# launchctl load -w /Library/LaunchAgents/org.macports.startx.plist"
                ui_msg "# "
                ui_msg "# This will be remembered across port updates on Snow Leopard and later."
                ui_msg "# "
                ui_msg "# Note that doing so on your OS version may make the Apple-provided version"
                ui_msg "# fail to launch."
            } else {
                ui_msg "# logout, and log back in."
            }

            ui_msg "###############################################################################"
        }
    }

    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       http://xorg.freedesktop.org/archive/individual/app/?C=M&O=D

