# -*- 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.
# Note: Stable Pango releases have an even-numbered minor version.

name                    pango-devel
conflicts               pango
set my_name             pango
epoch                   1
version                 1.55.0
revision                0
checksums               rmd160  e1a860f279fb352f41b95c7987e4cab678906945 \
                        sha256  a2c17a8dc459a7267b8b167bb149d23ff473b6ff9d5972bee047807ee2220ccf \
                        size    2098352

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.cxx_standard   2011
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 help2man invocation on Tiger
platform darwin 8 {
    # meson on Tiger cannot use rpaths, so we workaround with this to find dylib
    build.env-append    "DYLD_LIBRARY_PATH=${build_dir}/pango"
}

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

if {${os.platform} eq "darwin" && ${os.subplatform} eq "macosx" && ${os.major} > 8} {
    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
}

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}
