# -*- 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           active_variants 1.1
PortGroup           app 1.0
PortGroup           cmake 1.0
PortGroup           cxx11 1.1
PortGroup           conflicts_build 1.0

github.setup        darktable-org darktable 2.2.5 release-
revision            2

github.tarball_from releases
use_xz              yes

checksums           rmd160  1a66797ca24dc7ef06fc5bb2fbed98724d50c0f8 \
                    sha256  e303a42b33f78eb1f48d3b36d1df46f30873df4c5a7b49605314f61c49fbf281

set branch          [join [lrange [split ${version} .] 0 1] .]
categories          graphics
platforms           darwin
supported_archs     x86_64
maintainers         nomaintainer
license             GPL-3+

description         Virtual lighttable and darkroom for photographers

long_description    Darktable is a virtual lighttable and darkroom for \
                    photographers: it manages your digital negatives in a \
                    database and lets you view them through a zoomable \
                    lighttable. It also enables you to develop raw images \
                    and enhance them.

homepage            http://www.darktable.org/

depends_build-append  port:pkgconfig port:intltool

depends_lib-append  port:atk \
                    path:lib/pkgconfig/cairo.pc:cairo \
                    port:curl \
                    port:exiv2 \
                    port:flickcurl \
                    port:GraphicsMagick \
                    port:gdk-pixbuf2 \
                    port:gettext \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:gtk-osx-application-gtk3 \
                    port:gtk3 \
                    port:ilmbase \
                    port:jpeg \
                    port:json-glib \
                    port:lcms2 \
                    port:lensfun \
                    port:libgphoto2 \
                    port:libpng \
                    port:librsvg \
                    port:libsecret \
                    port:libsoup \
                    port:libusb \
                    port:lua52 \
                    port:libxml2 \
                    port:openexr \
                    port:openjpeg \
                    port:osm-gps-map \
                    path:lib/pkgconfig/pango.pc:pango \
                    port:pugixml \
                    port:sqlite3 \
                    port:webp \
                    port:tiff \
                    port:zlib

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

require_active_variants gtk3 quartz

conflicts_build lua

cmake.out_of_source yes

configure.args-append \
                    -DBUILD_CMSTEST=OFF \
                    -DTESTBUILD_OPENCL_PROGRAMS=OFF \
                    -DUSE_COLORD=OFF \
                    -DUSE_KWALLET=OFF \
                    -DUSE_OPENMP=OFF \
                    -DUSE_UNITY=OFF

post-build {
    set wrap [open "${workpath}/darktable-app" w 0755]
    puts ${wrap} "#!/bin/sh"
    puts ${wrap} ""
    puts ${wrap} "export XDG_DATA_DIRS=${prefix}/share:\$XDG_DATA_DIRS"
    puts ${wrap} "exec ${prefix}/bin/darktable --moduledir ${prefix}/lib/darktable"
    puts ${wrap} ""
    close ${wrap}
}

post-destroot {
    # need to determine why lib is not going where expected, until then...
    move ${destroot}${prefix}/lib/darktable/libdarktable.dylib ${destroot}${prefix}/lib/
}

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

app.executable      ${workpath}/darktable-app
app.icon            packaging/macosx/Icons.icns

universal_variant   no

# With gcc5 or gcc6, tries to build src/osx/osx.mm with gcc which results
# in a cascade of errors.  Leave disabled until a solution is found
# variant gcc5 description {Build with gcc5 to enable OpenMP for speed} {
#     depends_lib-append      port:gcc5
#     configure.args-replace  -DUSE_OPENMP=OFF -DUSE_OPENMP=ON
#     configure.compiler      macports-gcc-5
# }

variant clang39 conflicts clang40 description {Build with clang 3.9 to enable OpenMP for speed} {
    depends_lib-append      port:clang-3.9
    configure.args-replace  -DUSE_OPENMP=OFF -DUSE_OPENMP=ON
    configure.compiler      macports-clang-3.9
}

# See https://trac.macports.org/ticket/55380
# High Sierra build fails with clang-3.9
variant clang40 conflicts clang39 description {Build with clang 4.0 to enable OpenMP for speed} {
    depends_lib-append      port:clang-4.0
    configure.args-replace  -DUSE_OPENMP=OFF -DUSE_OPENMP=ON
    configure.compiler      macports-clang-4.0
}

if {![variant_isset clang39]} {
    default_variants    +clang40
}


notes "
Online documentation for ${name} is at:
http://www.darktable.org/usermanual/index.html.php

PDF documentation may be downloaded at:
http://www.darktable.org/resources/
"
livecheck.url       https://github.com/darktable-org/darktable/releases
livecheck.regex     release-(${branch}.\[0-9.\]?).tar