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

github.setup        ThioJoe jpeg2png 1.02 v
github.tarball_from archive
revision            0
categories          graphics
license             GPL-3
maintainers         {i0ntempest @i0ntempest} openmaintainer

description         Silky smooth JPEG decoding - no more artifacts!
long_description    JPEG encoding loses information. But it is JPEG decoding that introduces artifacts\
                    by filling the missing information with noise. ${name} is smarter and fills the\
                    missing information to create the smoothest possible picture.

checksums           rmd160  4e4cd1009eaba1e38991f59fa0669fc589ac6bbc \
                    sha256  6b2467e44db60e6d11f347f356be6b29a8bf0597ca97ad5afae9d461e8dcf119 \
                    size    69872

# static_assert
legacysupport.newest_darwin_requires_legacy \
                    14

compiler.c_standard 2011

depends_lib-append  port:libjpeg-turbo \
                    port:libpng \
                    port:zlib

post-patch {
    # remove the implicit variable reset
    system -W ${worksrcpath} "sed -i '' '3,8d' Makefile"
    reinplace "s|OPENMP=1|OPENMP=0|" Makefile
    reinplace "s|-Dm|-m|g" Makefile
    reinplace "s|/usr|${prefix}|g" Makefile
    if {${configure.build_arch} in [list arm64 ppc ppc64]} {
        reinplace "s|SIMD=1|SIMD=0|" Makefile
        reinplace "s|CFLAGS+=-msse2 -mfpmath=sse||" Makefile
    }
    if {[string match *clang* ${configure.compiler}]} {
        reinplace "s|PRAGMA_FP_CONTRACT=0|PRAGMA_FP_CONTRACT=1|" Makefile
    }
}

variant openmp description {enable parallelism support using OpenMP} {
    compiler.openmp_version 4.5
    compiler.blacklist-append   {macports-clang-[0-9].*}
    post-patch {
        reinplace "s|OPENMP=0|OPENMP=1|" Makefile
    }
}
