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

# Please keep the pango and pango-devel ports as similar as possible.
name                    pango-devel
conflicts               pango
set my_name             pango
epoch                   1
version                 1.57.1
revision                0
checksums               rmd160  6ffafe7c40f77f49ac1ff3f67f5f18ed6f48086c \
                        sha256  e65d6d117080dc3aeeb7d8b4b3b518f7383aa2e6cfce23117c623cd624764c2f \
                        size    2588416

set branch              [join [lrange [split ${version} .] 0 1] .]
categories              x11
maintainers             {ryandesign @ryandesign} {mascguy @mascguy} openmaintainer
license                 LGPL-2+
homepage                https://www.pango.org/
master_sites            gnome:sources/${my_name}/${branch}
distname                ${my_name}-${version}
dist_subdir             ${my_name}
use_xz                  yes

description             Framework for the layout and rendering of i18n text
long_description        The goal of the Pango project is to provide an \
                        open-source framework for the layout and rendering \
                        of internationalized text.

# Disable unexpected download of subprojects
meson.wrap_mode         nodownload

depends_build-append    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                        port:help2man \
                        path:bin/pkg-config:pkgconfig

depends_lib-append      path:lib/pkgconfig/cairo.pc:cairo \
                        port:fontconfig \
                        port:freetype \
                        port:fribidi \
                        path:lib/pkgconfig/glib-2.0.pc:glib2 \
                        path:lib/pkgconfig/harfbuzz.pc:harfbuzz

configure.args-append   -Dbuild-examples=false \
                        -Dbuild-testsuite=false \
                        -Dfontconfig=enabled \
                        -Dfreetype=enabled \
                        -Dintrospection=enabled \
                        -Dlibthai=disabled \
                        -Dxft=disabled

if { [string match *clang* ${configure.compiler}] } {
    configure.cflags-append \
                        -Wno-error,-Wimplicit-fallthrough \
                        -Wno-error,-Wmissing-declarations \
                        -Wno-error=unknown-warning-option \
                        -Wno-unknown-warning-option
}

compiler.c_standard     2011
compiler.cxx_standard   2011
compiler.blacklist-append {clang < 900}
configure.cxxflags-append \
                        -std=c++11

license_noconflict      gobject-introspection

# gobject-introspection uses g-ir-scanner, which uses $CC from env
if {${universal_possible} && [variant_isset universal]} {
    foreach arch ${configure.universal_archs} {
        lappend merger_build_env(${arch}) \
                        "CC=${configure.cc} -arch ${arch}"
        lappend merger_destroot_env(${arch}) \
                        "CC=${configure.cc} -arch ${arch}"
    }
} else {
    build.env-append    "CC=${configure.cc} ${configure.cc_archflags}"
    destroot.env-append "CC=${configure.cc} ${configure.cc_archflags}"
}

# Fix build errors on 10.5, caused by outdated 'nm'
# Issue: https://trac.macports.org/ticket/60253
if {${os.platform} eq "darwin" && ${os.major} == 9} {
    depends_build-append \
                        port:cctools
    configure.env-append \
                        NM=${prefix}/bin/nm
}

if {${os.platform} eq "darwin" && ${os.subplatform} eq "macosx"} {
    variant quartz {
        # Although this variant does nothing, pango will automatically build
        # itself differently depending on whether or not cairo is installed
        # with the quartz variant and whether CoreText is available. Therefore
        # this variant is necessary to be able to distinguish whether an
        # installed pango has Quartz support or not.
    }

    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

    if {[variant_isset quartz]} {
        require_active_variants path:lib/pkgconfig/cairo.pc:cairo quartz
    }
}

variant x11 {
    depends_lib-append  port:Xft2
    configure.args-replace \
                        -Dxft=disabled -Dxft=enabled
}

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

if {[variant_isset x11]} {
    require_active_variants path:lib/pkgconfig/cairo.pc:cairo x11
}

variant tests description {Enable test support} {
    configure.args-replace \
                        -Dbuild-testsuite=false \
                        -Dbuild-testsuite=true

    test.run            yes
    test.target         test
}

variant thai description {Enable line breaking on Thai language} {
    depends_lib-append  port:libthai
    configure.args-replace \
                        -Dlibthai=disabled \
                        -Dlibthai=enabled
}

pre-configure {
    delete ${worksrcpath}/subprojects/glib ${worksrcpath}/subprojects/glib.wrap
}

post-destroot {
    set docdir ${prefix}/share/doc/${my_name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} \
        CODING_STYLE.md COPYING NEWS README.md THANKS \
        ${destroot}${docdir}
}

livecheck.type          gnome-with-unstable
livecheck.name          ${my_name}
