#Packager: Richard Lapointe <richard@laprjns.com>
#Former Packager(s): Christian Dersch <chrisdersch~at~googlemail~dot~com>
#Anything commented out is optional and can be deleted.

pkgname=wine	
pkgver=1.5.15
pkgrel=1rl
pkgbasever=${pkgver/rc/-rc}
#arch=noarch
source=("http://ibiblio.org/pub/linux/system/emulators/wine/wine-$pkgver.tar.bz2" \
		"wine.desktop" \
		"winecfg.desktop" \
		"winecfg.png")
sourcetemplate=http://people.salixos.org/laprjns/$pkgname/$pkgver/
docs=("ANNOUNCE" "COPYING.LIB" "LICENSE" "LIVENCE.OLD" "VERSION" "readme" "install" "copying" "changelog" "authors" "news" "todo")
url="http://www.winehq.com/"
#dotnew=()
#CFLAGS=
#CXXFLAGS=
#options=('noextract')

#doinst() {
#
#}

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"wine (Wine Is Not an Emulator)"
"Wine is an Open Source implementation of the Windows API on top of"
"X and Linux/Unix. It allows you to run many software for Microsoft"
"Windows (but not all)."
""
"http://www.winehq.com/"
)

cd "$srcdir"

  # Allow ccache to work
  mv $pkgname-$_pkgbasever $pkgname

  # Get rid of old build dirs
  rm -rf $pkgname-{32,64}-build
  mkdir $pkgname-32-build

  # These additional CFLAGS solve FS#27662
  export CFLAGS="${CFLAGS/-D_FORTIFY_SOURCE=2/} -D_FORTIFY_SOURCE=0"
  export CXXFLAGS="${CXXFLAGS/-D_FORTIFY_SOURCE=2/} -D_FORTIFY_SOURCE=0"

  if [[ $CARCH == x86_64 ]]; then
    msg2 "Building Wine-64..."

    mkdir $pkgname-64-build
    cd "$srcdir/$pkgname-64-build"
    ../$pkgname/configure \
      --prefix=/usr \
      --sysconfdir=/etc \
      --libdir=/usr/lib \
      --with-x \
      --enable-win64

    make

    _wine32opts=(
      --libdir=/usr/lib32
      --with-wine64="$srcdir/$pkgname-64-build"
    )

    export PKG_CONFIG_PATH="/usr/lib32/pkgconfig"
  fi

  msg2 "Building Wine-32..."
  cd "$srcdir/$pkgname-32-build"
  ../$pkgname/configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --with-x \
    "${_wine32opts[@]}"

  # These additional CFLAGS solve FS#27560 and FS#23277
  make CFLAGS+="-mstackrealign -mincoming-stack-boundary=2" CXXFLAGS+="-mstackrealign -mincoming-stack-boundary=2"
}

package() {
  msg2 "Packaging Wine-32..."
  cd "$srcdir/$pkgname-32-build"

  if [[ $CARCH == i686 ]]; then
    make prefix="$pkgdir/usr" install
  else
    make prefix="$pkgdir/usr" \
      libdir="$pkgdir/usr/lib32" \
      dlldir="$pkgdir/usr/lib32/wine" install

    msg2 "Packaging Wine-64..."
    cd "$srcdir/$pkgname-64-build"
    make prefix="$pkgdir/usr" \
      libdir="$pkgdir/usr/lib" \
      dlldir="$pkgdir/usr/lib/wine" install
  fi
}

