# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem 1.0
PortGroup       compiler_blacklist_versions 1.0
PortGroup       xcodeversion 1.0

name            libsdl2
set my_name     SDL2
version         2.0.10
categories      devel multimedia
platforms       macosx freebsd
license         zlib
maintainers     {jmr @jmroot} openmaintainer
description     Cross-platform multi-media development API

long_description \
    Simple DirectMedia Layer is a cross-platform development library \
    designed to provide low level access to audio, keyboard, mouse, \
    joystick, and graphics hardware via OpenGL and Direct3D.

homepage        http://www.libsdl.org/
master_sites    ${homepage}release/
distname        ${my_name}-${version}

checksums       rmd160 b35818cbf8eaf0c9c4d3b6d7a293c05a368366b2 \
                sha256 b4656c13a1f0d0023ae2f4a9cf08ec92fffb464e0f24238337784159b8b91d57

# use of undeclared identifier 'NSEventSubtypeMouseEvent'
patchfiles      10.11-fix.patch

configure.args  --without-x
build.args      V=1

compiler.blacklist *gcc* { clang < 211 }

minimum_xcodeversions   {11 4.3}

platform macosx {
    if {${os.major} <= 10} {
        # Build requires at least 10.7.3 SDK, even when targeting 10.6
        set lion_sdkpath ${developer_dir}/SDKs/MacOSX10.7.sdk
        if {[file exists $lion_sdkpath]} {
            configure.sdkroot $lion_sdkpath
        } else {
            pre-fetch {
                error "Building $name @${version} on Mac OS X 10.6 requires the MacOSX10.7.sdk to be present in ${developer_dir}/SDKs/"
            }
        }
    }
}

variant x11 {
    configure.args-delete --without-x
    configure.args-append --x-includes=${prefix}/include \
                          --x-libraries=${prefix}/lib \
                          --disable-x11-shared
    depends_lib-append \
        port:xorg-libX11 \
        port:xorg-libXcursor \
        port:xorg-libXext \
        port:xorg-libXi \
        port:xorg-libXinerama \
        port:xorg-libXrandr \
        port:xorg-libXScrnSaver \
        port:xorg-libXxf86vm \
        port:xrender
}
if {${os.subplatform} ne "macosx"} {
    default_variants +x11
}

post-destroot {
    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} BUGS.txt COPYING.txt CREDITS.txt \
        README.txt README-SDL.txt TODO.txt WhatsNew.txt \
        {*}[glob ${worksrcpath}/docs/*.md] ${destroot}${docdir}
}

livecheck.type  regex
livecheck.url   ${homepage}download-2.0.php
livecheck.regex ${my_name}-(\\d+(?:\\.\\d+)*)