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

name            libsdl2
set my_name     SDL2
version         2.0.3
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  e6f3718c7366c5da793c1454cf0ec0972e8bd347 \
                sha256  a5a69a6abf80bcce713fa873607735fe712f44276a7f048d60a61bb2f6b3c90c

patch.pre_args            -p1
configure.args-append     --without-x

platform darwin 8 {
    patchfiles-append         patch-SDL2-2.0.3_OSX_104.diff

    # the joystick code in sdl 2.0.3 is based on APIs for 10.5+ only

    ######### option 1 disable joystick code ##################

#    configure.args-append     --disable-joystick

    ######### option 2  try to enable joystick using old joystick code from 2.0.1 ##############

    # copy joystick code from 2.0.1 into 2.0.3 source tree
    post-patch {
        delete ${worksrcpath}/src/joystick/darwin/SDL_sysjoystick.c
        delete ${worksrcpath}/src/joystick/darwin/SDL_sysjoystick_c.h
        copy ${portpath}/${filesdir}/SDL_sysjoystick_c.h ${worksrcpath}/src/joystick/darwin
        copy ${portpath}/${filesdir}/SDL_sysjoystick.c ${worksrcpath}/src/joystick/darwin
    }
    # needs extra framwork to support older joystick controller
    configure.ldflags-append  -framework ForceFeedback

    # work around bug in headers - this should be in a ppc only block
    configure.cflags-append   -faltivec

################################################################

    # either way, with or without joystick above, haptic code is not needed
    # 10.4 version has it included in the ForceFeedback framework
    configure.args-append     --disable-haptic
}

platform darwin 9 {
    patchfiles-append         patch-SDL2-2.0.3_OSX_105.diff
}

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 \
        ${destroot}${docdir}
}

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