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

name            xorg-server-1.18
conflicts       xorg-server-legacy xorg-server xorg-server-devel
version         1.18.4
revision        0
categories      x11 devel
license         X11
maintainers     nomaintainer
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.

master_sites    https://xorg.freedesktop.org/archive/individual/xserver/
#master_sites    xorg:individual/xserver/

distname        xorg-server-${version}

checksums       rmd160  6f58d84d3bbc59a773e6a2e1eafc208827a5923f \
                sha256  278459b2c31d61a15655d95a72fb79930c480a6bb8cf9226e48a07df8b1d31c8 \
                size    6009508

use_bzip2       yes
use_parallel_build yes

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

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

# 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

# GL/internal/dri_interface.h is missing in prefix (provided by libdrm for the xorg DDX... not helpful for us)
configure.cppflags-append -I/usr/include -I${filespath}/dri -F${configure.sdkroot}/System/Library/Frameworks/ApplicationServices.framework/Frameworks

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

patchfiles \
        0001-XQuartz-Fix-the-issue-where-the-h-key-could-be-come-.patch \
        0002-XQuartz-Cleanup-CPPFLAGS-that-are-no-longer-necessar.patch \
        0003-os-connection-Improve-abstraction-for-launchd-secure.patch \
        1001-XQuartz-Hack-around-an-issue-that-can-occur-on-macOS.patch \
        5000-sdksyms.sh-Use-CPPFLAGS-not-CFLAGS.patch \
        5001-Revert-dix-Restore-PaintWindow-screen-hook.patch \
        5002-Workaround-the-GC-clipping-problem-in-miPaintWindow-.patch \
        5003-Use-old-miTrapezoids-and-miTriangles-routines.patch \
        5004-fb-Revert-fb-changes-that-broke-XQuartz.patch \
        5005-fb-Revert-fb-changes-that-broke-XQuartz.patch

# 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

if { ${os.major} >= 19 } {
    # remove this line
    #    _appFlags._active = YES;
    # as _appFlags is no longer available in Darwin19 and newer
    patchfiles-append remove-appflags-active-hack.diff
}

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-util-macros \
        port:xorg-font-util

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
        }
}

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
