Files
hjozwiak e920543dcb Update the build script to put the Orca extension into place.
Still need to do the symlinking yourself though.
2026-10-31 10:03:30 -04:00

179 lines
6.1 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 and Orca extension 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)
orcaSourceDir="$projectDir/orca/wine_access"
orcaInstallDir="${prefix%/}/share/wine-access/orca/wine_access"
systemOrcaInstallDir="$systemPrefix/share/wine-access/orca/wine_access"
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
}
has_orca_extension() {
local candidateDir=$1
local extensionFile
for extensionFile in "$orcaSourceDir/"*.py; do
if [[ -e $extensionFile ]] && [[ -e "$candidateDir/${extensionFile##*/}" || -L "$candidateDir/${extensionFile##*/}" ]]; then
return 0
fi
done
return 1
}
if "$removeInstalled"; then
removedAny=false
if has_installation "$installDir"; then
for installedFile in "${installedFiles[@]}"; do
rm -f -- "$installDir/$installedFile"
done
echo "Removed Wine Access from $installDir"
removedAny=true
fi
if has_orca_extension "$orcaInstallDir"; then
for extensionFile in "$orcaSourceDir/"*.py; do
if [[ -e $extensionFile ]]; then
rm -f -- "$orcaInstallDir/${extensionFile##*/}"
fi
done
echo "Removed Wine Access Orca extension from $orcaInstallDir"
removedAny=true
fi
if ! "$removedAny"; then
if (( EUID != 0 && $# < 2 )) && { has_installation "$systemPrefix/libexec/wine-access" || has_orca_extension "$systemOrcaInstallDir"; }; then
echo "Only a system-wide installation was found. Run: sudo ./build.sh -r" >&2
exit 1
fi
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
}
install_orca_extension() {
if ! command -v orca >/dev/null 2>&1; then
return 0
fi
local versionOutput majorVersion=""
versionOutput=$(orca --version 2>/dev/null || true)
if [[ $versionOutput =~ [Vv]ersion[[:space:]]+([0-9]+) ]]; then
majorVersion=${BASH_REMATCH[1]}
fi
if [[ -z $majorVersion ]]; then
echo "Orca was found, but its version could not be determined." >&2
echo "Skipping the Wine Access Orca extension, which requires Orca 51 or later." >&2
return 0
fi
if (( 10#$majorVersion < 51 )); then
echo "Orca $majorVersion was found, but the Wine Access Orca extension requires Orca 51 or later; skipping it."
return 0
fi
local extensionFile
for extensionFile in "$orcaSourceDir/"*.py; do
install -Dm644 "$extensionFile" "$orcaInstallDir/${extensionFile##*/}"
done
echo "Installed the Wine Access Orca extension to $orcaInstallDir"
echo "Orca discovers extensions only in each user's extension directory."
echo "To enable it, run as your normal user:"
echo " mkdir -p \"\${XDG_DATA_HOME:-\$HOME/.local/share}/orca/extensions\""
echo " ln -sT $orcaInstallDir \"\${XDG_DATA_HOME:-\$HOME/.local/share}/orca/extensions/wine_access\""
echo " orca --approve-extension wine_access"
echo "Then restart Orca. If wine_access already exists in that directory,"
echo "move it aside first, and approve again after each Wine Access update."
}
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"
install_orca_extension