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

name            SDL3_image

github.setup    libsdl-org SDL_image 3.4.4 release-
revision        0
categories      devel graphics
license         zlib
maintainers     {jmr @jmroot} openmaintainer
description     Add-on library for libSDL handling several image formats

long_description \
    This is a simple library to load images of various formats as SDL surfaces. \
    This library supports BMP, PPM, PCX, GIF, JPEG, PNG, TGA and TIFF formats.

github.tarball_from releases
distname        ${name}-${version}

checksums       rmd160  ffece0e157ebde9d98abd5078bab041936104b5c \
                sha256  29751304a13d25ac513f24305fa25b06a6edd9607718c90129b8350d35fc5573 \
                size    11123077

# Disable broken compilers:
# SDL_stdinc.h:1149: error: size of array ‘SDL_compile_time_assert_bool_size’ is negative
compiler.blacklist  *clang* *gcc-4.*

depends_build-append \
                path:bin/pkg-config:pkgconfig
depends_lib     path:include/turbojpeg.h:libjpeg-turbo \
                port:libpng \
                port:SDL3 \
                port:tiff \
                port:webp \
                port:zlib

# STB disabled due to: https://github.com/Green-Sky/tomato/issues/53
configure.args-append \
                -DSDLIMAGE_AVIF=OFF \
                -DSDLIMAGE_BACKEND_IMAGEIO=OFF \
                -DSDLIMAGE_BACKEND_STB=OFF \
                -DSDLIMAGE_DEPS_SHARED=OFF \
                -DSDLIMAGE_INSTALL_MAN=ON \
                -DSDLIMAGE_JPG=ON \
                -DSDLIMAGE_JXL=OFF \
                -DSDLIMAGE_PNG=ON \
                -DSDLIMAGE_SAMPLES=OFF \
                -DSDLIMAGE_STRICT=ON

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

variant jxl description "Enable JPEG XL support (experimental)" {
    depends_lib-append      port:libjxl
    configure.args-replace  -DSDLIMAGE_JXL=OFF \
                            -DSDLIMAGE_JXL=ON
}

post-destroot {
    system "install_name_tool -id ${prefix}/lib/libSDL3_image.dylib ${destroot}${prefix}/lib/libSDL3_image.dylib"
}
