# -*- 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                libpeas1
set my_name         libpeas
version             1.36.0
revision            0
license             LGPL-2
set branch          [join [lrange [split ${version} .] 0 1] .]
description         libpeas is a GObject-based plugins engine
long_description    ${description}
maintainers         {devans @dbevans} openmaintainer
categories          gnome
homepage            https://wiki.gnome.org/Projects/Libpeas
master_sites        gnome:sources/${my_name}/${branch}/

distname            ${my_name}-${version}

use_xz              yes

checksums           rmd160  6df6c0dd387d0d57d910f8235f3ad5f778536600 \
                    sha256  297cb9c2cccd8e8617623d1a3e8415b4530b8e5a893e3527bbfd1edd13237b4c \
                    size    195432

depends_build-append \
                    port:pkgconfig \
                    port:gettext \
                    path:bin/vala:vala

depends_lib         port:gettext-runtime \
                    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3

configure.args      -Dglade_catalog=false \
                    -Dlua51=false \
                    -Dpython2=false \
                    -Dpython3=false \
                    -Dvapi=true

# Work around lack of @rpath on Tiger, i.e. this error:
# dyld: Library not loaded: @loader_path/libpeas-1.0.0.dylib
platform darwin 8 {
    destroot.env-append "DYLD_LIBRARY_PATH=${build_dir}/${my_name}:${build_dir}/${my_name}-gtk"
}

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

variant glade description {Enable glade catalog support} {
    depends_lib-append      port:glade
    configure.args-replace  -Dglade_catalog=false -Dglade_catalog=true
}

variant python38 conflicts python39 python310 description {Enable Python 3.8 plugin support} {
    depends_lib-append          port:py38-gobject3
    set python_prefix           ${frameworks_dir}/Python.framework/Versions/3.8
    configure.pkg_config_path-append   ${python_prefix}/lib/pkgconfig
    configure.args-replace      -Dpython3=false -Dpython3=true
}

variant python39 conflicts python38 python310 description {Enable Python 3.9 plugin support} {
    depends_lib-append          port:py39-gobject3
    set python_prefix           ${frameworks_dir}/Python.framework/Versions/3.9
    configure.pkg_config_path-append   ${python_prefix}/lib/pkgconfig
    configure.args-replace      -Dpython3=false -Dpython3=true
}

variant python310 conflicts python38 python39 description {Enable Python 3.10 plugin support} {
    depends_lib-append          port:py310-gobject3
    set python_prefix           ${frameworks_dir}/Python.framework/Versions/3.10
    configure.pkg_config_path-append   ${python_prefix}/lib/pkgconfig
    configure.args-replace      -Dpython3=false -Dpython3=true
}

if {![variant_isset python38] && \
    ![variant_isset python39] && \
    ![variant_isset python310] } {
    default_variants +python310
}

post-destroot {
# glade expects catalog modules and libraries to have a .so suffix
    if {[variant_isset glade]} {
        set libdir ${prefix}/lib
        ln -s ${libdir}/libpeas-gtk-1.0.dylib ${destroot}${libdir}/libpeas-gtk-1.0.so
    }
# same for libpeas demo plugin modules
    set plugindir ${prefix}/lib/peas-demo/plugins
    foreach plugin {helloworld secondtime} {
        ln -s ${plugindir}/$plugin/lib$plugin.dylib ${destroot}${plugindir}/$plugin/lib$plugin.so
    }
}

post-activate {
    system "${prefix}/bin/gtk-update-icon-cache -f -t ${prefix}/share/icons/hicolor"
}

livecheck.type      none
