# $Id: Portfile 92095 2012-04-18 17:12:54Z jeremyhu@macports.org $

PortSystem          1.0

name                xinit
version             1.3.2
revision            3
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    1c287ac016d277f973652fa3707eef6db8353d5a \
                    rmd160  097cd409e829255c328d1d87d69fb8206482f5d5 \
                    sha256  a1867fdaa83f68750b12ba4305c3c62f5992d0f52cfeb98e96c27a8e690e0235

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

patchfiles \
	disable-launchagent.patch \
	0001-launchd-privileged_startx-Improved-error-resolution.patch \
	0002-launchd-Don-t-provide-the-LaunchAgent-on-Tiger.patch \
	0003-launchd-Provide-more-verbose-error-reporting-for-lau.patch \
	0004-launchd-Load-privileged_startx-properly-on-Tiger.patch \
	0005-launchd-Fix-the-destination-of-moved-aside-directori.patch

patch.pre_args -p1

use_autoreconf  yes
autoreconf.args -fvi
depends_build-append port:xorg-util-macros

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

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

post-destroot {
    xinstall -d ${destroot}${prefix}/lib/X11/xinit/xinitrc.d
    eval xinstall -m 755 [glob ${filespath}/xinitrc.d/*.sh] ${destroot}${prefix}/lib/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}/lib/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,"
            ui_msg "# load the LaunchAgent, logout, and log back in.  To load the LaunchAgent,"
            ui_msg "# please execute the following:"

            if { ${os.major} < 10 } {
                ui_msg "# sudo launchctl load -w /Library/LaunchAgents/org.macports.startx.plist"
                ui_msg "# "
                ui_msg "# This will be required after every upgrade of the xinit port on Leopard"
            } else {
                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."
            }

            # 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 "# "
                ui_msg "# Note that doing so on your OS version may make the Apple-provided version"
                ui_msg "# fail to launch."
            }

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

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

install.asroot      yes
