From 369f3e155d53cd137b1a67bc45c346e3f6c38f3e Mon Sep 17 00:00:00 2001
From: "A. Wilcox" <AWilcox@Wilcox-Tech.com>
Date: Sat, 23 Jul 2022 02:46:59 -0500
Subject: user/wine: Update to 7.0 (WIP)

---
 user/wine/APKBUILD            | 79 +++++++++++++------------------------------
 user/wine/dlclose.patch       | 66 ------------------------------------
 user/wine/headers.patch       | 24 +++++++++++++
 user/wine/no-pie.patch        | 11 ------
 user/wine/printer.patch       |  6 ++--
 user/wine/rpath.patch         | 11 ++++++
 user/wine/winhlp32-flex.patch |  9 -----
 7 files changed, 61 insertions(+), 145 deletions(-)
 delete mode 100644 user/wine/dlclose.patch
 create mode 100644 user/wine/headers.patch
 delete mode 100644 user/wine/no-pie.patch
 create mode 100644 user/wine/rpath.patch
 delete mode 100644 user/wine/winhlp32-flex.patch

diff --git a/user/wine/APKBUILD b/user/wine/APKBUILD
index 87590ebb9..2e356df60 100644
--- a/user/wine/APKBUILD
+++ b/user/wine/APKBUILD
@@ -4,29 +4,27 @@
 # Contributor: Martell Malone <martell@marinelayer.io>
 # Maintainer: A. Wilcox <awilfox@adelielinux.org>
 pkgname=wine
-pkgver=4.0.1
+pkgver=7.0
 pkgrel=0
-pkgdesc="A compatibility layer for running Windows programs"
-url="http://www.winehq.com"
+pkgdesc="Compatibility layer for running Windows programs"
+url="https://www.winehq.org/"
 arch="pmmx x86 x86_64"
-license="LGPL-2.0|"
-# As of 2.0.3 most of the tests fails
+license="LGPL-2.0+"
 options="!check"
-subpackages="$pkgname-libs $pkgname-dev $pkgname-doc"
+depends=""
 depends_dev="$pkgname perl"
-makedepends="fontconfig-dev openldap-dev libxslt-dev libxxf86dga-dev
-	libxcursor-dev libxrandr-dev libxdamage-dev mesa-dev flex-dev bison
-	libpng-dev libjpeg-turbo-dev freetype-dev ncurses-dev openssl-dev
-	libxcomposite-dev libxrender-dev libxinerama-dev zlib-dev
-	cups-dev alsa-lib-dev libxml2-dev dbus-dev libxi-dev
-	gnutls-dev tiff-dev v4l-utils-dev udisks2-dev autoconf automake
-	openal-soft-dev pulseaudio-dev sane-dev eudev-dev mpg123-dev
-	autoconf automake libtool"
+makedepends="fontconfig-dev freetype-dev ncurses-dev openldap-dev openssl-dev
+	libxcomposite-dev libxcursor-dev libxext-dev libxfixes-dev libxi-dev
+	libxinerama-dev libxrandr-dev libxrender-dev libxxf86dga-dev mesa-dev
+	alsa-lib-dev cups-dev dbus-dev eudev-dev gnutls-dev openal-soft-dev
+	pulseaudio-dev sane-dev udisks2-dev unixodbc-dev v4l-utils-dev
+	gstreamer-dev krb5-dev libgphoto2-dev libusb-dev bison flex
+	autoconf automake libtool gst-plugins-base-dev"
+subpackages="$pkgname-dev $pkgname-doc"
 source="http://dl.winehq.org/$pkgname/source/${pkgver%.[1-9]}/$pkgname-$pkgver.tar.xz
-	dlclose.patch
-	no-pie.patch
+	headers.patch
 	printer.patch
-	winhlp32-flex.patch
+	rpath.patch
 	"
 
 prepare() {
@@ -36,7 +34,7 @@ prepare() {
 
 build() {
 	case "$CARCH" in
-		x86_64) _win64=--enable-win64;;
+		x86_64) _win64=--enable-win64; _ldrsuffix=64;;
 	esac
 	./configure \
 		--build=$CBUILD \
@@ -46,24 +44,21 @@ build() {
 		--sysconfdir=/etc \
 		--localstatedir=/var \
 		--with-cups \
-		--with-curses \
 		--with-dbus \
 		--with-fontconfig \
 		--with-freetype \
-		--with-jpeg \
-		--with-mpg123 \
 		--with-openal \
 		--with-opengl \
-		--with-png \
 		--with-pulse \
 		--with-sane \
 		--with-udev \
-		--with-va \
 		--with-x \
 		--with-xcomposite \
 		--with-xinerama \
-		--with-xslt \
 		$_win64
+	make LDFLAGS="$LDFLAGS -no-pie" \
+		tools/{widl/widl,winebuild/winebuild,winegcc/winegcc,wrc/wrc} \
+		loader/wine$_ldrsuffix loader/wine${_ldrsuffix}-preloader server/wineserver
 	make
 }
 
@@ -74,11 +69,6 @@ check() {
 package() {
 	make -j1 DESTDIR="$pkgdir" install
 
-	case "$CARCH" in
-		x86_64) _wine="wine64";;
-		*) _wine="wine";;
-	esac
-
 	install -Dm755 tools/wineapploader \
 		"$pkgdir"/usr/bin/wineapploader
 
@@ -97,32 +87,9 @@ dev() {
 		 winedbg winemaker winegcc winecpp wineg++; do
 		mv "$pkgdir"/usr/bin/$file "$subpkgdir"/usr/bin/
 	done
-
-	install -d "$subpkgdir"/usr/lib/wine
-	mv "$pkgdir"/usr/lib/wine/*.def "$subpkgdir"/usr/lib/wine/
-}
-
-doc() {
-	default_doc
-	rm -fr "$subpkgdir"/usr/share/man/*.UTF-8
-}
-
-libs() {
-	default_libs
-
-	install -d "$subpkgdir"/usr/lib/wine/fakedlls
-	for ext in dll16 drv16 exe16 acm dll drv ds ocx sys tlb vxd; do
-		for file in $(find "$pkgdir/usr/lib/wine/fakedlls" -name "*.$ext"); do
-			mv "$pkgdir"/usr/lib/wine/fakedlls/${file##*/} \
-				"$subpkgdir"/usr/lib/wine/fakedlls/
-			mv "$pkgdir"/usr/lib/wine/${file##*/}.so \
-				"$subpkgdir"/usr/lib/wine/
-		done
-	done
 }
 
-sha512sums="dd240525e389f841123a569fd2f9b8da698b7707bc0de408dfd60ae73c5e24d522abb42b76571c840df52c686fdeae56e0a9c69db2cd31f04cdb345feeacf1dc  wine-4.0.1.tar.xz
-7e68ffc953f8858538b03d79b78b53b46e33dc01a474cf2eadaa726ff04918eb8675e80da1c82d2d61b12753f10fd6eda9114c5bc263fe373b6900f174bc246f  dlclose.patch
-a96b1e248447912ba522067b67fc920063f355f326eaf3fec760c79a1c6e46019fbdcfa8b95b9d389959a7e3d3ab794f9aaf78913ad6a73be32b5d34ca8a2267  no-pie.patch
-05dcc931a3bf5569f0314e3ede9df11a6f2a5806ed9ed66da094f3ee811af316046f177d5190c09007227a455e402b4dc747098fc82cd410574fb241cc5d53ba  printer.patch
-522a94a31fc459e80ea7dd05f7aee64f6ae666ec05236d06614acde118d5c60002e0f253ae75edb5f02164f22937ca89578504b690d1a5611bd60f703c8f0c00  winhlp32-flex.patch"
+sha512sums="eec17b046ed5447eb540f421c9b2748d9419ce087496c2743a9914fd27bbe5ff9da0cfe47d3cd76fa97323bd1188a1d82b1eef4968d86ed1957dc1a95e28529c  wine-7.0.tar.xz
+04b4035ad7db762bf965bce095457be9e96292a799c4443c9b93fd572e49371a4bfe297bc3cf720c1e1f7338585767309ec9d84e83db64109883c1782cef40ba  headers.patch
+26c72d45329eaf6f0f361edf08a2984ecc99d892bff3d0932928514db5882bebd5744627aa3a63f0715fc308e12364879356d5e94b334d7c6dc9ea3ff854e423  printer.patch
+ade85bee3df634bfb69ae6a27f262708c68c0f9b7be894b44c17fdf14ce5fe8093b1ce2eb7ecca2ca245d9f9b7a1e62ff061449e44acb277c1f03a44449d5191  rpath.patch"
diff --git a/user/wine/dlclose.patch b/user/wine/dlclose.patch
deleted file mode 100644
index a9844ff68..000000000
--- a/user/wine/dlclose.patch
+++ /dev/null
@@ -1,66 +0,0 @@
---- a/configure.ac
-+++ b/configure.ac
-@@ -1123,6 +1123,12 @@ then
- 
-     dnl *** End of X11/Xlib.h check
- 
-+    dnl Check for the unload_after_dlclose libc
-+    AC_RUN_IFELSE(
-+	      [AC_LANG_PROGRAM([[#include <dlfcn.h>]], [[dlclose(dlopen("./conftest", 0)); return 0;]])],
-+	      ac_save_CPPFLAGS="$ac_save_CPPFLAGS -DNO_UNLOAD_AFTER_DLCLOSE",
-+	      [])
-+
-     dnl Check for the presence of OpenGL
-     opengl_msg=""
-     if test "x$with_opengl" != "xno"
---- a/dlls/ntdll/loader.c
-+++ b/dlls/ntdll/loader.c
-@@ -2289,6 +2289,13 @@ 
-             if (mod->Flags & LDR_WINE_INTERNAL && mod->SectionHandle == handle)
-             {
-                 info.wm = CONTAINING_RECORD(mod, WINE_MODREF, ldr);
-+#ifdef NO_UNLOAD_AFTER_DLCLOSE
-+                if (info.wm->ldr.LoadCount == 0) {
-+                    RtlEnterCriticalSection( &loader_section );
-+                    info.wm->ldr.LoadCount = 1;
-+                    RtlLeaveCriticalSection( &loader_section );
-+                }
-+#endif
-                 TRACE( "Found %s at %p for builtin %s\n",
-                        debugstr_w(info.wm->ldr.FullDllName.Buffer), info.wm->ldr.BaseAddress, debugstr_w(path) );
-                 break;
-@@ -3199,6 +3199,9 @@ 
-  *		LdrShutdownProcess (NTDLL.@)
-  *
-  */
-+#ifdef NO_UNLOAD_AFTER_DLCLOSE
-+static void MODULE_FlushModrefs(void);
-+#endif
- void WINAPI LdrShutdownProcess(void)
- {
-     TRACE("()\n");
-@@ -3194,6 +3203,12 @@ 
-     TRACE("()\n");
-+#ifdef NO_UNLOAD_AFTER_DLCLOSE
-+    RtlEnterCriticalSection( &loader_section );
-+    process_detach();
-+    MODULE_FlushModrefs();
-+    RtlLeaveCriticalSection( &loader_section );
-+#endif
-     process_detaching = TRUE;
-     process_detach();
- }
- 
- 
-@@ -3384,7 +3398,11 @@ 
-         if ( free_lib_count <= 1 )
-         {
-+#ifdef NO_UNLOAD_AFTER_DLCLOSE
-+            TRACE("apply no-op dlclose hacks on this platform\n");
-+#else
-             process_detach();
-             MODULE_FlushModrefs();
-+#endif
-         }
- 
-         TRACE("END\n");
diff --git a/user/wine/headers.patch b/user/wine/headers.patch
new file mode 100644
index 000000000..73ca8c7db
--- /dev/null
+++ b/user/wine/headers.patch
@@ -0,0 +1,24 @@
+These are needed for musl/POSIX.
+
+--- a/dlls/winebus.sys/bus_udev.c	2021-10-23 15:38:33.225064731 +0200
++++ b/dlls/winebus.sys/bus_udev.c	2021-10-23 15:39:06.662064765 +0200
+@@ -29,7 +29,8 @@
+ #include <stdlib.h>
+ #include <stdio.h>
+ #include <stdint.h>
+-#include <sys/types.h>
++#include <sys/types.h>
++#include <limits.h>
+ #include <dirent.h>
+ #ifdef HAVE_UNISTD_H
+ # include <unistd.h>
+--- a/server/security.h	2022-01-29 08:23:43.759508270 +0100
++++ b/server/security.h	2022-01-29 08:24:07.976443565 +0100
+@@ -22,6 +22,7 @@
+ #define __WINE_SERVER_SECURITY_H
+ 
+ #include <sys/types.h>
++#include <unistd.h>
+ 
+ extern const struct luid SeIncreaseQuotaPrivilege;
+ extern const struct luid SeSecurityPrivilege;
diff --git a/user/wine/no-pie.patch b/user/wine/no-pie.patch
deleted file mode 100644
index 2874e0af8..000000000
--- a/user/wine/no-pie.patch
+++ /dev/null
@@ -1,11 +0,0 @@
---- wine-4.0.1/configure.ac
-+++ wine-4.0.1/configure.ac
-@@ -955,7 +955,7 @@
- 
-       WINE_TRY_CFLAGS([-fPIC -Wl,--export-dynamic],
-                       [WINELOADER_LDFLAGS="-Wl,--export-dynamic"])
--      WINEPRELOADER_LDFLAGS="-static -nostartfiles -nodefaultlibs -Wl,-Ttext=0x7c400000"
-+      WINEPRELOADER_LDFLAGS="-static -nostartfiles -nodefaultlibs -Wl,-Ttext=0x7c400000 -no-pie"
- 
-       WINE_TRY_CFLAGS([-fPIC -Wl,--rpath,\$ORIGIN/../lib],
-                       [LDRPATH_INSTALL="-Wl,--rpath,\\\$\$ORIGIN/\`\$(MAKEDEP) -R \${bindir} \${libdir}\`"
diff --git a/user/wine/printer.patch b/user/wine/printer.patch
index 4910e4726..6ccfab003 100644
--- a/user/wine/printer.patch
+++ b/user/wine/printer.patch
@@ -2,12 +2,12 @@
  1 file changed, 1 insertion(+)
 --- a/dlls/winspool.drv/info.c	
 +++ a/dlls/winspool.drv/info.c	
-@@ -1620,6 +1620,7 @@ void WINSPOOL_LoadSystemPrinters(void)
- #endif
+@@ -1136,6 +1136,7 @@ void WINSPOOL_LoadSystemPrinters(void)
+     WCHAR               PrinterName[256];
  
      /* FIXME: The init code should be moved to spoolsv.exe */
 +    SetLastError(0);
-     init_mutex = CreateMutexW( NULL, TRUE, winspool_mutex_name );
+     init_mutex = CreateMutexW( NULL, TRUE, L"__WINE_WINSPOOL_MUTEX__" );
      if (!init_mutex)
      {
 -- 
diff --git a/user/wine/rpath.patch b/user/wine/rpath.patch
new file mode 100644
index 000000000..9f65cf034
--- /dev/null
+++ b/user/wine/rpath.patch
@@ -0,0 +1,11 @@
+--- a/configure.ac
++++ b/configure.ac
+@@ -859,6 +859,9 @@ case $host_os in
+     AC_SUBST(LIBWINE_SHAREDLIB,"libwine.so.$libwine_version")
+     AC_SUBST(LIBWINE_DEPENDS,"wine.map")
+     TOP_INSTALL_LIB="$TOP_INSTALL_LIB libs/wine/libwine.so.$libwine_version libs/wine/libwine.so.$libwine_soversion"
++
++    # do this at the end because it needs double dollar for makefile
++    WINE_TRY_CFLAGS([-Wl,-rpath,\\\$ORIGIN],[UNIXLDFLAGS="$UNIXLDFLAGS '-Wl,-rpath,\$\$ORIGIN'"])
+     ;;
+ esac
diff --git a/user/wine/winhlp32-flex.patch b/user/wine/winhlp32-flex.patch
deleted file mode 100644
index daeb790c2..000000000
--- a/user/wine/winhlp32-flex.patch
+++ /dev/null
@@ -1,9 +0,0 @@
---- a/programs/winhlp32/Makefile.in
-+++ b/programs/winhlp32/Makefile.in
-@@ -1,5 +1,5 @@
- MODULE    = winhlp32.exe
--APPMODE   = -mwindows
-+APPMODE   = -mwindows -lfl
- IMPORTS   = user32 gdi32
- DELAYIMPORTS = shell32 comctl32 comdlg32
- 
-- 
cgit v1.2.3-70-g09d2