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

name                cyan
categories          graphics
license             CeCILL-2.1
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         Cyan Graphics
long_description    ${name} is an open-source cross-platform image viewer \
                    and converter, designed for prepress (print) work.
homepage            https://cyan.graphics

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    PortGroup       qmake 1.0

    # This is the same upstream, older repo.
    # See: https://github.com/rodlie/cyan/issues/115
    # TODO: see if we can fix a newer version.
    # For QtMimeTypes use qt4-mimetypes port.
    github.setup    olear cyan 1.0.0 {} .RC2
    revision        0
    checksums       rmd160  0325d3d86d269fd7ccec5f77ac55e0d9478f1941 \
                    sha256  77ce3b37ffa32d0057544b59c1e8b231e533ab351236f70926333881456ec3ea \
                    size    475138
} else {
    PortGroup       qmake5 1.0

    github.setup    rodlie cyan 1.2.4
    revision        0
    checksums       rmd160  21bc30bd4cc1daa4050038db62aea21cd82629ff \
                    sha256  4edfb4414820934c6898ccfa9ef1c2bfe3745effe8736f0c14f3523e8c926ab0 \
                    size    9413972

    compiler.cxx_standard   2011
    compiler.openmp_version 2.5

    patchfiles      patch-do-not-hardcode-deployment-target.diff

    if {[string match *gcc* ${configure.compiler}]} {
        patchfiles-append \
                    patch-no-libomp.diff
    } elseif {[string match *clang* ${configure.compiler}]} {
        patchfiles-append \
                    patch-libomp.diff
        post-patch {
            reinplace "s|@PREFIX@|${prefix}|" ${worksrcpath}/${name}.pro
        }
    }
}

github.tarball_from archive

depends_lib-append  port:ImageMagick \
                    port:lcms2 \
                    port:libiconv

# While it builds against ImageMagick7,
# it fails to work: https://github.com/rodlie/cyan/issues/116
# configure.pkg_config_path-prepend \
                    ${prefix}/lib/ImageMagick7/lib/pkgconfig

configure.args-append \
                    ${worksrcpath}/${name}.pro

destroot {
    copy ${worksrcpath}/build/Cyan.app ${destroot}${applications_dir}

    if {(${os.platform} eq "darwin" && ${os.major} > 11) ||
        ${os.platform} ne "darwin"} {
        xinstall -d ${destroot}${prefix}/share/${name}
        copy ${worksrcpath}/docs ${destroot}${prefix}/share/${name}/
    }
}
