Skip to content

Instantly share code, notes, and snippets.

@shmerl
Last active May 5, 2024 19:59
Show Gist options
  • Save shmerl/bbd448bc2b579831a82df7bae3de8dc5 to your computer and use it in GitHub Desktop.
Save shmerl/bbd448bc2b579831a82df7bae3de8dc5 to your computer and use it in GitHub Desktop.
For building Wine
#!/bin/bash
# Builds Wine
# 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 You can override the Wine repo. For example, to build Wine-wayland:
#
# wine_repo='https://gitlab.collabora.com/alf/wine.git' wine_branch='wayland' wine_build.sh
#
# 5. Override arch to something else if you aren't using Ryzen.
#
# 6. wine_ver is a shortcut for the version to set the branch:
#
# wine_ver=9.8 wine_build.sh
base_dir="${HOME}/build/wine"
wine_branch=${wine_branch:-"master"}
wine_repo=${wine_repo:-"https://gitlab.winehq.org/wine/wine.git"}
wow64=${wow64:-true} # set to false to disable new unified wow64 mode
src_dir="${base_dir}/source"
build_dir="${base_dir}/build"
patches=${patches:-true} # enabled
patches_dir="${base_dir}/patches"
arch=${arch:-"znver4"} # assumes Ryzen, change if needed
if [[ "${wine_ver+isset}" ]]; then
wine_branch="wine-${wine_ver}"
fi
if [[ "$wine_branch" == "wine"* ]]; then
dest_dir="${HOME}/mnt/vmshare/${wine_branch}"
else
dest_dir="${HOME}/mnt/vmshare/wine-${wine_branch}"
fi
export CXXFLAGS="-O3 -march=${arch}"
export CFLAGS="$CXXFLAGS"
export CROSSCFLAGS="$CXXFLAGS"
function prepare() {
mkdir -p "$patches_dir"
mkdir -p "$build_dir"
}
function update_wine_sources() {
# Potential clean up of previously created repo directory due to repo URL mismatch.
if [[ -e "$src_dir" ]]; then
cd "$src_dir"
local prev_wine_repo=$(git config --get remote.origin.url)
if [[ "$prev_wine_repo" != "$wine_repo" ]]; then
cd $(dirname "$src_dir")
rm -rfv $(basename "$src_dir")
fi
fi
cd $(dirname "$src_dir")
if ! [[ -e "$src_dir" ]]; then
git clone "$wine_repo" $(basename "$src_dir")
fi
cd "$src_dir"
git reset --hard HEAD
git clean -df
git checkout master
git pull --rebase --prune
git checkout ${wine_branch}
if (($? != 0)); then
echo "Invalid branch or tag ${wine_branch}! Aborting"
exit 2
fi
}
function extra_patch() {
local patch_dir="$1"
cd $src_dir
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
echo "Press any key to continue..."
read -n 1
done
}
function patch_sources() {
if $patches; then
extra_patch "$patches_dir"
fi
}
function configure() {
rm -rfv ${build_dir}/*
cd $build_dir
local arch_param=''
if $wow64; then
arch_param='--enable-archs=i386,x86_64'
else
arch_param='--enable-win64'
fi
${src_dir}/configure $arch_param --with-wayland --disable-tests --prefix=
}
function build() {
cd $build_dir
make -j$(nproc)
if (($? != 0)); then
echo "Build failed!"
exit 2
fi
}
function publish() {
cd $build_dir
mkdir -p ${dest_dir}
rm -rfv ${dest_dir}/*
DESTDIR=${dest_dir} make -j$(nproc) install
}
############################################
shopt -s nullglob
prepare
update_wine_sources
patch_sources
configure
build
publish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment