# -*- 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           cmake 1.1
PortGroup           active_variants 1.1

set real_name       evolution-data-server
name                ${real_name}-gtk4
conflicts           ${real_name}
# We do not need the latest version, and it won’t build
# anyway due to required dependencies.
version             3.52.4
revision            3

categories          gnome
license             LGPL-2+
maintainers         nomaintainer

description         Addressbook and calender libs for GNOME.
long_description    Evolution Data Server provides a central location \
                    for addressbook and calendar in the GNOME Desktop.
homepage            https://wiki.gnome.org/Apps/Evolution

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

checksums           rmd160  6bac31557afcaaa4a11e17c828d64ae3f6f75da7 \
                    sha256  1b36a839db1c8d898066e19be78b995930a0a2f2a886f149e4f64e1755f064f7 \
                    size    5055252

set bdb_ver         62

depends_build-append \
                    port:gettext \
                    port:gperf \
                    port:intltool \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:db${bdb_ver} \
                    port:gettext-runtime \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    path:lib/pkgconfig/gtk+-4.0.pc:gtk4 \
                    path:lib/pkgconfig/icu-uc.pc:icu \
                    port:json-glib \
                    port:kerberos5 \
                    port:libcanberra \
                    port:libical \
                    port:libiconv \
                    port:libsecret \
                    path:lib/pkgconfig/libsoup-3.0.pc:libsoup \
                    port:libxml2 \
                    port:nss \
                    port:nspr \
                    path:lib/libldap.dylib:openldap \
                    port:sqlite3 \
                    port:zlib

depends_run-append  path:bin/perl:perl5

# src/services/evolution-alarm-notify/e-alarm-notify.c:29:10: fatal error: 'gio/gdesktopappinfo.h' file not found
require_active_variants path:lib/pkgconfig/glib-2.0.pc:glib2 x11

patchfiles-append   patch-cmake-find-our-build-tools.diff \
                    patch-remove-linker-flag-no-undefined.diff \
                    patch-fix-icu.diff

# ICU requires C++17
compiler.cxx_standard \
                    2017
configure.cxxflags-append \
                    -std=c++17

# weather and oauth2 cannot be enabled at the moment,
# since MacPorts does not have required versions of dependencies.
# Notice, oauth2 and goa must be disabled for powerpc systems,
# as there is no webkit2gtk at all.
configure.args-append \
                    -DENABLE_EXAMPLES=OFF \
                    -DENABLE_GOA=OFF \
                    -DENABLE_GOOGLE=OFF \
                    -DENABLE_GTK=ON \
                    -DENABLE_GTK4=ON \
                    -DENABLE_GTK_DOC=OFF \
                    -DENABLE_INSTALLED_TESTS=OFF \
                    -DENABLE_INTROSPECTION=OFF \
                    -DENABLE_IPV6=ON \
                    -DENABLE_OAUTH2_WEBKITGTK=OFF \
                    -DENABLE_OAUTH2_WEBKITGTK4=OFF \
                    -DENABLE_SCHEMAS_COMPILE=OFF \
                    -DENABLE_SMIME=ON \
                    -DENABLE_VALA_BINDINGS=OFF \
                    -DENABLE_WEATHER=OFF \
                    -DLIBEXEC_INSTALL_DIR=${prefix}/libexec/${real_name} \
                    -DWITH_LIBDB_CFLAGS="-I${prefix}/include/db${bdb_ver}" \
                    -DWITH_LIBDB_LIBS="-L${prefix}/lib/db${bdb_ver} -ldb" \
                    -DWITH_OPENLDAP=${prefix}

# port nss is not universal
universal_variant   no

# TODO: Need to fix CMake detection for 'libphonenumber-cpp', before we can enable
# See: https://trac.macports.org/ticket/63788
#default_variants    +phonenumber
variant phonenumber description {Phone number parsing/validation using libphonenumber} {
    depends_lib-append \
                    port:libphonenumber-cpp
    configure.cxxflags-append \
                    -DI18N_PHONENUMBERS_USE_BOOST
    configure.args-append \
                    -DWITH_PHONENUMBER=${prefix}/lib
}

post-destroot {
    ln -s ${prefix}/lib/${real_name}/libedbus-private.dylib ${destroot}${prefix}/lib
}

post-activate    {
    system "${prefix}/bin/glib-compile-schemas ${prefix}/share/glib-2.0/schemas"
}

livecheck.type      gnome
