#!/bin/sh set -eu base="${TMPDIR-/tmp}/mcpu-cpp-sys-root-$$" abs_root="$base/absolute-root" rel_root="$base/relative-root" home="$base/home" mkdir -p "$abs_root/include/as" "$rel_root/include/as" \ "$home/.mcpu/etc" "$base/forbidden" trap 'rm -rf "$base"' EXIT HUP INT TERM cat > "$abs_root/include/as/sys-root.h" <<'EOT' int from_absolute_sys_root = 103; EOT cat > "$rel_root/include/as/sys-root.h" <<'EOT' int from_relative_sys_root = 104; EOT cat > "$home/.mcpu/etc/mcpu-cpp.conf" < "$base/explicit.conf" < "$base/main.c" <<'EOT' #lang "as" #include #endlang EOT # An absolute --sys-root replaces the runtime root for the system include tree # and implies --no-config, including for an explicitly named config file. HOME="$home" "$MCPU_CPP" --sys-root="$abs_root" \ --config-file "$base/explicit.conf" -dconfig > "$base/absolute.config" grep "^MCPU_CPP_SYSTEM_INCLUDE_PATH = $abs_root/include;$" \ "$base/absolute.config" >/dev/null if grep 'MCPU_CPP_SYS_ROOT_SENTINEL\|forbidden' "$base/absolute.config" >/dev/null; then echo '--sys-root read a configuration file' >&2 exit 1 fi HOME="$home" "$MCPU_CPP" --sys-root="$abs_root" \ "$base/main.c" -o "$base/absolute.out" grep '^int from_absolute_sys_root = 103;$' "$base/absolute.out" >/dev/null # A relative --sys-root is interpreted relative to the invocation working # directory and becomes an absolute effective system include root. ( cd "$base" HOME="$home" "$MCPU_CPP" --sys-root=relative-root -dconfig \ > "$base/relative.config" HOME="$home" "$MCPU_CPP" --sys-root=relative-root \ "$base/main.c" -o "$base/relative.out" ) grep "^MCPU_CPP_SYSTEM_INCLUDE_PATH = $rel_root/include;$" \ "$base/relative.config" >/dev/null grep '^int from_relative_sys_root = 104;$' "$base/relative.out" >/dev/null # The separated spelling is accepted as the same option. HOME="$home" "$MCPU_CPP" --sys-root "$abs_root" -dsearch-dirs \ > "$base/separate.search" grep "^search: $abs_root/include/as$" "$base/separate.search" >/dev/null grep "^search: $abs_root/include$" "$base/separate.search" >/dev/null # An empty system root is never accepted. if HOME="$home" "$MCPU_CPP" --sys-root= -dconfig \ > "$base/empty.out" 2> "$base/empty.err"; then echo 'empty --sys-root unexpectedly accepted' >&2 exit 1 fi