# Maintainer: Sandy Carter <[email protected]>
# PKGBUILD source: https://github.com/bwrsandman/pkgbuild/tree/master/openmw

pkgname=openmw
pkgver=0.22.0
pkgrel=2
pkgdesc="An open-source engine reimplementation for the role-playing game Morrowind."
arch=('i686' 'x86_64')
url="http://www.openmw.org"
license=('GPL3' 'custom')

depends=('openal' 'ogre' 'mygui' 'bullet' 'mpg123' 'libsndfile' 'qt4' 'ffmpeg')

makedepends=('cmake' 'boost')

source=(http://openmw.googlecode.com/files/${pkgname}-${pkgver}-source.tar.gz)
sha1sums=('d896fe7593dac5f061a2b271357d52f1a8841c2e')

conflicts=('openmw-git')

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

# Workaround for bug in qt4 moc compiler
for f in $(find . -name CMakeLists.txt); do
sed -i 's/QT4_WRAP_CPP(\(.*\))/QT4_WRAP_CPP(\1 OPTIONS -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)/i' $f
done

msg "Starting make..."
cmake -DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DQT_QMAKE_EXECUTABLE=/usr/bin/qmake-qt4
make ${MAKEFLAGS}
}

package() {
cd "${srcdir}/openmw-${pkgname}-${pkgver}"

# Binaries
install -d -m755 "$pkgdir"/usr/bin
install -m755 openmw "$pkgdir"/usr/bin/
install -m755 opencs "$pkgdir"/usr/bin/
install -m755 omwlauncher "$pkgdir"/usr/bin/
install -m755 esmtool "$pkgdir"/usr/bin/
install -m775 mwiniimport "$pkgdir"/usr/bin


# Config files
# Replace resources location
sed -i 's,resources=\./resources,resources=/usr/share/games/openmw/resources,' openmw.cfg || exit 1

install -d -m755 "$pkgdir"/etc/openmw
install -m644 openmw.cfg "$pkgdir"/etc/openmw/
install -m644 settings-default.cfg "$pkgdir"/etc/openmw/
install -m644 transparency-overrides.cfg "$pkgdir"/etc/openmw/

# Desktop file and icon
install -d -m755 "$pkgdir"/usr/share/applications
install -m644 openmw.desktop "$pkgdir"/usr/share/applications/

install -d -m755 "$pkgdir"/usr/share/pixmaps
install -m644 files/launcher/images/openmw.png "$pkgdir"/usr/share/pixmaps/

# Resources
install -d -m755 "$pkgdir"/usr/share/games/openmw
cp -r resources "$pkgdir"/usr/share/games/openmw/ || exit 1

# Custom Licences
install -d -m755 "$pkgdir"/usr/share/licenses/openmw
install -D -m644 "DejaVu Font License.txt" "$pkgdir/usr/share/licenses/openmw/"
install -D -m644 "Daedric Font License.txt" "$pkgdir/usr/share/licenses/openmw/"
install -D -m644 "OFL.txt" "$pkgdir/usr/share/licenses/openmw/"
install -D -m644 "extern/shiny/License.txt" "$pkgdir/usr/share/licenses/openmw/Shiny License.txt"
}