# $Id: Portfile 57375 2009-09-10 08:16:41Z ryandesign@macports.org $

PortSystem 1.0

name        XFree86
version     4.7.0
categories  x11
maintainers nomaintainer
homepage    http://www.xfree86.org/

description X11R6 windowing system
long_description \
    The XFree86 project's X window system implementation

platforms       darwin freebsd
master_sites    xfree:${version}/source/

distfiles \
    ${distname}-src-1.tgz \
    ${distname}-src-2.tgz \
    ${distname}-src-3.tgz \
    ${distname}-src-4.tgz \
    ${distname}-src-5.tgz
checksums \
    ${distname}-src-1.tgz md5 e452e53240d16091abdc4f4bd2967ebd \
    ${distname}-src-2.tgz md5 db68bab296cff797c1ae399f683905f2 \
    ${distname}-src-3.tgz md5 4787c740ee8ae61a294f488606ced230 \
    ${distname}-src-4.tgz md5 e622168021c7e8ca60928fbb9febdae5 \
    ${distname}-src-5.tgz md5 05a3f3ce703df2fd24112cb8e9d86f73

patchfiles      patch-freetype.h \
                patch-glxcmds.c \
                patch-Xtranssock.c.diff \
                patch-decompress.c.diff
post-patch {
    set hostfd [open "${worksrcpath}/config/cf/host.def" a+]
    puts $hostfd "#define ProjectRoot               ${prefix}"
    puts $hostfd "#define NothingOutsideProjectRoot YES"
    puts $hostfd "#define EtcX11Directory           \"${prefix}/etc/X11\""
    puts $hostfd "#define StandardIncludes          \"-I${workpath}/include\""
    puts $hostfd "#define FontconfigFontsConfDir    \"${prefix}/etc/fonts\""
    close $hostfd
}

prefix                  /usr/X11R6
worksrcdir              xc

use_configure           no

build.target            World
destroot.target         install install.man
destroot.violate_mtree  yes

platform darwin {

    patchfiles-append \
        patch-XTerm.ad
    post-patch {
        file mkdir "${workpath}/include"
        file link -symbolic "${workpath}/include/security" "/usr/include/pam"
    }
}


platform puredarwin {

    post-patch {
        set hostfd [open "${worksrcpath}/config/cf/host.def" a+]
        puts $hostfd "#define DarwinQuartzSupport NO"
        puts $hostfd "#define BuildGlxExt         YES"
        puts $hostfd "#define BuildGLXLibrary     YES"
        close $hostfd
    }
}

platform macosx {

    # Should also check for cookie crumbs in the keyboard
    pre-fetch {
        if { [file exists ${prefix}/bin/Xquartz] } {
            if { ![file exists ${prefix}/include/X11/X.h] } {
                return -code error "

                    You have an Apple X11 installation already.
                        MacPorts will not overwrite it.

                    If you wish to use Apple X11,
                        install the X11SDK included with Xcode tools.

                    If you really want to use XFree86 instead,
                        please move it aside first :

                            sudo mv $prefix ${prefix}.apple
                "
            } else {
                return -code error "

                    You have an Apple X11 installation already.
                        MacPorts will not overwrite it.

                    If you really want to use XFree86 instead,
                        please move it aside first :

                            sudo mv $prefix ${prefix}.apple
                "
            }
        } elseif { [file exists ${prefix}/include/X11/X.h] } {
            return -code error "

                    You have an Apple X11SDK installation already.
                        MacPorts will not overwrite it.

                    If you wish to use Apple X11,
                        install it from your Mac OS X install disc.

                    If you really want to use XFree86 instead,
                        please move it aside first :

                            sudo mv $prefix ${prefix}.apple
            "
        }
    }

     post-destroot {
        xinstall -d ${destroot}/Applications/MacPorts
        ln -s ${prefix}/bin/XDarwin.app ${destroot}/Applications/MacPorts
    }
}

# No attempt has yet been made to allow XFree86 to build universal. Feel free
# to attempt. The default universal variant is merely being disabled here
# because it does not function with ports that do not use configure, and
# leaving it enabled prevents the universal installation of any other ports
# that depend on XFree86, even if they would otherwise succeed. See #12137.
universal_variant   no
# Disable livecheck
livecheck.type  none
