# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Jonathan Liu <net147@gmail.com>

_realname=wine
pkgbase=mingw-w64-wined3d
pkgname="${MINGW_PACKAGE_PREFIX}-wined3d"
pkgver=3.8
pkgrel=3
pkgdesc="Direct3D to OpenGL translator (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
url="https://www.winehq.org"
license=('LGPL')
options=('staticlibs' 'strip')
source=(https://prdownloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.xz{.sign,})
sha256sums=('SKIP'
            '02b00c6c948b3bab717e1b1e2075a5406b14d138bd2e01fdb1268a93d1c20d51')
validpgpkeys=('DA23579A74D4AD9AF9D3F945CEFAC8EAAF17519D')

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  cp -rf "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  case ${MINGW_CHOST} in
    i686*)
      _extra=
    ;;
    x86_64*)
      _extra="--enable-win64"
    ;;
  esac

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --disable-tests \
    --without-alsa \
    --without-capi \
    --without-coreaudio \
    --without-cups \
    --without-curses \
    --without-dbus \
    --without-fontconfig \
    --without-freetype \
    --without-gettext \
    --without-gphoto \
    --with-glu \
    --without-gnutls \
    --without-gsm \
    --without-gstreamer \
    --without-hal \
    --without-jpeg \
    --without-ldap \
    --without-mpg123 \
    --without-netapi \
    --without-openal \
    --without-opencl \
    --with-opengl \
    --without-osmesa \
    --without-oss \
    --without-png \
    --with-pthread \
    --without-sane \
    --without-tiff \
    --without-v4l \
    --without-xcomposite \
    --without-xcursor \
    --without-xinerama \
    --without-xinput \
    --without-xinput2 \
    --without-xml \
    --without-xrandr \
    --without-xrender \
    --without-xshape \
    --without-xshm \
    --without-xslt \
    --without-xxf86vm \
    --without-zlib \
    --without-x \
    $_extra \
    CFLAGS="-O2 -DUSE_WIN32_OPENGL -DWINE_NOWINSOCK -fcommon"

  make LN_S='ln -s' dlls/d3d8 dlls/d3d9 dlls/d3d10 dlls/d3d10core dlls/dxgi dlls/wined3d
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin
  local _dll_files=( $(find "${srcdir}"/build-${MSYSTEM} -type f -name "*.dll") )
  cp -f ${_dll_files[@]} ${pkgdir}${MINGW_PREFIX}/bin/
}
