# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           meson 1.0

name                libsoup-2.4
set my_name         libsoup
version             2.74.3
revision            0

categories          gnome net
license             LGPL-2+
maintainers         {mascguy @mascguy} {devans @dbevans} openmaintainer

description         Soup is an HTTP library implementation in C.
long_description    Soup provides a queued asynchronous callback-based \
                    mechanism for sending and servicing SOAP requests \
                    and a WSDL (Web Service Definition Language) for C \
                    compilers which generates client stubs and server \
                    skeletons for easily calling and implementing SOAP \
                    methods.
homepage            https://wiki.gnome.org/Projects/libsoup

set branch          [join [lrange [split ${version} .] 0 1] .]
master_sites        gnome:sources/${my_name}/${branch}/
use_xz              yes
distname            ${my_name}-${version}
dist_subdir         ${my_name}

# Disable unexpected download of subprojects
meson.wrap_mode     nodownload

checksums           rmd160  51ff0fefd575dfbb65f9d303b7e2ccefa1703a1f \
                    sha256  e4b77c41cfc4c8c5a035fcdc320c7bc6cfb75ef7c5a034153df1413fa1d92f13 \
                    size    1504804

depends_build-append \
                    port:pkgconfig \
                    port:gtk-doc \
                    port:curl \
                    path:bin/vala:vala

depends_lib         port:brotli \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:glib-networking \
                    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                    port:kerberos5 \
                    port:libpsl \
                    port:libxml2 \
                    port:sqlite3 \
                    port:zlib

configure.args      -Dbrotli=enabled \
                    -Dgnome=false \
                    -Dgssapi=enabled \
                    -Dgtk_doc=true \
                    -Dintrospection=enabled \
                    -Dntlm=disabled \
                    -Dsysprof=disabled \
                    -Dvapi=enabled \
                    -Dtests=false

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

platform darwin 8 {
    # meson on Tiger cannot use rpaths, so we workaround with this to find dylib
    destroot.env-append    "DYLD_LIBRARY_PATH=${build_dir}/${my_name}"
}

variant gnome description {Enable GNOME support} {
    configure.args-replace -Dgnome=false -Dgnome=true
}

default_variants    +gnome

# This port provides legacy bindings, previously provided by 'libsoup'.
# So the latter must be deactivated first, if an older version is installed.
# This logic added 2023-05-06; keep in place for at least 12 months.
pre-activate {
    set port_conflict_name    libsoup
    set port_conflict_ver_max "2.74.2"

    if { ![catch {set port_conflict_ver_info [lindex [registry_active ${port_conflict_name}] 0]}] } {
        set port_conflict_ver [lindex ${port_conflict_ver_info} 1]
        ui_info "${port_conflict_name} active version: ${port_conflict_ver}"
                    
        if { [vercmp ${port_conflict_ver} ${port_conflict_ver_max}] <= 0 } {
            ui_info "Deactivating conflicting port: ${port_conflict_name}"
            registry_deactivate_composite ${port_conflict_name} "" [list ports_nodepcheck 1]
        }
    }
}

livecheck.type      gnome
livecheck.name      ${my_name}
# restrict livecheck to 2.* release branch
# new 3.* branch breaks API/ABI
livecheck.regex     LATEST-IS-(2\\.\\d*\[02468\](?:\\.\\d+)*)
