# $Id: PKGBUILD 114755 2014-07-03 20:47:41Z heftig $
# Maintainer (Arch): Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor (Arch): Allan McRae <allan@archlinux.org>
# Contributor (Arch): dorphell <dorphell@archlinux.org>
# Maintainer (Hyperbola): André Silva <emulatorman@hyperbola.info>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>

_pkgbasename=sdl
pkgname=lib32-$_pkgbasename
pkgver=1.2.15
pkgrel=7.parabola1
pkgdesc="A library for portable low-level access to a video framebuffer, audio output, mouse, and keyboard (32-bit), without nonfree riva_mmio.h file"
arch=('x86_64')
url="http://www.libsdl.org"
license=('LGPL')
conflicts=('lib32-sdl-libre')
replaces=('lib32-sdl-libre')
depends=('lib32-libxext' 'lib32-libxrender' 'lib32-libx11' $_pkgbasename)
makedepends=('lib32-alsa-lib' 'lib32-mesa' 'lib32-libpulse' 'lib32-glu' gcc-multilib)
optdepends=('lib32-alsa-lib: ALSA audio driver'
            'lib32-libpulse: PulseAudio audio driver')
options=('staticlibs')
source=(https://repo.parabola.nu/other/sdl-libre/SDL-libre-${pkgver}.tar.gz
        sdl-1.2.14-fix-mouse-clicking.patch
        sdl-1.2.14-disable-mmx.patch
        fix_joystick_misc_axes.diff
        libsdl-1.2.15-resizing.patch
        sdl_x11sym.patch
        X11_KeyToUnicode.patch
        libre.patch)
md5sums=('6b9b5ac27428e1a3b96c50604f2b1c40'
         '04d8c179f125e04bcd4c9d60e013c2d7'
         'e5c16b7611f62c7cb25f0534eff68852'
         '687586a108b597a2a6b73070c1d37e51'
         '3dd50347d8856160a9cbd7f80383a1f8'
         '148b285bccee9d21bb96db807363b962'
         'edea272dff4698470877c016d818918d'
         '71fb007f43825950d0ec7558a30253e0')

prepare() {
  cd SDL-$pkgver
  patch -Np1 -i ../sdl-1.2.14-fix-mouse-clicking.patch
  patch -Np1 -i ../sdl-1.2.14-disable-mmx.patch
  patch -Np1 -i ../fix_joystick_misc_axes.diff
  patch -Np1 -i ../libsdl-1.2.15-resizing.patch
  patch -Np0 -i ../sdl_x11sym.patch
  patch -Np1 -i ../X11_KeyToUnicode.patch

  patch -Np1 -i ../libre.patch
}

build() {
  export CC="gcc -m32"
  export CXX="g++ -m32"
  export PKG_CONFIG_PATH="/usr/lib32/pkgconfig"

  cd SDL-$pkgver
  ./configure --prefix=/usr --disable-nasm --enable-alsa \
              --with-x --disable-rpath --disable-static --libdir=/usr/lib32
  make
}

package() {
  cd SDL-$pkgver
  make DESTDIR="$pkgdir" install

  rm -rf "$pkgdir"/usr/{include,share}

  cd "$pkgdir/usr/bin"
  mv sdl-config sdl-config-32
}
