# -*- 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                gexiv2
version             0.12.1
revision            0
license             GPL-2+
set branch          [join [lrange [split ${version} .] 0 1] .]
description         gexiv2 is a GObject-based wrapper around the exiv2 library.
long_description    ${description} \
                    It makes the basic features of exiv2 available to GNOME applications. \
                    Thanks to GObject Introspection support, gexiv2 has excellent support \
                    for Python 2 & 3, and can also be accessed by any other programming \
                    language that supports GI.
maintainers         {devans @dbevans} openmaintainer
categories          gnome graphics
platforms           darwin
homepage            https://wiki.gnome.org/Projects/gexiv2
master_sites        gnome:sources/${name}/${branch}/

use_xz              yes

checksums           rmd160  174717b7098fa545a60e05252c0568023dfdbab8 \
                    sha256  8aeafd59653ea88f6b78cb03780ee9fd61a2f993070c5f0d0976bed93ac2bd77 \
                    size    372104

depends_build-append \
                    port:pkgconfig \
                    port:gtk-doc

depends_lib         port:exiv2 \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:gobject-introspection \
                    port:vala

# one each of python2 python3 allowed

variant python27 description {Build Python2 bindings using Python 2.7} {
    depends_lib-append      port:py27-gobject3
}

default_variants +python27

variant python36 conflicts python37 python38 description {Build Python3 bindings using Python 3.6} {
    depends_lib-append      port:py36-gobject3
}

variant python37 conflicts python36 python38 description {Build Python3 bindings using Python 3.7} {
    depends_lib-append      port:py37-gobject3
}

variant python38 conflicts python36 python37 description {Build Python3 bindings using Python 3.8} {
    depends_lib-append      port:py38-gobject3
}

if {![variant_isset python36] && \
    ![variant_isset python37] && \
    ![variant_isset python38]} {
    default_variants +python38
}

patchfiles          patch-python-bins.diff

post-patch {
    if {[variant_isset python27]} {
        reinplace "s|@@PYTHON2_BIN@@|${prefix}/bin/python2.7|" ${worksrcpath}/meson.build
    } else {
        configure.args-append -Dpython2_girdir=no
    }

    if {[variant_isset python36]} {
        reinplace "s|@@PYTHON3_BIN@@|${prefix}/bin/python3.6|" ${worksrcpath}/meson.build
    } elseif {[variant_isset python37]} {
        reinplace "s|@@PYTHON3_BIN@@|${prefix}/bin/python3.7|" ${worksrcpath}/meson.build
    } elseif {[variant_isset python38]} {
        reinplace "s|@@PYTHON3_BIN@@|${prefix}/bin/python3.8|" ${worksrcpath}/meson.build
    } else {
        configure.args-append -Dpython3_girdir=no
    }
}

# https://trac.macports.org/ticket/61777
compiler.cxx_standard 2011

configure.args-append -Dgtk_doc=true

# the legacysupport math fixes are broken so we have to use gcc7+
if {${os.platform} eq "darwin" && ${cxx_stdlib} ne "libc++"} {
    compiler.blacklist *clang* *gcc6 *gcc5 *gcc-4*
}

# uses g-ir-scanner, which uses $CC from env
if {[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}"
}

livecheck.type      gnome
