# Template file for 'wine'
pkgname=wine
version=1.7.48
revision=1
build_style=gnu-configure
configure_args="--without-gstreamer"
short_desc="Run Microsoft Windows applications"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
license="LGPL-2.1"
homepage="http://www.winehq.org/"
#distfiles="${SOURCEFORGE_SITE}/${pkgname}/${pkgname}-${version}.tar.bz2" # Not working right now
distfiles="http://mirrors.ibiblio.org/wine/source/1.7/$pkgname-$version.tar.bz2"
checksum=e3f55ce56e2092d49b317fea8802e314be2b2170fd434f5e45f7141773946c8e

lib32mode=full
only_for_archs=i686

hostmakedepends="pkg-config flex prelink"
makedepends="gettext-devel lcms2-devel zlib-devel ncurses-devel
 glu-devel libSM-devel libXext-devel libX11-devel libXpm-devel
 libXinerama-devel libXcomposite-devel libXmu-devel libXxf86vm-devel
 libXcursor-devel libXrandr-devel libXdamage-devel libXi-devel
 libldap-devel alsa-lib-devel libgphoto2-devel libxml2-devel
 libxslt-devel glib-devel freetype-devel
 mpg123-devel libgsm-devel libopenal-devel giflib-devel libpng-devel
 v4l-utils-devel fontconfig-devel gnutls-devel dbus-devel sane-devel
 libpcap-devel cups-devel dbus-devel ocl-icd-devel"
depends="libXi libXinerama libXcomposite libXcursor libOSMesa
 desktop-file-utils hicolor-icon-theme liberation-fonts-ttf"

binfmts="/usr/bin/wine --magic MZ"

build_options="staging d3d9"
desc_option_staging="Enable wine-staging patchset"
desc_option_d3d9="Enable d3d9 state tracker patchset"
build_options_default="staging"

if [ ${build_option_staging} ] || [ ${build_option_d3d9} ]; then
	hostmakedepends+=" automake"
fi

if [ ${build_option_staging} ]; then
	makedepends+=" pulseaudio-devel libva-devel"
	distfiles+=" https://github.com/wine-compholio/${pkgname}-staging/archive/v${version}.tar.gz"
	checksum+=" 66d264eb75edc40d7b42f0f49681878c0cb510451b4e0da858881c4d71896d22"
fi

if [ ${build_option_d3d9} ]; then
	distfiles+=" https://github.com/NP-Hardass/wine-d3d9-patches/archive/wine-d3d9-${version}.tar.gz"
	checksum+=" b9dafc22e86b880c4cb08e3635ef4ea8657489be238373fb01d3f85c8b864446"
	configure_args+=" --with-d3dadapter"
fi

post_extract() {
	if [ ${build_option_d3d9} ]; then
		patch -p1 < ${XBPS_BUILDDIR}/wine-d3d9-patches-wine-d3d9-${version}/wine-d3d9.patch
		autoreconf -f
	fi
	if [ ${build_option_staging} ]; then
		cd ${XBPS_BUILDDIR}/${pkgname}-staging-${version}/patches/
		DESTDIR="$wrksrc" ./patchinstall.sh --all
	fi
}

post_install() {
	# Font aliasing settings for Win32 applications
	install -d ${DESTDIR}/etc/fonts/conf.{avail,d}
	install -m644 ${FILESDIR}/30-win32-aliases.conf ${DESTDIR}/etc/fonts/conf.avail
	ln -s ../conf.avail/30-win32-aliases.conf ${DESTDIR}/etc/fonts/conf.d/30-win32-aliases.conf
}

libwine_package() {
	lib32mode=full
	short_desc+=" - Runtime library"
	replaces="libwine-unstable>=0"
	pkg_install() {
		vmove "usr/lib/*.so.*"
		vmove usr/lib/wine
	}
}
wine-devel_package() {
	depends="libwine-${version}_${revision}"
	short_desc+=" - development files"
	replaces="wine-unstable-devel>=0"
	pkg_install() {
		vmove usr/include
		vmove "usr/lib/*.so"
	}
}
