# -*- 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               cmake 1.1
PortGroup               conflicts_build 1.0
PortGroup               github 1.0
PortGroup               legacysupport 1.1
PortGroup               perl5 1.0

# FIXME: this is unusable on powerpc atm:
# https://github.com/aurelienpierreeng/ansel/issues/622

github.setup            aurelienpierreeng ansel 11ef7ff89971ad36443847e701670832b55e6f25
version                 2026.02.08
revision                3

categories              graphics
license                 GPL-3+
maintainers             {@barracuda156 macos-powerpc.org:barracuda} openmaintainer

description             darktable fork minus the bloat plus some design vision
long_description        Ansel is an open-source photo-editing software for digital artists, \
                        designed to help you achieve your own interpretation of raw digital photographs.
homepage                https://ansel.photos

# See: https://github.com/aurelienpierreeng/ansel/tree/bfa86dccea8a4bad347d6af2a051e95a3a3b1b7c/src/external
set xcf_hash            64efecf63ddd952ccf654e479714aaae6f8c5986
set rawspeed_hash       44c126d49476e534b7a56eb7af63320a805abb3c
set whereami_hash       dcb52a058dc14530ba9ae05e4339bd3ddfae0e0e

master_sites-append     https://github.com/houz/libxcf/archive/${xcf_hash}/:xcf \
                        https://github.com/darktable-org/rawspeed/archive/${rawspeed_hash}/:rawspeed \
                        https://github.com/gpakosz/whereami/archive/${whereami_hash}/:whereami

distfiles-append        libxcf-${xcf_hash}${extract.suffix}:xcf \
                        rawspeed-${rawspeed_hash}${extract.suffix}:rawspeed \
                        whereami-${whereami_hash}${extract.suffix}:whereami

checksums               ${distname}${extract.suffix} \
                        rmd160  20b2dffcb063bdcb657d883bd5941bc76632b79a \
                        sha256  7fb073a6ad629494ba09a0973915dd1dcc79d1207df58851248384f3022aa8ca \
                        size    58912363 \
                        libxcf-${xcf_hash}${extract.suffix} \
                        rmd160  b6234b368db69972061c0b1245ba272b579d02ec \
                        sha256  c7f51c387729f22534b953740ae6d1a5096e24688aeb640c08bf9cf25f169e2b \
                        size    111594 \
                        rawspeed-${rawspeed_hash}${extract.suffix} \
                        rmd160  095da5fe0d7e9ad1633e76b46cb5a2fa94447b87 \
                        sha256  6ec0539cd1d0fe41535de7c9284c8bf7a71c07a056459854357006fcf75d35fd \
                        size    488358 \
                        whereami-${whereami_hash}${extract.suffix} \
                        rmd160  99fd70cee1330daf4e899cfebf920029548a36a5 \
                        sha256  9eb20753b8994a51693373120a5deea502288954fa975704ba609b2c7a849615 \
                        size    15410
github.tarball_from     archive

extract.only            ${distname}${extract.suffix}

post-extract {
    set tar [findBinary tar ${portutil::autoconf::tar_command}]
    system -W ${workpath} "${tar} -zxf ${distpath}/libxcf-${xcf_hash}${extract.suffix}"
    system -W ${workpath} "${tar} -zxf ${distpath}/rawspeed-${rawspeed_hash}${extract.suffix}"
    system -W ${workpath} "${tar} -zxf ${distpath}/whereami-${whereami_hash}${extract.suffix}"
    delete ${worksrcpath}/src/external/libxcf
    delete ${worksrcpath}/src/external/rawspeed
    delete ${worksrcpath}/src/external/whereami
    move ${workpath}/libxcf-${xcf_hash} ${worksrcpath}/src/external/libxcf
    move ${workpath}/rawspeed-${rawspeed_hash} ${worksrcpath}/src/external/rawspeed
    move ${workpath}/whereami-${whereami_hash} ${worksrcpath}/src/external/whereami
}

# If lua installed, those headers are found first, rather than lua54.
conflicts_build         lua

# Enable use of 'macports-libcxx' for macOS 10.12 and earlier, as port uses
# libcxx features normally only available on 10.13 and later.
legacysupport.use_mp_libcxx \
                        yes

# Supported build types: Debug:RelWithDebInfo;Release;Coverage;Sanitize;Tsan;Fuzz
if {[variant_isset debug]} {
    cmake.build_type    RelWithDebInfo
} else {
    cmake.build_type    Release
}

perl5.branches          5.34

depends_build-append    port:cctools \
                        port:gettext \
                        port:intltool \
                        port:perl${perl5.major} \
                        path:bin/pkg-config:pkgconfig \
                        port:po4a

# Build with libsoup3 is broken atm.
depends_lib-append      port:atk \
                        path:lib/pkgconfig/cairo.pc:cairo \
                        port:curl \
                        port:exiv2 \
                        port:flickcurl \
                        port:GraphicsMagick \
                        path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                        port:gettext-runtime \
                        path:lib/pkgconfig/glib-2.0.pc:glib2 \
                        port:gmic-lib \
                        path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                        path:lib/pkgconfig/harfbuzz.pc:harfbuzz \
                        path:lib/pkgconfig/icu-uc.pc:icu \
                        port:imath \
                        port:iso-codes \
                        port:jasper \
                        port:json-glib \
                        port:lcms2 \
                        port:lensfun \
                        port:libavif \
                        port:libgphoto2 \
                        port:libheif \
                        path:include/turbojpeg.h:libjpeg-turbo \
                        port:libjxl \
                        port:libpng \
                        port:libraw \
                        path:lib/pkgconfig/librsvg-2.0.pc:librsvg \
                        port:libsecret \
                        port:libsoup-2.4 \
                        path:lib/pkgconfig/libusb-1.0.pc:libusb \
                        port:libxml2 \
                        port:lua54 \
                        port:openexr \
                        port:openjpeg \
                        port:osm-gps-map \
                        path:lib/pkgconfig/pango.pc:pango \
                        port:portmidi \
                        port:pugixml \
                        port:sqlite3 \
                        port:webp \
                        port:tiff \
                        port:zlib

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

require_active_variants gtk3 x11 quartz

# Use correct namespace:
patchfiles-append       patch-cmath.diff

# Do not fail on unsupported platforms:
patchfiles-append       patch-Allow-building-for-32-bit-and-PPC.diff

# Fix incoherent headers:
patchfiles-append       patch-osx-headers.diff

# Untested at the moment:
if {[string match *gcc* ${configure.compiler}]} {
    patchfiles-append   patch-osx.mm
}

# https://github.com/aurelienpierreeng/ansel/issues/573
patchfiles-append       trash-bad-check.patch

# https://github.com/aurelienpierreeng/ansel/issues/426
patchfiles-append       patch-exclude-broken-source.diff

# No not assume app bundle:
patchfiles-append       patch-no-bundle.diff

# https://github.com/aurelienpierreeng/ansel/issues/572
patchfiles-append       patch-no-opencl.diff

patchfiles-append       patch-ConfigureChecks.cmake

# Sets optimization to generic, but not for PowerPC,
# where it is not supported.
if {${configure.build_arch} ni [list ppc ppc64]} {
    configure.args-append \
                        -DBINARY_PACKAGE_BUILD=ON
}

configure.args-append   -DBUILD_CMSTEST=OFF \
                        -DBUILD_CURVE_TOOLS=ON \
                        -DBUILD_NOISE_TOOLS=ON \
                        -DTESTBUILD_OPENCL_PROGRAMS=OFF \
                        -DUSE_BUNDLED_LIBRAW=OFF \
                        -DUSE_BUNDLED_LUA=OFF \
                        -DUSE_COLORD=OFF \
                        -DUSE_KWALLET=OFF \
                        -DUSE_MAC_INTEGRATION=OFF \
                        -DUSE_OPENCL=OFF \
                        -DUSE_OPENMP=ON \
                        -DUSE_UNITY=OFF \
                        -DUSE_XCF=ON \
                        -DWITH_LIBSOUP2=ON \
                        -Dperl_BIN=${perl5.bin}

# For ARM build, we must disable Intel instruction set use.
if {${configure.build_arch} ni [list i386 x86_64]} {
    configure.args-append \
                        -DBUILD_SSE2_CODEPATHS=OFF
}

universal_variant       no

compiler.cxx_standard   2017
compiler.blacklist-append {clang < 1700}
compiler.blacklist-append {macports-clang-1[4-5]}
compiler.blacklist-append {macports-gcc-1[0-1]}
compiler.thread_local_storage yes
compiler.openmp_version 4.5

# The port sets its own optimization flags
configure.optflags
# Disable deprecation warnings
configure.cppflags-append \
                        -Wno-deprecated-declarations
# darktable.c:1513:24: error: passing argument 2 of 'host_page_size' from incompatible pointer type [-Wincompatible-pointer-types]
configure.cflags-append -Wno-error=incompatible-pointer-types
# https://gitlab.gnome.org/GNOME/gexiv2/-/issues/73
configure.cxxflags-append \
                        -D_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR

# Disabling OpenMP is not honored:
# Undefined symbols for architecture x86_64: "___kmpc_for_static_fini"
if {[string match *clang* ${configure.compiler}]} {
    depends_lib-append  port:libomp
    configure.ldflags-append \
                        -L${prefix}/lib/libomp \
                        -lomp
}

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