# -*- 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

github.setup    rawstudio rawstudio c140a5eb64901e07db5190db20f9884e86e5dcae
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version         20210603
revision        1
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 \
                patch-compatibility-with-libxml2-2.12.x.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 \
                port: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

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]
        configure.cflags-append \
                -Wno-c++11-narrowing \
                -Wno-return-type
    }

    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}
    }
}
