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

github.setup    XQuartz xorg-server c5d80026d246cbe2df785e77558ffeafe6850927
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball

name            xorg-server-devel
conflicts       xorg-server-legacy xorg-server xorg-server-1.18
version         1.20.99.1
revision        1
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  61b06168c2ae0c14c0c6a289a7069beb8846302b \
                    sha256  f6ffa03d36f2d861e9d9039edd60a2c5d08ab5537278bbce95e727f2b773a2f0 \
                    size    5844257

use_parallel_build yes

# Yes, mesa is a *BUILD* dependency
depends_build-append \
        port:pkgconfig \
        port:mesa \
        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-libxkbfile \
        port:xorg-libXfont \
        port:xorg-libXt \
        port:xorg-libAppleWM \
        port:xorg-libXfixes \
        port:xorg-libXfont2

# 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 --with-apple-applications-dir=${applications_dir} \
        --with-bundle-id-prefix=org.macports \
        --without-dtrace \
        --without-doxygen \
        --without-fop \
        --without-xmlto \
        --disable-devel-docs \
        --with-sha1=CommonCrypto \
        --disable-dri2 \
        --disable-dri3

# Debugging ...
#configure.cppflags-append  -g -fsanitize=address -fno-omit-frame-pointer
#configure.cflags-append    -g -fsanitize=address -fno-omit-frame-pointer
#configure.cppflags-replace -Os -O1
#configure.cflags-replace   -Os -O1

configure.env-append \
        RAWCPP=${configure.cpp}

# the following patch avoids redefinition errors on pre-C11 compilers
# https://trac.macports.org/ticket/57333
# another approach would be to update the port to build with gcc6+
patchfiles-append \
        5006-patch-xorg-server-dont-redefine-GLXscreen.diff

# enables the automake option "subdir-objects" so that automake
# doesn't complain about subdirectory *.in replacement files usage.
patchfiles-append 2001-enable-automake-subdir-objects.patch

patch.pre_args-replace  -p0 -p1

use_autoreconf yes
autoreconf.args -fvi

build.args V=1

depends_build-append \
        port:xorg-util-macros \
        port:xorg-font-util

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

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

variant xcsecurity description "Enable Security Extensions" {
    configure.args-append  --enable-xcsecurity
}

variant docs description "Install extra documentation" {
        depends_build-append \
                path:bin/doxygen:doxygen \
                port:fop \
                port:xmlto \
                port:xorg-sgml-doctools

        depends_skip_archcheck-append \
                doxygen \
                xmlto

        configure.args-delete \
                --without-doxygen \
                --without-fop \
                --without-xmlto \
                --disable-devel-docs

        configure.args-append \
                --with-doxygen \
                --with-fop \
                --with-xmlto \
                --enable-devel-docs

        configure.env-append \
                DOXYGEN=${prefix}/bin/doxygen \
                FOP=${prefix}/bin/fop \
                XMLTO=${prefix}/bin/xmlto
}

livecheck.type none
