Skip to content

Instantly share code, notes, and snippets.

@shmerl
Last active May 5, 2024 20:00
Show Gist options
  • Save shmerl/baf82630e312c04e8910ca3081ab943f to your computer and use it in GitHub Desktop.
Save shmerl/baf82630e312c04e8910ca3081ab943f to your computer and use it in GitHub Desktop.
For building Wine staging
#!/bin/bash
# Builds Wine-staging
# Notes:
# 1. Targeted for usage inside a VM (use shared directory $HOME/mnt/vmshare between host and guest).
# 2. You'd need to separately push the result on the host to whatever location you want (like to /opt).
# 3. Place any manual patches in ${HOME}/build/patches
# 4. Override arch to something else if you aren't using Ryzen.
#
# Usage:
# wine_staging_build.sh [staging-patchset]
#
# Examples:
# 1. To build just Wine with esync patches:
#
# wine_staging_build.sh eventfd_synchronization
#
# 2. To build specific Wine version with esync (matching versions help avoid conflicts);
#
# wine_branch=wine-8.21 wine_staging_branch=v8.21 wine_staging_build.sh eventfd_synchronization
#
# 3. wine_ver is a shortcut variable that allows setting aligning version for both:
#
# wine_ver=8.21 wine_staging_build.sh eventfd_synchronization
#
# 4. To build full Wine staging:
#
# wine_staging_build.sh
#
base=${HOME}/build
wine_branch=${wine_branch:-"master"}
wine_src="${base}/wine/source"
wine_build="${base}/wine/build"
wine_staging_branch=${wine_staging_branch:-"master"}
wine_staging_src="${base}/wine-staging"
wow64=${wow64:-true} # set to false to disable new unified wow64 mode
update_sources=${update_sources:-true}
reset_sources=${reset_sources:-true}
update_staging_sources=${update_staging_sources:-true}
reset_staging_sources=${reset_staging_sources:-true}
patches=${patches:-true} # enabled
patches_dir="${base}/wine/patches-staging" # extra patches if any
arch=${arch:-"znver4"} # assumes Ryzen, change if needed
staging_patchset="$@"
if [[ "${wine_ver+isset}" ]]; then
wine_branch="wine-${wine_ver}"
wine_staging_branch="v${wine_ver}"
fi
if [[ "$staging_patchset" == "" ]]; then
staging_patchset='--all'
fi
if [[ "$wine_branch" == "wine"* ]]; then
dest_dir="${HOME}/mnt/vmshare/${wine_branch}-staging"
else
dest_dir="${HOME}/mnt/vmshare/wine-${wine_branch}-staging"
fi
export CXXFLAGS="-O3 -march=${arch}"
export CFLAGS="$CXXFLAGS"
export CROSSCFLAGS="$CXXFLAGS"
function prepare() {
mkdir -p "$patches_dir"
mkdir -p "$wine_build"
}
function update_wine_sources() {
cd $(dirname "$wine_src")
git clone https://gitlab.winehq.org/wine/wine.git $(basename "$wine_src")
cd "$wine_src"
# If updating, reset is enforced regardless of the $reset_sources, to avoid possible merging confusion
if $reset_sources || $update_sources; then
git reset --hard HEAD
git clean -df
fi
if $update_sources; then
git checkout master
git pull --rebase --prune
fi
git checkout ${wine_branch}
if (($? != 0)); then
echo "Invalid branch or tag ${wine_branch}! Aborting"
exit 2
fi
}
function update_wine_staging_sources() {
cd $(dirname "$wine_staging_src")
git clone https://gitlab.winehq.org/wine/wine-staging.git $(basename "$wine_staging_src")
cd "$wine_staging_src"
# If updating, reset is enforced regardless of the $reset_sources, to avoid possible merging confusion
if $reset_staging_sources || $update_staging_sources; then
git reset --hard HEAD
git clean -df
fi
if $update_staging_sources; then
git checkout master
git pull --rebase --prune
fi
git checkout ${wine_staging_branch}
if (($? != 0)); then
echo "Invalid branch or tag ${wine_staging_branch}! Aborting"
exit 2
fi
}
function extra_patch() {
local patch_dir="$1"
cd $wine_src
for patchfile in ${patch_dir}/*; do
echo "Applying ${patchfile}"
patch -p1 -i ${patchfile}
if (($? != 0)); then
echo "Extra patching failed, check what's wrong..."
exit 1
fi
done
}
function patch_staging {
cd "$wine_src"
${wine_staging_src}/staging/patchinstall.py $staging_patchset
if (($? != 0)); then
echo "Patching failed, check what's wrong..."
exit 1
fi
}
function patch_sources() {
if $patches; then
extra_patch "${patches_dir}"
fi
patch_staging
}
function configure() {
rm -rfv ${wine_build}/*
cd $wine_build
local arch_param=''
if $wow64; then
arch_param='--enable-archs=i386,x86_64'
else
arch_param='--enable-win64'
fi
${wine_src}/configure $arch_param --with-wayland --disable-tests --prefix=
}
function build() {
cd $wine_build
make -j$(nproc)
if (($? != 0)); then
echo "Build failed!"
exit 2
fi
}
function publish() {
cd $wine_build
mkdir -p ${dest_dir}
rm -rfv ${dest_dir}/*
DESTDIR=${dest_dir} make -j$(nproc) install
}
############################################
shopt -s nullglob
prepare
update_wine_sources
update_wine_staging_sources
patch_sources
configure
build
publish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment