2018-08-21 02:11:58 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
SRCDIR="$(dirname "$0")"
|
|
|
|
DEFAULT_BUILD_NAME="proton-localbuild" # If no --build-name specified
|
|
|
|
|
|
|
|
# Output helpers
|
|
|
|
COLOR_ERR=""
|
|
|
|
COLOR_STAT=""
|
|
|
|
COLOR_INFO=""
|
|
|
|
COLOR_CMD=""
|
|
|
|
COLOR_CLEAR=""
|
|
|
|
if [[ $(tput colors 2>/dev/null || echo 0) -gt 0 ]]; then
|
|
|
|
COLOR_ERR=$'\e[31;1m'
|
|
|
|
COLOR_STAT=$'\e[32;1m'
|
|
|
|
COLOR_INFO=$'\e[30;1m'
|
|
|
|
COLOR_CMD=$'\e[93;1m'
|
|
|
|
COLOR_CLEAR=$'\e[0m'
|
|
|
|
fi
|
|
|
|
|
2023-01-13 12:48:41 +01:00
|
|
|
sh_quote() {
|
2018-11-07 00:32:57 +01:00
|
|
|
local quoted
|
2023-01-13 12:48:41 +01:00
|
|
|
quoted="$(printf '%q ' "$@")"; [[ $# -eq 0 ]] || echo "${quoted:0:-1}";
|
2018-11-07 00:32:57 +01:00
|
|
|
}
|
2018-08-21 02:11:58 +02:00
|
|
|
err() { echo >&2 "${COLOR_ERR}!!${COLOR_CLEAR} $*"; }
|
|
|
|
stat() { echo >&2 "${COLOR_STAT}::${COLOR_CLEAR} $*"; }
|
|
|
|
info() { echo >&2 "${COLOR_INFO}::${COLOR_CLEAR} $*"; }
|
|
|
|
showcmd() { echo >&2 "+ ${COLOR_CMD}$(sh_quote "$@")${COLOR_CLEAR}"; }
|
|
|
|
die() { err "$@"; exit 1; }
|
|
|
|
finish() { stat "$@"; exit 0; }
|
|
|
|
cmd() { showcmd "$@"; "$@"; }
|
|
|
|
|
2021-06-10 23:50:53 +02:00
|
|
|
#
|
|
|
|
# Dependency Checks
|
|
|
|
#
|
|
|
|
|
|
|
|
MISSING_DEPENDENCIES=0
|
|
|
|
|
|
|
|
dependency_command() {
|
|
|
|
local COMMAND=$1
|
|
|
|
shift
|
|
|
|
if ! command -v "$COMMAND" &> /dev/null; then
|
|
|
|
err "Couldn't find command '$COMMAND'. Please install ${@:-$COMMAND}."
|
|
|
|
MISSING_DEPENDENCIES=1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-07-09 15:57:09 +02:00
|
|
|
CONTAINER_MOUNT_OPTS=""
|
|
|
|
|
2021-06-11 08:06:58 +02:00
|
|
|
check_container_engine() {
|
2021-12-22 20:59:36 +01:00
|
|
|
stat "Trying $1."
|
2023-01-12 14:09:23 +01:00
|
|
|
if ! cmd $1 run --rm $2; then
|
2021-12-22 20:59:36 +01:00
|
|
|
info "$1 is unable to run the container."
|
|
|
|
return 1
|
2021-06-11 08:06:58 +02:00
|
|
|
fi
|
2021-06-14 15:20:12 +02:00
|
|
|
|
|
|
|
touch permission_check
|
2021-12-22 20:59:36 +01:00
|
|
|
local inner_uid="$($1 run -v "$(pwd):/test$CONTAINER_MOUNT_OPTS" \
|
2023-01-12 14:09:23 +01:00
|
|
|
--rm $2 \
|
2021-07-09 15:57:09 +02:00
|
|
|
stat --format "%u" /test/permission_check 2>&1)"
|
2021-06-14 15:20:12 +02:00
|
|
|
rm permission_check
|
|
|
|
|
2021-07-09 15:57:09 +02:00
|
|
|
if [[ $inner_uid == *"Permission denied"* ]]; then
|
|
|
|
err "The container cannot access files. Are you using SELinux?"
|
2021-12-22 20:59:36 +01:00
|
|
|
die "Please read README.md and check your $1 setup works."
|
2021-07-09 15:57:09 +02:00
|
|
|
elif [ "$inner_uid" -eq 0 ]; then
|
2021-06-14 15:20:12 +02:00
|
|
|
# namespace maps the user as root or the build is performed as host's root
|
|
|
|
ROOTLESS_CONTAINER=1
|
|
|
|
elif [ "$inner_uid" -eq "$(id -u)" ]; then
|
|
|
|
ROOTLESS_CONTAINER=0
|
|
|
|
else
|
|
|
|
err "File owner's UID doesn't map to 0 or $(id -u) in the container."
|
2021-12-22 20:59:36 +01:00
|
|
|
die "Don't know how to map permissions. Please check your $1 setup."
|
2021-06-14 15:20:12 +02:00
|
|
|
fi
|
2021-06-11 08:06:58 +02:00
|
|
|
}
|
|
|
|
|
2018-08-21 02:11:58 +02:00
|
|
|
#
|
|
|
|
# Configure
|
|
|
|
#
|
|
|
|
|
|
|
|
THIS_COMMAND="$0 $*" # For printing, not evaling
|
|
|
|
MAKEFILE="./Makefile"
|
|
|
|
|
|
|
|
# This is not rigorous. Do not use this for untrusted input. Do not. If you need a version of
|
|
|
|
# this for untrusted input, rethink the path that got you here.
|
|
|
|
function escape_for_make() {
|
|
|
|
local escape="$1"
|
|
|
|
escape="${escape//\\/\\\\}" # '\' -> '\\'
|
|
|
|
escape="${escape//#/\\#}" # '#' -> '\#'
|
|
|
|
escape="${escape//\$/\$\$}" # '$' -> '$$'
|
|
|
|
escape="${escape// /\\ }" # ' ' -> '\ '
|
|
|
|
echo "$escape"
|
|
|
|
}
|
|
|
|
|
|
|
|
function configure() {
|
2023-01-12 14:09:23 +01:00
|
|
|
local steamrt_image="$arg_protonsdk_image"
|
2018-11-07 00:32:57 +01:00
|
|
|
local srcdir
|
|
|
|
srcdir="$(dirname "$0")"
|
2018-08-21 02:11:58 +02:00
|
|
|
|
2023-03-30 12:53:04 +02:00
|
|
|
if [[ "$srcdir" = "." ]]; then
|
|
|
|
err "Cannot do a top level in-tree build."
|
|
|
|
die "Create a subdirectory in build/ or outside of the tree and run configure.sh from there."
|
|
|
|
fi
|
|
|
|
|
2023-01-12 14:09:23 +01:00
|
|
|
# nothing specified, getting the default value from the Makefile to test the
|
|
|
|
# container engine
|
|
|
|
if [[ -z $steamrt_image ]]; then
|
|
|
|
steamrt_image="$(sed -n 's/STEAMRT_IMAGE ?= //p' $SRCDIR/Makefile.in)"
|
|
|
|
fi
|
|
|
|
|
2018-08-21 02:11:58 +02:00
|
|
|
# Build name
|
|
|
|
local build_name="$arg_build_name"
|
|
|
|
if [[ -n $build_name ]]; then
|
|
|
|
info "Configuring with build name: $build_name"
|
|
|
|
else
|
|
|
|
build_name="$DEFAULT_BUILD_NAME"
|
|
|
|
info "No build name specified, using default: $build_name"
|
|
|
|
fi
|
|
|
|
|
2021-06-10 23:50:53 +02:00
|
|
|
dependency_command make "GNU Make"
|
|
|
|
|
|
|
|
if [ "$MISSING_DEPENDENCIES" -ne 0 ]; then
|
|
|
|
die "Missing dependencies, cannot continue."
|
|
|
|
fi
|
|
|
|
|
2021-07-09 15:57:09 +02:00
|
|
|
if [[ -n "$arg_relabel_volumes" ]]; then
|
|
|
|
CONTAINER_MOUNT_OPTS=:Z
|
|
|
|
fi
|
|
|
|
|
2021-06-11 08:06:58 +02:00
|
|
|
if [[ -n "$arg_container_engine" ]]; then
|
2023-01-12 14:09:23 +01:00
|
|
|
check_container_engine "$arg_container_engine" "$steamrt_image" || die "Specified container engine \"$arg_container_engine\" doesn't work"
|
2021-12-22 20:59:36 +01:00
|
|
|
else
|
|
|
|
stat "Trying to find usable container engine."
|
2023-01-12 14:09:23 +01:00
|
|
|
if check_container_engine docker "$steamrt_image"; then
|
2021-12-22 20:59:36 +01:00
|
|
|
arg_container_engine="docker"
|
2023-01-12 14:09:23 +01:00
|
|
|
elif check_container_engine podman "$steamrt_image"; then
|
2021-12-22 20:59:36 +01:00
|
|
|
arg_container_engine="podman"
|
|
|
|
else
|
|
|
|
die "${arg_container_engine:-Container engine discovery} has failed. Please fix your setup."
|
|
|
|
fi
|
2021-06-11 08:06:58 +02:00
|
|
|
fi
|
|
|
|
|
2021-12-22 20:59:36 +01:00
|
|
|
stat "Using $arg_container_engine."
|
|
|
|
|
2018-08-21 02:11:58 +02:00
|
|
|
## Write out config
|
|
|
|
# Don't die after this point or we'll have rather unhelpfully deleted the Makefile
|
|
|
|
[[ ! -e "$MAKEFILE" ]] || rm "$MAKEFILE"
|
|
|
|
|
2018-11-07 00:32:57 +01:00
|
|
|
{
|
|
|
|
# Config
|
|
|
|
echo "# Generated by: $THIS_COMMAND"
|
|
|
|
echo ""
|
|
|
|
echo "SRCDIR := $(escape_for_make "$srcdir")"
|
|
|
|
echo "BUILD_NAME := $(escape_for_make "$build_name")"
|
2018-08-21 02:11:58 +02:00
|
|
|
|
2023-01-12 14:09:23 +01:00
|
|
|
# SteamRT was specified, baking it into the Makefile
|
|
|
|
if [[ -n $arg_protonsdk_image ]]; then
|
|
|
|
echo "STEAMRT_IMAGE := $(escape_for_make "$arg_protonsdk_image")"
|
|
|
|
fi
|
2018-08-21 02:11:58 +02:00
|
|
|
|
2021-06-14 15:20:12 +02:00
|
|
|
echo "ROOTLESS_CONTAINER := $ROOTLESS_CONTAINER"
|
2021-06-11 08:06:58 +02:00
|
|
|
echo "CONTAINER_ENGINE := $arg_container_engine"
|
2019-06-24 16:32:26 +02:00
|
|
|
if [[ -n "$arg_docker_opts" ]]; then
|
|
|
|
echo "DOCKER_OPTS := $arg_docker_opts"
|
|
|
|
fi
|
2021-07-09 15:57:09 +02:00
|
|
|
if [[ -n "$CONTAINER_MOUNT_OPTS" ]]; then
|
|
|
|
echo "CONTAINER_MOUNT_OPTS := $CONTAINER_MOUNT_OPTS"
|
|
|
|
fi
|
2021-06-14 15:21:36 +02:00
|
|
|
if [[ -n "$arg_enable_ccache" ]]; then
|
|
|
|
echo "ENABLE_CCACHE := 1"
|
|
|
|
fi
|
2023-09-04 15:12:40 +02:00
|
|
|
if [[ -n "$arg_enable_bear" ]]; then
|
|
|
|
echo "ENABLE_BEAR := 1"
|
|
|
|
fi
|
2019-06-24 16:32:26 +02:00
|
|
|
|
2018-11-07 00:32:57 +01:00
|
|
|
# Include base
|
|
|
|
echo ""
|
2021-12-22 20:45:47 +01:00
|
|
|
echo "include \$(SRCDIR)/Makefile.in"
|
2018-11-07 00:32:57 +01:00
|
|
|
} >> "$MAKEFILE"
|
2018-08-21 02:11:58 +02:00
|
|
|
|
|
|
|
stat "Created $MAKEFILE, now run make to build."
|
2018-10-05 21:44:15 +02:00
|
|
|
stat " See README.md for make targets and instructions"
|
2018-08-21 02:11:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Parse arguments
|
|
|
|
#
|
|
|
|
|
2023-01-12 14:09:23 +01:00
|
|
|
arg_protonsdk_image=""
|
2018-08-21 02:11:58 +02:00
|
|
|
arg_build_name=""
|
2021-12-22 20:59:36 +01:00
|
|
|
arg_container_engine=""
|
2019-06-24 16:32:26 +02:00
|
|
|
arg_docker_opts=""
|
2021-07-09 15:57:09 +02:00
|
|
|
arg_relabel_volumes=""
|
2021-06-14 15:21:36 +02:00
|
|
|
arg_enable_ccache=""
|
2023-09-04 15:12:40 +02:00
|
|
|
arg_enable_bear=""
|
2018-08-21 02:11:58 +02:00
|
|
|
arg_help=""
|
|
|
|
invalid_args=""
|
|
|
|
function parse_args() {
|
|
|
|
local arg;
|
|
|
|
local val;
|
|
|
|
local val_used;
|
|
|
|
local val_passed;
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
arg="$1"
|
|
|
|
val=''
|
|
|
|
val_used=''
|
|
|
|
val_passed=''
|
|
|
|
if [[ -z $arg ]]; then # Sanity
|
|
|
|
err "Unexpected empty argument"
|
|
|
|
return 1
|
|
|
|
elif [[ ${arg:0:2} != '--' ]]; then
|
|
|
|
err "Unexpected positional argument ($1)"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Looks like an argument does it have a --foo=bar value?
|
2018-11-07 00:32:57 +01:00
|
|
|
if [[ ${arg%=*} != "$arg" ]]; then
|
2018-08-21 02:11:58 +02:00
|
|
|
val="${arg#*=}"
|
|
|
|
arg="${arg%=*}"
|
|
|
|
val_passed=1
|
|
|
|
else
|
|
|
|
# Otherwise for args that want a value, assume "--arg val" form
|
|
|
|
val="${2:-}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# The args
|
|
|
|
if [[ $arg = --help || $arg = --usage ]]; then
|
|
|
|
arg_help=1
|
|
|
|
elif [[ $arg = --build-name ]]; then
|
|
|
|
arg_build_name="$val"
|
|
|
|
val_used=1
|
2021-06-11 08:06:58 +02:00
|
|
|
elif [[ $arg = --container-engine ]]; then
|
|
|
|
arg_container_engine="$val"
|
|
|
|
val_used=1
|
2019-06-24 16:32:26 +02:00
|
|
|
elif [[ $arg = --docker-opts ]]; then
|
|
|
|
arg_docker_opts="$val"
|
|
|
|
val_used=1
|
2021-07-09 15:57:09 +02:00
|
|
|
elif [[ $arg = --relabel-volumes ]]; then
|
|
|
|
arg_relabel_volumes="1"
|
2021-06-14 15:21:36 +02:00
|
|
|
elif [[ $arg = --enable-ccache ]]; then
|
|
|
|
arg_enable_ccache="1"
|
2023-09-04 15:12:40 +02:00
|
|
|
elif [[ $arg = --enable-bear ]]; then
|
|
|
|
arg_enable_bear="1"
|
2021-04-19 15:32:32 +02:00
|
|
|
elif [[ $arg = --proton-sdk-image ]]; then
|
2018-08-21 02:11:58 +02:00
|
|
|
val_used=1
|
2021-04-19 15:32:32 +02:00
|
|
|
arg_protonsdk_image="$val"
|
2018-08-21 02:11:58 +02:00
|
|
|
else
|
|
|
|
err "Unrecognized option $arg"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if this arg used the value and shouldn't have or vice-versa
|
2018-11-07 00:32:57 +01:00
|
|
|
if [[ -n $val_used && -z $val_passed ]]; then
|
2018-08-21 02:11:58 +02:00
|
|
|
# "--arg val" form, used $2 as the value.
|
|
|
|
|
|
|
|
# Don't allow this if it looked like "--arg --val"
|
2018-11-07 00:32:57 +01:00
|
|
|
if [[ ${val#--} != "$val" ]]; then
|
2018-08-21 02:11:58 +02:00
|
|
|
err "Ambiguous format for argument with value \"$arg $val\""
|
|
|
|
err " (use $arg=$val or $arg='' $val)"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Error if this was the last positional argument but expected $val
|
|
|
|
if [[ $# -le 1 ]]; then
|
|
|
|
err "$arg takes a parameter, but none given"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
shift # consume val
|
|
|
|
elif [[ -z $val_used && -n $val_passed ]]; then
|
|
|
|
# Didn't use a value, but passed in --arg=val form
|
|
|
|
err "$arg does not take a parameter"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
shift # consume arg
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
2023-09-22 22:21:29 +02:00
|
|
|
"$1" "Usage: $0 { --proton-sdk-image=<image> }"
|
2018-08-21 02:11:58 +02:00
|
|
|
"$1" " Generate a Makefile for building Proton. May be run from another directory to create"
|
|
|
|
"$1" " out-of-tree build directories (e.g. mkdir mybuild && cd mybuild && ../configure.sh)"
|
|
|
|
"$1" ""
|
|
|
|
"$1" " Options"
|
|
|
|
"$1" " --help / --usage Show this help text and exit"
|
|
|
|
"$1" ""
|
|
|
|
"$1" " --build-name=<name> Set the name of the build that displays when used in Steam"
|
|
|
|
"$1" ""
|
2021-12-22 20:59:36 +01:00
|
|
|
"$1" " --container-engine=<engine> Which Docker-compatible container engine to use,"
|
|
|
|
"$1" " e.g. podman. Tries to do autodiscovery when not specified."
|
2021-06-11 08:06:58 +02:00
|
|
|
"$1" ""
|
2019-06-24 16:32:26 +02:00
|
|
|
"$1" " --docker-opts='<options>' Extra options to pass to Docker when invoking the runtime."
|
|
|
|
"$1" ""
|
2021-07-09 15:57:09 +02:00
|
|
|
"$1" " --relabel-volumes Bind-mounted volumes will be relabeled. Use with caution."
|
|
|
|
"$1" ""
|
2021-06-14 15:21:36 +02:00
|
|
|
"$1" " --enable-ccache Mount \$CCACHE_DIR or \$HOME/.ccache inside of the container and use ccache for the build."
|
|
|
|
"$1" ""
|
2023-09-04 15:12:40 +02:00
|
|
|
"$1" " --enable-bear Invokes make via bear creating compile_commands.json."
|
|
|
|
"$1" ""
|
2018-08-21 02:11:58 +02:00
|
|
|
"$1" " Steam Runtime"
|
|
|
|
"$1" " Proton builds that are to be installed & run under the steam client must be built with"
|
2018-10-05 21:44:15 +02:00
|
|
|
"$1" " the Steam Runtime SDK to ensure compatibility. See README.md for more information."
|
2018-08-21 02:11:58 +02:00
|
|
|
"$1" ""
|
2021-04-19 15:32:32 +02:00
|
|
|
"$1" " --proton-sdk-image=<image> Automatically invoke the Steam Runtime SDK in <image>"
|
|
|
|
"$1" " for build steps that must be run in an SDK"
|
|
|
|
"$1" " environment. See README.md for instructions to"
|
|
|
|
"$1" " create this image."
|
2018-08-21 02:11:58 +02:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_args "$@" || usage err
|
|
|
|
[[ -z $arg_help ]] || usage info
|
|
|
|
|
2023-01-12 14:09:23 +01:00
|
|
|
configure
|