# -*- 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       github 1.0
PortGroup       legacysupport 1.1
PortGroup       openssl 1.0

# Original upstream is dead.
github.setup    sergiomb2 rawstudio 6ecad748e672fdef3ebd60e19c3e3d4dd4480614
version         20240610
revision        2
categories      graphics
license         GPL-2+
maintainers     {@barracuda156 gmail.com:vital.had} openmaintainer
homepage        https://rawstudio.org
description     Raw-image converter
long_description \
                Rawstudio is a modern raw-image converter and organizer with many features. \
                * Reads all dcraw supported formats \
                * Internal 16-bit rgb \
                * Various post-shot controls (white balance, saturation \
                  and exposure compensation among others) \
                * Realtime histogram \
                * Easy sorting of images \
                * Fullscreen mode for better overview

legacysupport.redirect_bins rawstudio

# Rawstudio uses an external submodule Rawspeed which is missing in a tarball.
# https://github.com/rawstudio/rawstudio/tree/master/plugins/load-rawspeed
# https://github.com/klauspost/rawspeed/tree/fa23d1c2f71c01cc085b80a2a6f8b633edd2626b
fetch.type      git

post-fetch {
    system -W ${worksrcpath} "git submodule update --init"
}

patchfiles-append \
                patch-DARWIN_C_SOURCE.diff \
                patch-rawstudio.h.diff

# exiv2 0.28+ compatibility:
patchfiles-append \
                patch-exiv2.diff

if {[string match *gcc* ${configure.compiler}]} {
    patchfiles-append \
                patch-inlines.diff
}

# Apple clangs fail to build it too, at least very recent ones.
compiler.blacklist-append \
                {clang} {macports-clang-1[5-9]}
# Not declared explicitly, but used.
# Symbol not found: __ZN5Exiv27ExifKeyC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
compiler.cxx_standard   2011

depends_build-append \
                port:autoconf \
                port:automake \
                port:gettext \
                port:libtool \
                path:bin/pkg-config:pkgconfig

depends_lib-append \
                port:curl \
                path:lib/pkgconfig/dbus-1.pc:dbus \
                port:exiv2 \
                port:fftw-3 \
                port:fftw-3-single \
                port:flickcurl \
                port:gconf \
                port:gettext-runtime \
                path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                port:lcms2 \
                port:lensfun \
                port:libgphoto2 \
                path:include/turbojpeg.h:libjpeg-turbo \
                port:libxml2 \
                port:sqlite3 \
                port:tiff \
                port:xorg-libX11

# This way it works:
configure.cmd   ./autogen.sh

# ciff-meta.c: error: incompatible integer to pointer conversion passing 'guint'
# (aka 'unsigned int') to parameter of type 'GDateTime *' (aka 'struct _GDateTime *')
configure.cflags-append \
                -Wno-error=int-conversion

platform darwin {
    if {[string match *clang* ${configure.compiler}]} {
        # rs-curve.c: error: non-void function 'rs_curve_widget_draw' should return a value [-Wreturn-type]
        # Also force an error on implicit-function-declaration to replicate gcc14 behavior.
        configure.cflags-append \
                -Wno-c++11-narrowing \
                -Wno-return-type \
                -Werror=implicit-function-declaration
    } elseif {[string match macports-gcc* ${configure.compiler}]} {
        # rs-cmm.c: error: passing argument 1 of 'cmsBuildGamma' from incompatible pointer type [-Wincompatible-pointer-types]
        configure.cflags-append \
                -Wno-error=incompatible-pointer-types
    }

    if {${configure.build_arch} in [list ppc ppc64]} {
        # Do not use Xcode clang for ppc.
        compiler.blacklist-append clang
        # Do not use Intel instructions on Rosetta.
        configure.args-append \
                CAN_COMPILE_SSE2=no \
                CAN_COMPILE_SSE4_1=no \
                CAN_COMPILE_AVX=no \
                --build=powerpc-apple-darwin${os.major}
    }
}
