# -*- 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                   debug 1.0
PortGroup                   legacysupport 1.1
PortGroup                   muniversal 1.0
PortGroup                   xcodeversion 1.0

# memmem
# https://gitlab.freedesktop.org/cairo/cairo/-/issues/635
legacysupport.newest_darwin_requires_legacy 10

# Please keep the cairo and cairo-devel ports as similar as possible.

set my_name                 cairo
name                        ${my_name}
conflicts                   ${my_name}-devel
version                     1.18.4
revision                    1
# Due to reverting https://github.com/macports/macports-ports/commit/2841d90a120874130a357d2e371d962c8564d5a5
epoch                       1
categories                  graphics
platforms                   darwin macosx
maintainers                 {ryandesign @ryandesign} {mascguy @mascguy}
license                     {LGPL-2.1 MPL-1.1}
description                 vector graphics library with cross-device output support
long_description            Cairo is a ${description}. It is designed to produce \
                            identical output on all output media while taking \
                            advantage of display hardware acceleration when \
                            available (e.g. through the X Render Extension).
homepage                    https://www.cairographics.org
master_sites                ${homepage}/releases/ \
                            https://gitlab.freedesktop.org/cairo/cairo/-/archive/${version}/
dist_subdir                 ${my_name}
distname                    ${my_name}-${version}
use_xz                      yes
checksums                   rmd160  757415ba8e1b5df92474644c887865a5ade9fd93 \
                            sha256  445ed8208a6e4823de1226a74ca319d3600e83f6369f99b14265006599c32ccb \
                            size    32578804

depends_build               path:bin/pkg-config:pkgconfig

depends_lib                 port:expat \
                            path:lib/pkgconfig/fontconfig.pc:fontconfig \
                            path:lib/pkgconfig/freetype2.pc:freetype \
                            path:lib/pkgconfig/glib-2.0.pc:glib2 \
                            path:lib/pkgconfig/pixman-1.pc:libpixman \
                            port:libpng \
                            port:lzo2 \
                            port:zlib

minimum_xcodeversions       {8 2.4.1}

patch.pre_args-replace      -p0 -p1

# Restore autotools, since meson build is broken: https://gitlab.freedesktop.org/cairo/cairo/-/work_items/948
# Prevent cairo from using librsvg, libspectre, poppler.
patchfiles-append           cairo-${version}-autotools.patch
# cairo-quartz-surface.c:1944:5: error: implicit declaration of function 'CTFontDrawGlyphs'
patchfiles-append           cairo-ctfontdrawglyphs-fallback.patch

post-patch {
    system "touch ${worksrcpath}/boilerplate/Makefile.am.features"
}

if {![info exists universal_possible]} {
    set universal_possible [expr {${os.universal_supported} && [llength ${configure.universal_archs}] >= 2}]
}

use_autoreconf              yes

configure.args              --disable-quartz \
                            --disable-quartz-font \
                            --disable-quartz-image \
                            --disable-silent-rules \
                            --disable-svg \
                            --disable-symbol-lookup \
                            --disable-xcb \
                            --disable-xcb-shm \
                            --disable-xlib \
                            --disable-xlib-xcb \
                            --enable-ft \
                            --enable-pdf \
                            --enable-png \
                            --enable-ps \
                            --enable-script \
                            --enable-tee \
                            --without-x

# Prevent cairo from using ghostscript.
configure.args-append       ac_cv_prog_GS=""

compiler.c_standard         2011
compiler.cxx_standard       2011

platform macosx {
    variant quartz {
        configure.args-replace  --disable-quartz --enable-quartz \
                                --disable-quartz-font --enable-quartz-font \
                                --disable-quartz-image --enable-quartz-image
    }

    default_variants        +quartz
    # Don't allow Quartz support to be disabled. Keep the variant for awhile in
    # case any dependents are using the active_variants portgroup to check for it.
    variant_set             quartz
}

variant x11 {
    depends_lib-append      port:xrender \
                            port:xorg-libXext \
                            port:xorg-xcb-util

    configure.args-replace  --disable-xcb --enable-xcb \
                            --disable-xlib --enable-xlib \
                            --disable-xlib-xcb --enable-xlib-xcb \
                            --without-x --with-x
    configure.args-append   --enable-xlib-xrender \
                            --x-include=${prefix}/include \
                            --x-lib=${prefix}/lib
}

default_variants            +x11
if {${os.platform} ne "darwin" || ${os.subplatform} ne "macosx"} {
    # When not on macOS, don't allow X11 support to be disabled, since it is the
    # only available option.
    variant_set             x11
}

test.run                    yes
test.target                 check

livecheck.type              regex
livecheck.url               ${homepage}/news/
livecheck.regex             ${my_name}-(\[0-9\]+\\.\[0-9\]*\[02468\]\\.\[0-9\]+)
