Files

118 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
usage() {
echo "Usage: $0 [-r] [build-directory [install-prefix]]"
echo "Build and install locally as a user, or system wide as root."
echo " -r Remove the installed helper instead of building."
echo " -h Show this help."
}
removeInstalled=false
while getopts ':rh' option; do
case "$option" in
r) removeInstalled=true ;;
h) usage; exit 0 ;;
*) usage >&2; exit 2 ;;
esac
done
shift "$((OPTIND - 1))"
if (( $# > 2 )); then
usage >&2
exit 2
fi
projectDir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
buildDir=${1:-"$projectDir/build"}
systemPrefix=/usr
if (( EUID == 0 )); then
defaultPrefix=$systemPrefix
else
defaultPrefix="${HOME}/.local"
fi
prefix=${2:-"$defaultPrefix"}
installDir="${prefix%/}/libexec/wine-access"
installedFiles=(wine-access.exe wine-access.exe.so wine-access-menu.dll
wine-access-menu32.dll wine-access-menu-host32.exe)
has_installation() {
local candidateDir=$1
local installedFile
for installedFile in "${installedFiles[@]}"; do
if [[ -e "$candidateDir/$installedFile" || -L "$candidateDir/$installedFile" ]]; then
return 0
fi
done
return 1
}
if "$removeInstalled"; then
if has_installation "$installDir"; then
for installedFile in "${installedFiles[@]}"; do
rm -f -- "$installDir/$installedFile"
done
echo "Removed Wine Access from $installDir"
elif (( EUID != 0 && $# < 2 )) && has_installation "$systemPrefix/libexec/wine-access"; then
echo "Only a system-wide installation was found. Run: sudo ./build.sh -r" >&2
exit 1
else
echo "No Wine Access installation found in $installDir"
fi
exit 0
fi
check_prerequisites() {
local requirement tool package
local -a missingRequirements=() missingPackages=()
local -A seenPackages=()
local -a requirements=(
cmake:cmake make:make gcc:gcc g++:gcc pkg-config:pkgconf
winegcc:wine wineg++:wine widl:wine
x86_64-w64-mingw32-gcc:mingw-w64-gcc
i686-w64-mingw32-gcc:mingw-w64-gcc
)
for requirement in "${requirements[@]}"; do
tool=${requirement%%:*}
package=${requirement#*:}
if ! command -v "$tool" >/dev/null 2>&1; then
missingRequirements+=("$tool (Arch Linux package: $package)")
if [[ ! -v "seenPackages[$package]" ]]; then
missingPackages+=("$package")
seenPackages[$package]=1
fi
fi
done
if command -v pkg-config >/dev/null 2>&1 && ! pkg-config --exists gio-2.0; then
missingRequirements+=("GIO development files, gio-2.0 (Arch Linux package: glib2)")
missingPackages+=(glib2)
fi
if (( ${#missingRequirements[@]} > 0 )); then
echo "Missing build prerequisites:" >&2
for requirement in "${missingRequirements[@]}"; do
echo " $requirement" >&2
done
if ! command -v pkg-config >/dev/null 2>&1; then
echo "GIO development files cannot be checked until pkg-config is available." >&2
fi
echo "On Arch Linux: sudo pacman -S --needed ${missingPackages[*]}" >&2
echo "On other distributions, install the equivalent development packages." >&2
return 1
fi
}
check_prerequisites
cmake \
-S "$projectDir" \
-B "$buildDir" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_TOOLCHAIN_FILE="$projectDir/winelib-toolchain.cmake" \
-DCMAKE_INSTALL_PREFIX="$prefix" \
-DCMAKE_INSTALL_LIBEXECDIR:PATH=libexec \
-DWINE_ACCESS_INSTALL_DIR:PATH=libexec/wine-access
cmake --build "$buildDir" --parallel
cmake --install "$buildDir"