blob: d64a9b88c1cac40f3ffc1eb24bc5b12980ede48b (
plain)
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
45
46
47
48
49
50
51
52
53
54
55
|
#!/bin/sh
set -eu
base="${TMPDIR-/tmp}/mcpu-cpp-relocatable-root-$$"
root_a="$base/mcpu-a"
root_b="$base/mcpu-b"
mkdir -p "$root_a/bin" "$root_a/etc" "$root_a/include/diff" "$base/home"
trap 'rm -rf "$base"' EXIT HUP INT TERM
cp "$MCPU_CPP" "$root_a/bin/mcpu-cpp"
chmod +x "$root_a/bin/mcpu-cpp"
cat > "$root_a/include/diff/relocated.h" <<'EOT'
int relocated_header = 37;
EOT
cat > "$root_a/etc/mcpu-cpp.conf" <<'EOT'
MCPU_CPP_RELOCATION_SENTINEL = runtime-config;
EOT
# The copied executable first derives its defaults from its new physical root.
HOME="$base/home" "$root_a/bin/mcpu-cpp" --no-config -dsearch-dirs \
> "$base/root-a.search"
grep "^search: $root_a/include/diff$" "$base/root-a.search" >/dev/null
grep "^search: $root_a/include$" "$base/root-a.search" >/dev/null
# Move the complete MCPU tree without reconfiguring or rebuilding anything.
mv "$root_a" "$root_b"
HOME="$base/home" "$root_b/bin/mcpu-cpp" --no-config -dsearch-dirs \
> "$base/root-b.search"
grep "^search: $root_b/include/diff$" "$base/root-b.search" >/dev/null
grep "^search: $root_b/include$" "$base/root-b.search" >/dev/null
if grep "$root_a" "$base/root-b.search" >/dev/null; then
echo 'relocated mcpu-cpp retained its previous installation root' >&2
exit 1
fi
cat > "$base/main.c" <<'EOT'
#lang "diff"
#include <relocated.h>
#endlang
EOT
HOME="$base/home" "$root_b/bin/mcpu-cpp" --no-config \
"$base/main.c" -o "$base/main.out"
grep '^int relocated_header = 37;$' "$base/main.out" >/dev/null
# The packaged configuration is found relative to the relocated root as well.
HOME="$base/home" "$root_b/bin/mcpu-cpp" -dconfig > "$base/config.out"
grep '^MCPU_CPP_RELOCATION_SENTINEL = runtime-config;$' "$base/config.out" >/dev/null
# Invoking through a symbolic link must still resolve the physical executable
# and therefore the same relocated MCPU root.
ln -s "$root_b/bin/mcpu-cpp" "$base/mcpu-cpp"
HOME="$base/home" "$base/mcpu-cpp" --no-config -dconfig > "$base/link.out"
grep "^MCPU_CPP_SYSTEM_INCLUDE_PATH = $root_b/include;$" "$base/link.out" >/dev/null
|