# -*- 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       compiler_blacklist_versions 1.0
PortGroup       github 1.0
PortGroup       legacysupport 1.1

# for strnlen, at least
legacysupport.newest_darwin_requires_legacy 10

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

name            xorg-server-legacy
conflicts       xorg-server-1.18 xorg-server xorg-server-devel
version         1.20.10
revision        3
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  1ae5d1a6f73315c35b2e7469f22b4c6d1d01d191 \
                sha256  19f2ef049f40629de2dde3825340760a944ca852fa2983f7a3c5bdbddc63fe29 \
                size    5843887

# Yes, mesa is a *BUILD* dependency
depends_build-append \
        port:mesa \
        path:bin/pkg-config:pkgconfig \
        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:quartz-wm \
        port:xinit \
        port:xkeyboard-config \
        port:xorg-fonts

depends_lib-append \
        path:lib/pkgconfig/pixman-1.pc:libpixman \
        port:xorg-libAppleWM \
        port:xorg-libXfixes \
        port:xorg-libXfont \
        port:xorg-libXfont2 \
        port:xorg-libxkbfile \
        port:xorg-libxshmfence \
        port:xorg-libXt

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

# 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

platform darwin 8 {
    configure.args-append \
        --disable-dependency-tracking
}

use_autoreconf yes
autoreconf.args -fvi

build.args V=1

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

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

platform macosx {
    if { ${os.major} < 10 } {
        # Xplugin.h is missing on Tiger and incorrect on Leopard
        configure.cppflags-append -I${filespath}/include
    }

    if {${os.major} >= 15} {
        known_fail yes
        pre-fetch {
            ui_error "$name is intended for OS X 10.4 through 10.10 and has known issues running on macOS 10.15 and later."
            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 \
                --disable-devel-docs \
                --without-doxygen \
                --without-fop \
                --without-xmlto

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

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

livecheck.type none