### this file is sourced not run
PKGVER=2.22
PKGBUILD=1
PKGARCH=i686

# source: james
TARBALL=wine-$PKGVER.tar.xz
MD5SUM=5e9cd8389fe36fac8910e6a17e040fd7
SRC_URL=https://dl.winehq.org/wine/source/2.x/$TARBALL
BUNDLE=

# wine extras
WINE_GECKO_PREFIX=http://dl.winehq.org/wine/wine-gecko/2.47
WINE_GECKO=wine_gecko-2.47-x86.msi
WINE_GECKO_MD5=5ebc4ec71c92b3db3d84b334a1db385d
WINE_GECKO64=wine_gecko-2.47-x86_64.msi
WINE_GECKO64_MD5=d93ac0d2e6aceafe9113a9918916df45

WINE_MONO_PREFIX=http://dl.winehq.org/wine/wine-mono/4.7.1
WINE_MONO=wine-mono-4.7.1.msi
WINE_MONO_MD5=844ae4134e6df71f23dbb222076c37a6

SLACKREQ='mpg123 libtiff libpng libjpeg-turbo fontconfig
gstreamer2 lcms2 freetype2 libgphoto2 sane-backend dbus 
mesa libgnutls libxml2 libxslt openal libtasn1 libpcap
mpg123_32 libtiff32 libpng32 libjpeg-turbo32 fontconfig32
gstreamer2_32 lcms2_32 freetype2_32 libgphoto2_32 sane-backend32 dbus32
mesa32 libgnutls32 libxml2_32 libxslt32 openal32 libtasn1_32 libpcap32' 
SLACKDESC="wine: wine $PKGVER (WINE is Not Emulator)
wine: 
wine: Wine enables Linux, Mac, FreeBSD, and Solaris users to run Windows 
wine: applications without a copy of Microsoft Windows. This package 
wine: supports running 32-bit and 64-bit Windows programs.
wine: 
wine: https://wiki.winehq.org/Main_Page
wine: 
wine: 
wine: 
wine: 
"

### wine build config
PKG_NOSTRIP=yes # stripping will kill it (remove some needed info from DLLs)
WINE_ROOT=/opt/wine-$PKGVER
#WINE_ROOT=/usr # if you enable this, make sure you fix the shims

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	TARBALL=$WINE_GECKO SRC_URL=$WINE_GECKO_PREFIX/$WINE_GECKO MD5SUM=$WINE_GECKO_MD5 &&
	pkg_check $SRC_DIR $TARBALL $MD5SUM &&
	TARBALL=$WINE_GECKO64 SRC_URL=$WINE_GECKO_PREFIX/$WINE_GECKO64 MD5SUM=$WINE_GECKO64_MD5 &&
	pkg_check $SRC_DIR $TARBALL $MD5SUM &&
	TARBALL=$WINE_MONO SRC_URL=$WINE_MONO_PREFIX/$WINE_MONO MD5SUM=$WINE_MONO_MD5 &&
	pkg_check $SRC_DIR $TARBALL $MD5SUM
}

### package
pkg_package() {
	# add gecko and mono
	mkdir -p ./$WINE_ROOT/share/wine/gecko ./$WINE_ROOT/share/wine/mono usr/bin &&
	cp $SRC_DIR/$WINE_GECKO $SRC_DIR/$WINE_GECKO64 ./$WINE_ROOT/share/wine/gecko &&
	cp $SRC_DIR/$WINE_MONO ./$WINE_ROOT/share/wine/mono &&
	if ! [ -e usr/bin/wine ]; then
		ln -sfv $WINE_ROOT/bin/wine usr/bin/wine
	fi
	wget -O ./usr/bin/winetricks https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks &&
	chmod +x ./usr/bin/winetricks &&
	sed -i -e "/^WINETRICKS_VERSION/ aWINESERVER=\${WINESERVER:-${WINE_ROOT}/bin/wineserver}" ./usr/bin/winetricks
}

### build
pkg_build() {
	# build dirs
	mkdir /tmp/build32 /tmp/build64

	# reset these from setup_arch_vars - let wine decide the arch to use
	unset CC CXX
	
	# build 64-bit wine first
	export USE_ARCH=64 PKG_CONFIG_PATH=/usr/lib64/pkgconfig
	cd /tmp/build64 &&
	../wine*/configure --prefix=$WINE_ROOT 	--enable-win64 &&
	make $MAKEFLAGS &&

	# build 32-bit wine
	export USE_ARCH=32 PKG_CONFIG_PATH=/usr/lib/pkgconfig	
	cd /tmp/build32 &&
	../wine*/configure --prefix=$WINE_ROOT --with-wine64=/tmp/build64 &&
	make $MAKEFLAGS &&
	
	# install 32-bit wine first
	make install &&

	# install 64-bit wine
	export USE_ARCH=64 PKG_CONFIG_PATH=/usr/lib64/pkgconfig	
	cd /tmp/build64 &&
	make install &&

	# done
	pkg_build_slackdesc &&

	# install shims
	sed -i -e "s|@WINE_ROOT|$WINE_ROOT|" /tmp/pkg/wine{,64} &&
	install -m755 /tmp/pkg/wine{,64} /usr/bin &&

	# ROX filer integration
	mkdir -p /etc/xdg/rox.sourceforge.net/MIME-types &&
	install -m755 /tmp/pkg/application_x-ms-dos-executable /etc/xdg/rox.sourceforge.net/MIME-types/ &&
	(cd /etc/xdg/rox.sourceforge.net/MIME-types/ &&
	 ln -sf application_x-ms-dos-executable application_x-msi &&
	 ln -sf application_x-ms-dos-executable application_x-ms-shortcut &&
	 ln -sf application_x-ms-dos-executable application_x-ole-storage
	) &&

	# install recommended system commands, symlinking to apploader script
	# cf. https://wiki.winehq.org/Packaging#Wine_Components	
	install -m755 /tmp/build64/tools/wineapploader $WINE_ROOT/bin &&
	(cd /usr/bin &&
	 for p in regedit regsvr32 wineboot winecfg winedbg winefile winepath; do
		ln -sf $WINE_ROOT/bin/wineapploader $p || return 1
	 done
	)	
}

<< "EOF"
sh-4.3# ./configure --help
`configure' configures Wine 1.9.2 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/wine]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

X features:
  --x-includes=DIR    X include files are in DIR
  --x-libraries=DIR   X library files are in DIR

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --disable-win16         do not include Win16 support
  --enable-win64          build a Win64 emulator on AMD64 (won't run Win32
                          binaries)
  --disable-tests         do not build the regression tests
  --enable-maintainer-mode
                          enable maintainer-specific build rules
  --disable-largefile     omit support for large files

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --without-alsa          do not use the Alsa sound support
  --without-capi          do not use CAPI (ISDN support)
  --without-cms           do not use CMS (color management support)
  --without-coreaudio     do not use the CoreAudio sound support
  --without-cups          do not use CUPS
  --without-curses        do not use (n)curses
  --without-dbus          do not use DBus (dynamic device support)
  --without-fontconfig    do not use fontconfig
  --without-freetype      do not use the FreeType library
  --without-gettext       do not use gettext
  --with-gettextpo        use the GetTextPO library to rebuild po files
  --without-gphoto        do not use gphoto (Digital Camera support)
  --without-glu           do not use the GLU library
  --without-gnutls        do not use GnuTLS (schannel support)
  --without-gsm           do not use libgsm (GSM 06.10 codec support)
  --without-gstreamer     do not use GStreamer (codecs support)
  --without-hal           do not use HAL (dynamic device support)
  --without-jpeg          do not use JPEG
  --without-ldap          do not use LDAP
  --without-mpg123        do not use the mpg123 library
  --without-netapi        do not use the Samba NetAPI library
  --without-openal        do not use OpenAL
  --without-opencl        do not use OpenCL
  --without-opengl        do not use OpenGL
  --without-osmesa        do not use the OSMesa library
  --without-oss           do not use the OSS sound support
  --without-pcap          do not use the Packet Capture library
  --without-png           do not use PNG
  --without-pthread       do not use the pthread library
  --without-pulse         do not use PulseAudio sound support
  --without-sane          do not use SANE (scanner support)
  --without-tiff          do not use TIFF
  --without-v4l           do not use v4l1 (v4l support)
  --without-xcomposite    do not use the Xcomposite extension
  --without-xcursor       do not use the Xcursor extension
  --without-xinerama      do not use Xinerama (multi-monitor support)
  --without-xinput        do not use the Xinput extension
  --without-xinput2       do not use the Xinput 2 extension
  --without-xml           do not use XML
  --without-xrandr        do not use Xrandr (resolution changes)
  --without-xrender       do not use the Xrender extension
  --without-xshape        do not use the Xshape extension
  --without-xshm          do not use XShm (shared memory extension)
  --without-xslt          do not use XSLT
  --without-xxf86vm       do not use XFree video mode extension
  --without-zlib          do not use Zlib (data compression)
  --with-wine-tools=DIR   use Wine tools from directory DIR
  --with-wine64=DIR       use the 64-bit Wine in DIR for a Wow64 build
  --with-x                use the X Window System

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CXX         C++ compiler command
  CXXFLAGS    C++ compiler flags
  CPP         C preprocessor
  XMKMF       Path to xmkmf, Makefile generator for X Window System
  XML2_CFLAGS C compiler flags for libxml-2.0, overriding pkg-config
  XML2_LIBS   Linker flags for libxml-2.0, overriding pkg-config
  XSLT_CFLAGS C compiler flags for libxslt, overriding pkg-config
  XSLT_LIBS   Linker flags for libxslt, overriding pkg-config
  DBUS_CFLAGS C compiler flags for dbus-1, overriding pkg-config
  DBUS_LIBS   Linker flags for dbus-1, overriding pkg-config
  HAL_CFLAGS  C compiler flags for hal, overriding pkg-config
  HAL_LIBS    Linker flags for hal, overriding pkg-config
  GNUTLS_CFLAGS
              C compiler flags for gnutls, overriding pkg-config
  GNUTLS_LIBS Linker flags for gnutls, overriding pkg-config
  SANE_CFLAGS C compiler flags for libsane, overriding pkg-config
  SANE_LIBS   Linker flags for libsane, overriding pkg-config
  GPHOTO2_CFLAGS
              C compiler flags for libgphoto2, overriding pkg-config
  GPHOTO2_LIBS
              Linker flags for libgphoto2, overriding pkg-config
  GPHOTO2_PORT_CFLAGS
              C compiler flags for libgphoto2_port, overriding pkg-config
  GPHOTO2_PORT_LIBS
              Linker flags for libgphoto2_port, overriding pkg-config
  LCMS2_CFLAGS
              C compiler flags for lcms2, overriding pkg-config
  LCMS2_LIBS  Linker flags for lcms2, overriding pkg-config
  FREETYPE_CFLAGS
              C compiler flags for freetype2, overriding pkg-config
  FREETYPE_LIBS
              Linker flags for freetype2, overriding pkg-config
  PULSE_CFLAGS
              C compiler flags for libpulse, overriding pkg-config
  PULSE_LIBS  Linker flags for libpulse, overriding pkg-config
  GSTREAMER_CFLAGS
              C compiler flags for gstreamer-1.0 gstreamer-video-1.0
              gstreamer-audio-1.0, overriding pkg-config
  GSTREAMER_LIBS
              Linker flags for gstreamer-1.0 gstreamer-video-1.0
              gstreamer-audio-1.0, overriding pkg-config
  CAPI20_CFLAGS
              C compiler flags for capi20, overriding pkg-config
  CAPI20_LIBS Linker flags for capi20, overriding pkg-config
  FONTCONFIG_CFLAGS
              C compiler flags for fontconfig, overriding pkg-config
  FONTCONFIG_LIBS
              Linker flags for fontconfig, overriding pkg-config
  JPEG_CFLAGS C compiler flags for libjpeg, overriding pkg-config
  JPEG_LIBS   Linker flags for libjpeg, overriding pkg-config
  PNG_CFLAGS  C compiler flags for libpng, overriding pkg-config
  PNG_LIBS    Linker flags for libpng, overriding pkg-config
  TIFF_CFLAGS C compiler flags for libtiff-4, overriding pkg-config
  TIFF_LIBS   Linker flags for libtiff-4, overriding pkg-config
  MPG123_CFLAGS
              C compiler flags for libmpg123, overriding pkg-config
  MPG123_LIBS Linker flags for libmpg123, overriding pkg-config

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to <wine-devel@winehq.org>.
Wine home page: <http://www.winehq.org>.
EOF
