tce-load -lwi unixODBC-dev bash compiletc libvulkan-dev gnutls38-dev alsa-dev krb5-dev openssl-dev libpcap-dev sdl2-dev opencl-headers pcsc-lite-dev libusb-dev libsane-dev libgphoto2-dev gstreamer-dev gst-plugins-base-dev weston-dev sstrip squashfs-tools binutils coreutils python3.9 python3.9-pip ffmpeg5-dev

wine=9.21
staging=f03d32e381f829e13a82726cad521d4b1c223b10

#get wine
wget -O- --no-check-certificate https://dl.winehq.org/wine/source/9.x/wine-$wine.tar.xz | tar -xJ

#get staging
wget --no-check-certificate -O- https://codeload.github.com/wine-staging/wine-staging/zip/$staging | busybox unzip -qq -
cd wine-staging-$staging/
chmod u+x ./patches/gitapply.sh
python3.9 ./staging/patchinstall.py DESTDIR=../wine-$wine/ --all --no-autoconf \
-W eventfd_synchronization \
-W ntdll-Junction_Points \
-W ntdll-NtDevicePath \
-W ntdll_reg_flush \
-W server-File_Permissions \
-W server-Stored_ACLs \
-W user32-rawinput-mouse

cd ../wine-$wine/

#fix ca-certificates & ca-bundle location
sed -i 's#/etc/ssl/certs/ca-certificates.crt#/usr/local/etc/ssl/certs/ca-certificates.crt#' ./dlls/crypt32/unixlib.c
sed -i 's#/usr/share/ca-certificates/ca-bundle.crt#/usr/local/etc/ssl/ca-bundle.crt#' ./dlls/crypt32/unixlib.c

#get mingw for WoW64 support
wget -O- --no-check-certificate https://github.com/mstorsjo/llvm-mingw/releases/download/20231128/llvm-mingw-20231128-ucrt-ubuntu-20.04-x86_64.tar.xz | tar xJ
export PATH=$PATH:./llvm-mingw-20231128-ucrt-ubuntu-20.04-x86_64/bin/
sudo ln -s /lib /lib64

#compile
./configure --libdir=/usr/local/lib --prefix=/usr/local --localstatedir=/var --without-pulse --without-dbus --enable-archs=i386,x86_64
find . -name Makefile -type f -exec sed -i 's/-g -O2/-Os/g' {} \;

make -j8
make install DESTDIR=/tmp/wine
find /tmp/wine/ -exec strip -s {} \;
find /tmp/wine/ -exec x86_64-w64-mingw32-strip -s {} \;
#find /tmp/wine/ -exec i686-w64-mingw32-strip -s {} \;
#/\ not needed? 64bit strip seems to be stripping 32bits files

find /tmp/wine/ -iname *.a -delete
mksquashfs /tmp/wine/ wine-latest.tcz -e usr/local/bin/winegcc -e usr/local/bin/wineg++ -e usr/local/bin/winecpp -e usr/local/bin/function_grep.pl -e usr/local/include -e usr/local/share/man
exit

[-flto fails]

configure: libOSMesa 64-bit development files not found (or too old), OpenGL rendering in bitmaps won't be supported.
configure: OSS sound system found but too old (OSSv4 needed), OSS won't be supported.
configure: libcapi20 64-bit development files not found, ISDN won't be supported.
configure: libnetapi not found, Samba NetAPI won't be supported.
