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

# Please keep libjpeg-turbo and libjpeg-turbo-devel as similar as possible

name                libjpeg-turbo
conflicts           libjpeg-turbo-devel mozjpeg
set my_name         libjpeg-turbo
version             3.1.1
revision            0
github.setup        ${my_name} ${my_name} ${version}
github.tarball_from archive

categories          graphics
license             BSD
maintainers         {larryv @larryv} {mascguy @mascguy} {jmr @jmroot}

description         SIMD-accelerated libjpeg-compatible JPEG codec \
                    library
long_description    libjpeg-turbo is a JPEG image codec that uses SIMD \
                    instructions (MMX, SSE2, NEON) to accelerate \
                    baseline JPEG compression and decompression on \
                    x86, x86-64, and ARM systems. On such systems, \
                    libjpeg-turbo is generally 2-6x as fast as \
                    libjpeg, all else being equal. On other types of \
                    systems, libjpeg-turbo can still outperform \
                    libjpeg by a significant amount, by virtue of its \
                    highly-optimized Huffman coding routines. In many \
                    cases, the performance of libjpeg-turbo rivals \
                    that of proprietary high-speed JPEG codecs.
homepage            https://www.${my_name}.org

dist_subdir         ${my_name}

checksums           rmd160  ceafe9b5a25b92d2b6bd6f88f5aaa38ed10086be \
                    sha256  304165ae11e64ab752e9cfc07c37bfdc87abd0bfe4bc699e59f34036d9c84f72 \
                    size    2506010

configure.args-append \
                    -DENABLE_SHARED:BOOL=ON \
                    -DENABLE_STATIC:BOOL=ON \
                    -DWITH_JPEG8:BOOL=ON

if {${universal_possible} && [variant_isset universal]} {
    if {"x86_64" in ${configure.universal_archs} || "i386" in ${configure.universal_archs}} {
        depends_build-append port:nasm
    }
    set merger_configure_env(i386)  ASM_NASM=${prefix}/bin/nasm
    set merger_configure_env(x86_64)    ASM_NASM=${prefix}/bin/nasm
} elseif {${configure.build_arch} in {i386 x86_64}} {
    depends_build-append port:nasm
    configure.env       ASM_NASM=${prefix}/bin/nasm
} elseif {${configure.build_arch} eq "ppc"} {
    if {[catch {sysctl hw.vectorunit} result] || $result == 0} {
        configure.args-append   -DWITH_SIMD=OFF
        archive_sites
    }
}

variant java description {Add Java support} {
    PortGroup           java 1.0

    java.version        1.8
    java.fallback       openjdk8
    configure.args-append \
                        -DWITH_JAVA:BOOL=ON
}

variant tests description {Enable tests} {
    configure.pre_args-replace \
                        -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
                        -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF

    test.run            yes
    test.env-append \
                        CTEST_OUTPUT_ON_FAILURE=1
}

# Betas are numbered x.x.9x
github.livecheck.regex  {(\d+\.\d+\.(?:\d|[0-8]\d)(?:\.[0-9]+)*)}
