# -*- 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           meson 1.0
PortGroup           gobject_introspection 1.0
PortGroup           gitlab 1.0

gitlab.instance     https://gitlab.gnome.org
gitlab.setup        GNOME gjs 1.80.1
revision            0

checksums           rmd160  151d8cba3eb10450c1871f4a6caa6efb007c2f65 \
                    sha256  c14f0ac52a29686dc2b5bcece91124c0df0198098d72e200cb39be36ebe8e678 \
                    size    703487

conflicts           gjs-devel
set my_name         gjs

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

description         GNOME JavaScript/Spidermonkey bindings
long_description    ${description}
homepage            https://gjs-docs.gnome.org/gjs

set py_ver          3.12
set py_ver_nodot    [string map {. {}} ${py_ver}]

depends_build-append \
                    path:bin/pkg-config:pkgconfig \
                    port:python${py_ver_nodot}

depends_lib-append \
                    path:lib/pkgconfig/cairo.pc:cairo \
                    port:dbus \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:libffi \
                    port:mozjs115 \
                    port:readline

compiler.cxx_standard \
                    2017

# LD_LIBRARY_PATH => DYLD_LIBRARY_PATH
patchfiles-append   patch-gjs-test.diff

# The gobject_introspection PG needs an 'introspection' option
patchfiles-append   patch-gjs-meson_options.diff

post-patch {
    reinplace "s|^#!/usr/bin/env python3|#!${configure.python}|" \
        build/compile-gschemas.py \
        build/symlink-gjs.py
}

configure.python    ${prefix}/bin/python${py_ver}

# profiler currently only supported on Linux
configure.args-append \
                    -Dprofiler=disabled \
                    -Dskip_dbus_tests=true \
                    -Dskip_gtk_tests=true \
                    -Dbsymbolic_functions=false

gobject_introspection yes

if {${os.platform} eq "darwin" && ${os.major} < 16} {
    # Fallback version for older systems.
    gitlab.setup    GNOME gjs 1.63.3
    revision        0
    checksums       rmd160  60cbadb35bad345917b153dc115f2c84fc8e55d3 \
                    sha256  63e97e3b76062c931fab1e0afa25f2db701e91e92653452df50e3ab3b51dfbbc \
                    size    435576

    # Use rust-free version of mozjs:
    depends_lib-replace     port:mozjs115 port:mozjs60

    patchfiles-delete       patch-gjs-test.diff patch-gjs-meson_options.diff

    # LD_LIBRARY_PATH => DYLD_LIBRARY_PATH
    patchfiles-append       patch-gjs-test-legacy.diff

    # The gobject_introspection PG needs an 'introspection' option
    patchfiles-append       patch-gjs-meson_options-legacy.diff

    # Fix gsize/size_t mismatch on 32-bit systems
    patchfiles-append       patch-gjs-gsize.diff

    # Fix gint64/int64_t mismatch on x86_64
    patchfiles-append       patch-gjs-gint64.diff

    # gatomic.h: error: argument 2 of '__atomic_load' must not be a pointer to a 'volatile' type
    patchfiles-append       patch-atomic_load.diff

    compiler.cxx_standard   2014
}

# Note that a few tests in the "Scripts / CommandLine" category may fail as the
# typelib (gobject-introspection) expects libgjs.0.dylib to be installed at the
# system level during testing
test.run            yes
test.target         test
