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

name                ResIL
conflicts           libdevil
version             1.7.9
revision            8
categories          devel multimedia
license             LGPL-2.1
maintainers         ryandesign openmaintainer

description         Library to develop applications with powerful image \
                    loading capabilities

long_description    Resilient Image Library (ResIL, a fork of DevIL) is a programmer's \
                    library to develop applications with very powerful image \
                    loading capabilities, yet is easy for a developer to \
                    learn and use. Ultimate control of images is left to the \
                    developer, so unnecessary conversions, etc. are not \
                    performed. ResIL utilizes a simple, yet powerful, \
                    syntax. ResIL can load, save, convert, manipulate, \
                    filter and display a wide variety of image formats.

homepage            http://resil.sourceforge.net/
master_sites        sourceforge:project/resil
use_zip             yes

checksums           rmd160  7a0e5a15df4af3db735234db8789909f2097deac \
                    sha256  83f522170a3838f108e6d9e95989948f898df764c0838f614c8c18e6e8e8e918

depends_lib         port:lcms \
                    port:libmng \
                    port:libpng \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:tiff \
                    port:jasper \
                    port:xrender \
                    port:libGLU \
                    port:mesa

extract {
    # The 1.7.9 distfile has numerous packaging errors.
    # https://sourceforge.net/p/resil/tickets/1/
    
    # Some files fail to extract. The names have non-ASCII characters; possibly a character encoding problem.
    # Fortunately the files in question are unnecessary Visual Studio user settings so we can ignore the failure.
    system -W ${distpath} "unzip ${extract.pre_args} ${distfiles} ${extract.post_args} || true"

    # These directories are missing write permission for the user, causing permission errors when cleaning the port.
    foreach d {include lib test} {
        file attributes "${worksrcpath}/Input Libs/zlib128-dll/${d}" -permissions u+w
    }

    # Missing execute bit on scripts.
    foreach f {build-aux/install-sh configure} {
        file attributes ${worksrcpath}/${f} -permissions a+x
    }
}

patchfiles          patch-ilur.c \
                    patch-devil_internal_exports.h.diff \
                    patch-lib-Makefile.am.diff \
                    patch-include_IL_il.h \
                    patch-src-IL-include-il_endian.h.diff \
                    patch-strnicmp.diff

# include/IL/config.h.in is missing.
# https://sourceforge.net/p/resil/tickets/2/
use_autoreconf      yes

configure.args      --enable-ILU \
                    --enable-ILUT \
                    --enable-x11 \
                    --enable-render \
                    --enable-shm \
                    --disable-allegro \
                    --disable-exr \
                    --disable-sdl \
                    --disable-xpm

if {!${universal_possible} || ![variant_isset universal]} {
    if {${configure.build_arch} eq "i386"} {
        configure.args-append   --enable-x86
    } elseif {${configure.build_arch} eq "x86_64"} {
        configure.args-append   --enable-x86_64
    } else {
        configure.args-append   --enable-ppc
    }
}
set merger_configure_args(i386) --enable-x86
set merger_configure_args(x86_64) --enable-x86_64
set merger_configure_args(ppc) --enable-ppc
set merger_configure_args(ppc64) --enable-ppc

# https://sourceforge.net/p/resil/tickets/6/
if {[string match *clang* ${configure.compiler}]} {
    configure.cflags-append -std=gnu89
}

post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} AUTHORS COPYING CREDITS ChangeLog \
        NEWS README TODO ${destroot}${prefix}/share/doc/${name}
    file copy ${worksrcpath}/docs/html ${destroot}${prefix}/share/doc/${name}
}

variant sdl description {Enable libSDL renderer} {
    depends_lib-append port:libsdl
    configure.args-delete --disable-sdl
}

livecheck.regex     /${name}-(\[0-9.\]+)${extract.suffix}
