# Maintainer: schuay <jakob.gruber@gmail.com>
# Contributor: Jeremy Newton (Mystro256)

pkgname=dolphin-emu
pkgver=4.0.2
pkgrel=6
epoch=1
pkgdesc='A Gamecube / Wii / Triforce emulator'
arch=('i686' 'x86_64')
url='http://dolphin-emu.org'
license=('GPL2')

makedepends=('cmake' 'git' 'opencl-headers')
depends=('bluez-libs' 'ffmpeg' 'glew' 'libao' 'libusbx' 'miniupnpc' 'openal' 'sdl2' 'soundtouch' 'wxgtk')
#optdepends=('pulseaudio: PulseAudio backend')

options=('!emptydirs')
install="${pkgname}.install"
source=("${pkgname%-*}::git+https://code.google.com/p/dolphin-emu/#tag=${pkgver}"
        'dolphin-emu-gcc49.patch'
        'dolphin-emu.xml'
        'dolphin-emu_games.xml'
        'dolphin-emu_scan.sh'
        'gen_lib_dolphin-emu.conf')

prepare() {
  cd "${srcdir}/${pkgname%-*}"

  patch -Np1 -i ../dolphin-emu-gcc49.patch
}

build() {
  cd "${srcdir}/${pkgname%-*}"

  mkdir build && cd build
  if [[ $CARCH == x86_64 ]]; then
    cmake .. -DCMAKE_INSTALL_PREFIX='/usr' -DCMAKE_CXX_FLAGS='-fno-inline-functions'
  else
    cmake .. -DCMAKE_INSTALL_PREFIX='/usr'
  fi
  make
}

package() {
  cd "${srcdir}/${pkgname%-*}/build"

  #LinHES Stuff
  mkdir -p "${pkgdir}"/usr/share/mythtv/themes/defaultmenu
  mkdir -p "${pkgdir}"/usr/LH/bin
  cp "${srcdir}/dolphin-emu.xml" "${pkgdir}/usr/share/mythtv/themes/defaultmenu"
  cp "${srcdir}/dolphin-emu_games.xml" "${pkgdir}/usr/share/mythtv/themes/defaultmenu"
  install -m755 "${srcdir}/dolphin-emu_scan.sh" "${pkgdir}/usr/LH/bin"
  #add in file for gen_game.xml
  install -D -m0744 ${srcdir}/gen_lib_dolphin-emu.conf ${pkgdir}/etc/gen_game_xml.d/dolphin-emu.conf

  make DESTDIR="${pkgdir}" install
}
md5sums=('SKIP'
         '5fead49fc3a0ff9a9d1435368b5df1f9'
         'ab7a9b9cfe03db65c881134c0f02bda0'
         '1d03499e0abab56285bc97176d311bf1'
         'af44dd20626ce26d0a07dadc37c20233'
         '9884a9769c1954ab9dcb0727c8c81984')