# -*- 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       meson 1.0

# This is the XQuartz fork's xorg-server 21.1.24, a superset of the
# commit shipped in XQuartz 2.8.6
github.setup    XQuartz xorg-server c0fb33e194c9430352c8c8eec7cd5609721103e9
github.tarball_from archive

name            xorg-server
conflicts       xorg-server-legacy xorg-server-devel xorg-server-1.18
version         21.1.24
categories      x11 devel
license         X11
maintainers     {jeremyhu @jeremyhu} openmaintainer
description     The X.org / Xquartz X server.
homepage        https://www.x.org
platforms       darwin macosx
long_description The X.org X server allows you to run X11 applications on your computer.

checksums       rmd160  fca793a79f312be75923721f1f92b7dd19c6c9e9 \
                sha256  f9e5dcdc0ff52cb159c8fa97d2de8def9e5505a84552f41136cb77dd9855033c \
                size    5445200

# Yes, mesa is a *BUILD* dependency (GL headers and gl.pc for GLX)
depends_build-append \
        port:pkgconfig \
        port:mesa \
        port:xorg-font-util \
        port:xorg-xorgproto \
        port:xorg-xtrans

# This xinit dependency needs to be port: not bin: because we specifically run ${prefix}/bin/startx from bundle-main.c
depends_run-append \
        port:xinit \
        port:quartz-wm \
        port:xorg-fonts \
        port:xkeyboard-config

depends_lib-append \
        path:lib/pkgconfig/pixman-1.pc:libpixman \
        port:xorg-libX11 \
        port:xorg-libXau \
        port:xorg-libXdmcp \
        port:xorg-libAppleWM \
        port:xorg-libXext \
        port:xorg-libXfixes \
        port:xorg-libXfont2 \
        port:xorg-libxkbfile \
        port:xorg-libxshmfence

# The chown-bundle.sh install script ignores DESTDIR, so it fails in destroot.
# MacPorts sets ownership at activation time anyway.
post-patch {
    reinplace "/chown-bundle/d" ${worksrcpath}/hw/xquartz/bundle/meson.build
}

# https://trac.macports.org/ticket/36055
# https://llvm.org/bugs/show_bug.cgi?id=30346
# https://trac.macports.org/ticket/53910
compiler.blacklist gcc-4.0 macports-clang-devel {clang >= 802 < 900}

configure.args  -Dapple-applications-dir=${applications_dir} \
                -Dbundle-id-prefix=org.macports \
                -Dsha1=CommonCrypto \
                -Ddtrace=false \
                -Dsecure-rpc=false \
                -Dxquartz=true \
                -Dxvfb=true \
                -Dxnest=true \
                -Dxorg=false \
                -Dxephyr=false \
                -Dxwin=false \
                -Dglamor=false \
                -Ddri1=false \
                -Ddri2=false \
                -Ddri3=false \
                -Ddocs=false \
                -Ddevel-docs=false

post-destroot {
        ln -s Xquartz ${destroot}${prefix}/bin/X
}

platform macosx {
    if {${os.major} < 15} {
        known_fail  yes
        pre-fetch {
            ui_error "$name requires macOS 10.11 or later. Please use the xorg-server-legacy port instead."
            error "unsupported OS version"
        }
    }
}

variant xcsecurity description "Enable Security Extensions" {
    configure.args-append  -Dxcsecurity=true
}

livecheck.type none
