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

name                libbpg
version             0.9.8
revision            1
categories          graphics
maintainers         {ryandesign @ryandesign} openmaintainer
license             BSD LGPL-2.1+

description         better portable graphics -- a new image format

long_description    BPG (Better Portable Graphics) is a new lossy and \
                    lossless picture compression format based on HEVC. \
                    Its purpose is to replace the JPEG image format when \
                    quality or file size is an issue.

homepage            https://bellard.org/bpg/
master_sites        ${homepage}

checksums           rmd160  9960aea61e9e51e6c53a477d95a7c7b37d0dd7cc \
                    sha256  c0788e23bdf1a7d36cb4424ccb2fae4c7789ac94949563c4ad0e2569d3bf0095 \
                    size    2029021

depends_build       path:bin/pkg-config:pkgconfig

depends_lib         path:include/turbojpeg.h:libjpeg-turbo \
                    port:libpng \
                    port:libsdl \
                    port:libsdl_image

post-extract {
    # Work around conflict with C++20 <version> header on case-insensitive filesystems:
    # ./version:1:1: error: expected unqualified-id
    move ${worksrcpath}/VERSION ${worksrcpath}/VERSION.txt
}

patchfiles          Makefile.patch \
                    implicit.patch

use_configure       no

variant universal {}

# cc1: error: unrecognized command line option "-fno-signed-zeros"
# atomic_gcc.h:32: error: ‘__ATOMIC_SEQ_CST’ undeclared
compiler.blacklist-append \
                    *gcc-4.0 *gcc-4.2

build.args          prefix=${prefix} \
                    CC="${configure.cc} [get_canonical_archflags cc]" \
                    CXX="${configure.cxx} [get_canonical_archflags cxx]"

destroot.args       prefix=${prefix}

post-destroot {
    set docdir ${prefix}/share/doc/${subport}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} \
        README \
        doc/bpg_spec.txt \
        ${destroot}${docdir}
}

platform darwin {
    build.args-append CONFIG_APPLE=y
}
