Skip to content

Instantly share code, notes, and snippets.

@shkhln
Last active March 8, 2022 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shkhln/e39432d8b5f8d62da9b7d55aad641ddd to your computer and use it in GitHub Desktop.
Save shkhln/e39432d8b5f8d62da9b7d55aad641ddd to your computer and use it in GitHub Desktop.
diff --git a/emulators/wine-devel/Makefile b/emulators/wine-devel/Makefile
index 8cffa314355f..9da71b58d417 100644
--- a/emulators/wine-devel/Makefile
+++ b/emulators/wine-devel/Makefile
@@ -167,6 +167,16 @@ pre-build:
cd ${WRKSRC} && ${MAKE_CMD} depend
post-install:
+.if ${ARCH} == i386
+ ${MV} ${STAGEDIR}${PREFIX}/bin/wineserver ${STAGEDIR}${PREFIX}/bin/wineserver32
+ ${MV} ${STAGEDIR}${PREFIX}/bin/wine ${STAGEDIR}${PREFIX}/bin/.wine32
+ ${INSTALL_SCRIPT} ${FILESDIR}/wine-i386.sh ${STAGEDIR}${PREFIX}/bin/wine
+.else
+ ${MV} ${STAGEDIR}${PREFIX}/bin/wine64 ${STAGEDIR}${PREFIX}/bin/.wine64
+ ${INSTALL_SCRIPT} ${FILESDIR}/wine64.sh ${STAGEDIR}${PREFIX}/bin/wine64
+ ${INSTALL_SCRIPT} ${FILESDIR}/wine-amd64.sh ${STAGEDIR}${PREFIX}/bin/wine
+ ${INSTALL_SCRIPT} ${FILESDIR}/pkg32.sh ${STAGEDIR}${DATADIR}/pkg32.sh
+.endif
@${MV} -f ${STAGEDIR}${WINELIBDIR}/libwine.so.1.0 \
${STAGEDIR}${WINELIBDIR}/libwine.so.1
@${LN} -sf libwine.so.1 ${STAGEDIR}/${WINELIBDIR}/libwine.so
diff --git a/emulators/wine-devel/files/pkg32.sh b/emulators/wine-devel/files/pkg32.sh
new file mode 100755
index 000000000000..a47e9e0c3c97
--- /dev/null
+++ b/emulators/wine-devel/files/pkg32.sh
@@ -0,0 +1,14 @@
+#!/bin/sh -e
+
+if [ `id -u` = '0' ]
+then
+ echo "Don't run this script as root!"
+ exit 1
+fi
+
+I386_ROOT="${WINE_i386_ROOT:-$HOME/.i386-wine-pkg}"
+
+mkdir -p "$I386_ROOT"
+ABI=`pkg config ABI | sed s/amd64/i386/`
+echo pkg -o ABI=$ABI -o INSTALL_AS_USER=true -o RUN_SCRIPTS=false --rootdir "$I386_ROOT" "$@"
+exec pkg -o ABI=$ABI -o INSTALL_AS_USER=true -o RUN_SCRIPTS=false --rootdir "$I386_ROOT" "$@"
diff --git a/emulators/wine-devel/files/wine-amd64.sh b/emulators/wine-devel/files/wine-amd64.sh
new file mode 100755
index 000000000000..6e2ec7b079b3
--- /dev/null
+++ b/emulators/wine-devel/files/wine-amd64.sh
@@ -0,0 +1,32 @@
+#!/bin/sh -e
+TARGET="`realpath $0`"
+
+I386_ROOT="${WINE_i386_ROOT:-$HOME/.i386-wine-pkg}"
+LOCALBASE=/usr/local
+
+export LIBGL_DRIVERS_PATH="${LIBGL_DRIVERS_PATH:+$LIBGL_DRIVERS_PATH:}$LOCALBASE/lib/dri:$LOCALBASE/lib32/dri:$I386_ROOT/$LOCALBASE/lib/dri"
+export LD_32_LIBRARY_PATH="${LD_32_LIBRARY_PATH:+$LD_32_LIBRARY_PATH:}$I386_ROOT/$LOCALBASE/lib/wine:$LOCALBASE/lib32:$I386_ROOT/$LOCALBASE/lib"
+export LD_32_LIBRARY_PATH_RPATH=y
+
+if [ ! -f "$I386_ROOT/$LOCALBASE/bin/wine" ]
+then
+ printf "%s doesn't exist!\n\n" "$I386_ROOT/$LOCALBASE/bin/wine"
+ printf "Try installing 32-bit wine with\n\t%s\n" "$LOCALBASE/share/wine/pkg32.sh install wine-devel mesa-dri"
+ exit 1
+fi
+
+if [ -z "$WINE_NO_WOW64" ] && [ -z "$WINELOADERNOEXEC" ]
+then
+ export WINESERVER="${TARGET}server"
+
+ WINE32_VERSION=`"$I386_ROOT/$LOCALBASE/bin/wine" --version`
+ WINE64_VERSION=`"${TARGET}64" --version`
+ if [ "$WINE32_VERSION" != "$WINE64_VERSION" ]
+ then
+ printf "wine [%s] and wine64 [%s] versions do not match!\n\n" "$WINE32_VERSION" "$WINE64_VERSION"
+ printf "Try updating 32-bit wine with\n\t%s\n" "$LOCALBASE/share/wine/pkg32.sh upgrade"
+ exit 1
+ fi
+fi
+
+exec "$I386_ROOT/$LOCALBASE/bin/wine" "$@"
diff --git a/emulators/wine-devel/files/wine-i386.sh b/emulators/wine-devel/files/wine-i386.sh
new file mode 100755
index 000000000000..5a4c9bcd1183
--- /dev/null
+++ b/emulators/wine-devel/files/wine-i386.sh
@@ -0,0 +1,9 @@
+#!/bin/sh -e
+TARGET="`realpath $0`"
+
+# workaround for https://bugs.winehq.org/show_bug.cgi?id=50257
+export LD_BIND_NOW=1
+export LD_32_BIND_NOW=1
+
+export WINESERVER=${WINESERVER:-${TARGET}server32}
+exec "${TARGET%/*}/.${TARGET##*/}32" "$@"
diff --git a/emulators/wine-devel/files/wine64.sh b/emulators/wine-devel/files/wine64.sh
new file mode 100755
index 000000000000..4202635a90fc
--- /dev/null
+++ b/emulators/wine-devel/files/wine64.sh
@@ -0,0 +1,5 @@
+#!/bin/sh -e
+TARGET="`realpath $0`"
+# workaround for https://bugs.winehq.org/show_bug.cgi?id=50257
+export LD_BIND_NOW=1
+exec "${TARGET%/*}/.${TARGET##*/}" "$@"
diff --git a/emulators/wine-devel/pkg-plist b/emulators/wine-devel/pkg-plist
index e31224fadf28..e099c810de6e 100644
--- a/emulators/wine-devel/pkg-plist
+++ b/emulators/wine-devel/pkg-plist
@@ -5,7 +5,9 @@ bin/notepad
bin/regedit
bin/regsvr32
bin/widl
-%%WINE32%%bin/wine
+bin/wine
+%%WINE32%%bin/.wine32
+%%WINE64%%bin/.wine64
%%WINE64%%bin/wine64
bin/wineboot
bin/winebuild
@@ -20,7 +22,8 @@ bin/winegcc
bin/winemaker
bin/winemine
bin/winepath
-bin/wineserver
+%%WINE32%%bin/wineserver32
+%%WINE64%%bin/wineserver
bin/wmc
bin/wrc
include/wine/debug.h
@@ -3487,6 +3490,7 @@ share/applications/wine.desktop
%%DATADIR%%/nls/normnfkc.nls
%%DATADIR%%/nls/normnfkd.nls
%%DATADIR%%/nls/sortdefault.nls
+%%WINE64%%%%DATADIR%%/pkg32.sh
%%PORTDOCS%%%%DOCSDIR%%/ANNOUNCE
%%PORTDOCS%%%%DOCSDIR%%/AUTHORS
%%PORTDOCS%%%%DOCSDIR%%/README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment