# -*- 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           gobject_introspection 1.0
PortGroup           legacysupport 1.1
PortGroup           perl5 1.0
PortGroup           yelp 1.0

# strnlen
legacysupport.newest_darwin_requires_legacy 10

name                gnumeric
version             1.12.61
revision            0
set branch          [join [lrange [split ${version} .] 0 1] .]

license             GPL-2+
maintainers         {devans @dbevans} openmaintainer
categories          gnome math science

description         Powerful Gtk3 based spreadsheet with Excel, ODF, R and Python support
long_description    A powerful Gtk3 based spreadsheet that features full Excel function \
                    and file compatibility and additional functions not found in Excel, \
                    and statistics operations based on R. Functionality can be extended \
                    with Python and plugins. Other file compatibility includes OASIS ODF, \
                    Quattro Pro, Psion 5, Paradox DB and more (see homepage). GDA \
                    database support is available with the +database variant.

homepage            http://www.gnumeric.org
master_sites        gnome:sources/${name}/${branch}/
use_xz              yes

checksums           rmd160  6457d8efd74c606757e763f667fb053200bd2546 \
                    sha256  2ac135d856572713c1a408b76b50a59f2a9769ed21f1213446b5af255df20a12 \
                    size    17921384

perl5.branches      5.34

depends_build-append \
                    port:autoconf \
                    port:automake \
                    port:bison \
                    port:gettext \
                    port:gsed \
                    port:gtk-doc \
                    port:intltool \
                    port:itstool \
                    port:libtool \
                    path:bin/pkg-config:pkgconfig

# update-desktop-database is provided by desktop-file-utils

depends_lib-append  port:gettext-runtime \
                    port:goffice \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:libxml2 \
                    port:perl${perl5.major} \
                    port:psiconv \
                    port:pxlib

depends_run         port:adwaita-icon-theme \
                    port:desktop-file-utils

gobject_introspection   yes

patchfiles          patch-perl5.26-Makefile-fix.diff \
                    patch-dont-build-broken-sstest.diff \
                    patch-python-introspection-install-fix.diff \
                    patch-psiconv-read.diff \
                    patch-Makefile-perl.diff

# reconfigure using upstream autogen.sh for intltool 0.51 compatibility

post-patch {
    xinstall -m 755 ${filespath}/autogen.sh ${worksrcpath}
}

configure.cmd       ./autogen.sh

# Type redefinition
compiler.c_standard 2011

configure.perl      ${perl5.bin}

configure.args      --disable-silent-rules \
                    --disable-schemas-compile \
                    --without-gda \
                    --without-python \
                    ac_cv_prog_AWK=/usr/bin/awk

variant quartz      { }

if {[variant_isset quartz]} {
    require_active_variants gtk3 quartz
    require_active_variants goffice quartz
} else {
    require_active_variants gtk3 x11
    require_active_variants goffice "" quartz
}

variant database description "Build with support for GDA database" {
    depends_lib-append          port:libgda5
    configure.args-replace      --without-gda --with-gda
}

# FIXME: flag passed manually due to a bug in py-gobject3: https://trac.macports.org/ticket/72209

variant python310 conflicts python311 description "Build Python plugin loader using Python 3.10" {
    configure.python            ${prefix}/bin/python3.10
    configure.args-replace      --without-python --with-python
    depends_lib-append          port:py310-gobject3
    set python_framework        ${frameworks_dir}/Python.framework/Versions/3.10
    configure.pkg_config_path   ${python_framework}/lib/pkgconfig
    configure.cppflags-append   -I/${python_framework}/include/python3.10/pygobject/pygobject-3.0
}

variant python311 conflicts python310 description "Build Python plugin loader using Python 3.11" {
    configure.python            ${prefix}/bin/python3.11
    configure.args-replace      --without-python --with-python
    depends_lib-append          port:py311-gobject3
    set python_framework        ${frameworks_dir}/Python.framework/Versions/3.11
    configure.pkg_config_path   ${python_framework}/lib/pkgconfig
    configure.cppflags-append   -I/${python_framework}/include/python3.11/pygobject/pygobject-3.0
}

if {![variant_isset python39] && ![variant_isset python310]} {
    default_variants-append     +python311
}

post-activate {
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
    # gtk3 provides gtk-update-icon-cache
    system "${prefix}/bin/gtk-update-icon-cache -f -t ${prefix}/share/icons/hicolor"
    system "${prefix}/bin/glib-compile-schemas ${prefix}/share/glib-2.0/schemas"
}

livecheck.type  gnome
