Repository navigation
Expand file tree
/
Copy pathresolve-prefix.sh
More file actions
44 lines (42 loc) · 1.88 KB
/
Copy pathresolve-prefix.sh
File metadata and controls
44 lines (42 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
#
# resolve-prefix.sh — shared helper for check-soversion.sh and
# check-parallel-install.sh.
#
# Sourced (not executed) by both gate scripts to avoid copy-pasting the
# config.status prefix-resolution pipeline in two places.
#
# Inputs (must be set by the caller before sourcing):
# CONFIG_STATUS — absolute path to the config.status file in BUILD_DIR.
# fail — a shell function that prints a message and exits non-zero.
#
# Outputs (set in the caller's environment):
# RESOLVED_PREFIX — the configured installation prefix (e.g. /usr/local).
#
# After sourcing, callers typically derive:
# LIBDIR="$RESOLVED_PREFIX/lib"
# INCDIR="$RESOLVED_PREFIX/include"
#
# Design note: this helper is intentionally kept standalone (no sourcing of
# further helpers) so that each gate script remains easy to invoke in
# isolation without a complex dependency chain.
# Resolve prefix by asking config.status. The --config flag prints the
# original configure arguments, one per line after splitting on spaces. We
# grep for the --prefix= token, strip surrounding single-quotes (an autoconf
# quoting convention), and fall back to /usr/local when absent.
#
# POSIX-portable sed is used: avoid GNU \? (undefined in POSIX BRE/ERE).
# The trailing `|| true` matters when the caller runs under `set -e`: a default
# (unset) prefix makes the grep match nothing and exit 1, which pipefail would
# otherwise propagate and abort the script before the /usr/local fallback below.
RESOLVED_PREFIX="$("$CONFIG_STATUS" --config 2>/dev/null \
| tr ' ' '\n' \
| grep -E "^'?--prefix=" \
| head -1 \
| sed "s/^'*--prefix=//;s/'*$//" || true)"
[ -z "$RESOLVED_PREFIX" ] && RESOLVED_PREFIX="/usr/local"
# Guard: an absolute path is required for safe use in rm -rf / mkdir -p.
case "$RESOLVED_PREFIX" in
/*) ;;
*) fail "resolved prefix is not absolute: $RESOLVED_PREFIX" ;;
esac