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

# clock_gettime, filesystem
legacysupport.newest_darwin_requires_legacy 18
legacysupport.use_mp_libcxx yes

github.setup        butcherg rawproc 1.4
revision            0
categories          graphics
license             GPL-3
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         Select RAW processing routines
long_description    This is a project that aims to make some of RawTherapeeʼs \
                    highly optimized raw processing routines readily available \
                    for other FOSS photo editing software.
distname            ${name}-${version}.0
checksums           rmd160  586f7539e7de2b23b060b885a75b4a28a799d901 \
                    sha256  b184e439edd737399c70efc826a7c93bf31eeaa6e544058a675888e30b81b868 \
                    size    2329488
github.tarball_from releases

compiler.cxx_standard   2017

# Patches from upstream, drop with next release:
# https://github.com/butcherg/rawproc/issues/25
patch.pre_args-replace  -p0 -p1
patchfiles          bea9e18969953ce3cdc5bc28be60219a05994c60.patch \
                    626a36fdd1f12cb91f1f9fca944046e1ef69a656.patch \
                    4c5326dcd34f1ffa221a884d0bfb30a44c680848.patch \
                    3cca5cf63c3d466f6ffea1c771e4f556c67509d4.patch

depends_build-append \
                    path:bin/pkg-config:pkgconfig \
                    port:wget

depends_lib-append  port:exiv2 \
                    port:lcms2 \
                    port:lensfun \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libpng \
                    port:libraw \
                    port:librtprocess \
                    port:tiff

compiler.openmp_version 2.5

if {[string match *clang* ${configure.compiler}]} {
    configure.cxxflags-append \
                    -D_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES \
                    -Wno-non-pod-varargs

    configure.ldflags-append \
                    -L${prefix}/lib/libomp \
                    -lomp
}

if {${os.platform} eq "darwin" && ${os.major} > 15} {
    wxWidgets.use   wxWidgets-3.2
} elseif {${os.platform} eq "darwin" && ${os.major} > 11} {
    wxWidgets.use   wxWidgets-3.0-cxx11
} else {
    wxWidgets.use   wxGTK-3.0-cxx11
}

depends_lib-append  port:${wxWidgets.port}
configure.args-append \
                    -DwxWidgets_CONFIG_EXECUTABLE:FILEPATH=${wxWidgets.wxconfig}

configure.args-append \
                    -DEXIV2=ON \
                    -DLCMS2=ON \
                    -DLENSFUN=ON \
                    -DLIBRAW=ON \
                    -DLIBRTPROCESS=ON \
                    -DGMIC=OFF

build.target        all conf

destroot {
    copy ${cmake.build_dir}/rawproc ${destroot}${prefix}/bin/
    move ${cmake.build_dir}/exif ${destroot}${prefix}/bin/rawproc-exif
    move ${cmake.build_dir}/img ${destroot}${prefix}/bin/rawproc-img
    move ${cmake.build_dir}/wxcmd ${destroot}${prefix}/bin/rawproc-wxcmd
}

legacysupport.redirect_bins rawproc rawproc-exif rawproc-img rawproc-wxcmd

post-destroot {
    xinstall -d ${destroot}${prefix}/share/${name}
    copy ${cmake.build_dir}/${name}.conf ${destroot}${prefix}/share/
}

notes "
A generated config file has been placed into $prefix/share/$name folder.\
Please copy it to ~/.$name and edit if needed.
"
