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

name                inkscape
conflicts           inkscape-devel
set my_name         inkscape

set ver_num         1.4.3
set ver_date        2025-12-25
set ver_hash        0d15f75042
set ver_gal_item    58914
version             ${ver_num}
epoch               1

categories          graphics gnome
license             GPL-3+
maintainers         {mascguy @mascguy} openmaintainer

description         This is the current stable release version of Inkscape.
long_description    Inkscape is an multi-platform, Open-Source Vector Graphics Editor \
                    that uses SVG as its native file format. \
                    {*}${description}
homepage            https://inkscape.org/

master_sites        https://inkscape.org/gallery/item/${ver_gal_item}
worksrcdir          ${my_name}-${ver_num}_${ver_date}_${ver_hash}
distname            ${my_name}-${ver_num}
dist_subdir         ${my_name}
use_xz              yes

checksums           rmd160  c467d4018561eb4fedef1c6284b9cd998ced5591 \
                    sha256  e83a2c3db570b6c5a1ff0fccfe7098837b3f6bd74b133567937c8a91710ed1d1 \
                    size    53907460

cmake.generator     Ninja

set python_major    3
set python_minor    12
set python_version  ${python_major}${python_minor}

# Fix for poppler >= 26.01.0: gfree -> g_free, reset -> rewind
patchfiles-append   poppler-26.01.0.patch

# Fix for glibmm-2.4 < 2.64: Glib::canonicalize_filename not available
patchfiles-append   glibmm-canonicalize.patch

post-patch {
    reinplace "s|\"python-interpreter\", *\{\"python3\"|\"python-interpreter\", \{\"python${python_major}.${python_minor}\"|g" \
        ${worksrcpath}/src/extension/implementation/script.cpp
    reinplace "s|COMMAND python3 |COMMAND ${prefix}/bin/python${python_major}.${python_minor} |g" \
        ${worksrcpath}/share/filters/CMakeLists.txt \
        ${worksrcpath}/share/markers/CMakeLists.txt \
        ${worksrcpath}/share/paint/CMakeLists.txt \
        ${worksrcpath}/share/palettes/CMakeLists.txt \
        ${worksrcpath}/share/symbols/CMakeLists.txt \
        ${worksrcpath}/share/templates/CMakeLists.txt
    reinplace "s|\"\$\{CMAKE_INSTALL_LIBDIR\}/inkscape\"|\$\{CMAKE_INSTALL_LIBDIR\}|" \
        ${worksrcpath}/src/CMakeLists.txt
}

# Blacklist older Clang versions, for compilation errors:
#   src/display/cairo-utils.cpp:
#     No matching function for call to 'isnan'
#   src/ui/dialog/objects.cpp:
#     No member named 'extract'
# See: https://trac.macports.org/ticket/65002
compiler.blacklist-append \
                    {clang < 1001}

if { [string match *clang* ${configure.compiler}] } {
    configure.cxxflags-append \
                    -Wno-invalid-constexpr \
                    -Wno-error=unknown-warning-option \
                    -Wno-unknown-warning-option
}

# Inkscape 1.4+ uses boost::asio (needs >= 1.78 for C++20 compat)
# and links against boost_filesystem
boost.version       1.81
boost.depends_type  lib
depends_build-append \
                    port:gettext \
                    port:gtest \
                    path:bin/pkg-config:pkgconfig

depends_lib-append \
                    port:boehmgc \
                    path:lib/pkgconfig/cairo.pc:cairo \
                    port:desktop-file-utils \
                    port:double-conversion \
                    port:fontconfig \
                    path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                    port:gettext-runtime \
                    path:lib/pkgconfig/glibmm-2.68.pc:glibmm \
                    port:gsl \
                    port:gspell \
                    port:gtkmm3 \
                    port:gtksourceview4 \
                    path:lib/pkgconfig/harfbuzz.pc:harfbuzz \
                    port:ImageMagick \
                    port:lcms2 \
                    port:libcdr-0.1 \
                    port:libepoxy \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libpng \
                    port:libsigcxx2 \
                    port:libvisio-0.1 \
                    port:libwpg-0.3 \
                    port:libxml2 \
                    port:libxslt \
                    path:lib/pkgconfig/pango.pc:pango \
                    path:lib/pkgconfig/poppler.pc:poppler \
                    port:potrace \
                    port:python${python_version} \
                    port:zlib

depends_run-append \
                    port:adwaita-icon-theme \
                    port:py${python_version}-cssselect \
                    port:py${python_version}-lxml \
                    port:py${python_version}-numpy \
                    port:py${python_version}-scour

compiler.cxx_standard \
                    2020

# Inkscape 1.4.3 uses CMP0167 NEW, requiring Boost config mode
configure.args-append \
                    -DCMAKE_PREFIX_PATH="[boost::install_area]" \
                    -DBUILD_TESTING=OFF \
                    -DENABLE_LCMS=ON \
                    -DENABLE_POPPLER=ON \
                    -DENABLE_POPPLER_CAIRO=OFF \
                    -DWITH_ASAN=OFF \
                    -DWITH_GNU_READLINE=OFF \
                    -DWITH_GRAPHICS_MAGICK=OFF \
                    -DWITH_GSOURCEVIEW=ON \
                    -DWITH_GSPELL=ON \
                    -DWITH_IMAGE_MAGICK=ON \
                    -DWITH_INTERNAL_CAIRO=OFF \
                    -DWITH_INTERNAL_2GEOM=ON \
                    -DWITH_JEMALLOC=OFF \
                    -DWITH_LIBCDR=ON \
                    -DWITH_LIBVISIO=ON \
                    -DWITH_LIBWPG=ON \
                    -DWITH_MANPAGE_COMPRESSION=OFF \
                    -DWITH_NLS=ON \
                    -DWITH_OPENMP=OFF \
                    -DWITH_PROFILING=OFF \
                    -DWITH_X11=OFF

# The following dummy variants are used to identify this port's binary dependencies,
# based on which variant of gtkmm is used for the build.
variant x11 conflicts quartz {}
variant quartz conflicts x11 {}

if {![variant_isset quartz]} {
    default_variants +x11
}

variant tests description {Enable tests} {
    configure.args-replace \
                    -DBUILD_TESTING=OFF \
                    -DBUILD_TESTING=ON

    test.run        yes
}

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

notes {
    Install port 'inkscape-app', to create a macOS app launcher.
}

livecheck.type      regex
livecheck.url       https://inkscape.org/release/
livecheck.regex     ">Inkscape (\\d+(?:\\.\\d+)*)<"
