Skip to content

Instantly share code, notes, and snippets.

@shmerl
Last active March 21, 2024 08:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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.
base_dir="${HOME}/build/wine"
wine_branch=${wine_branch:-"master"}
wine_repo=${wine_repo:-"https://gitlab.winehq.org/wine/wine.git"}
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_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
${src_dir}/configure --with-wayland --enable-win64 --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