scripts/user_settings_asm.sh: give priority to user_settings.h found via the supplied search path arguments, and fall back to current directory; use POSIX sh variable expansions for prefix trimming and variable existence testing; trim trailing slash from supplied search path arguments; direct error messages to stderr.

pull/5692/head
Daniel Pouzzner 2022-10-12 11:20:56 -05:00
parent e05d044cf9
commit 67c194edf8
1 changed files with 30 additions and 29 deletions

View File

@ -1,42 +1,43 @@
#!/bin/sh #!/bin/sh
if test $# -eq 0; then if test $# -eq 0; then
echo "user_settings_asm.sh requires one argument specifying compiler flags to pull include directories from." echo "user_settings_asm.sh requires one argument specifying compiler flags to pull include directories from." 1>&2
exit 1 exit 1
fi fi
user_settings_path="" # Compress multiple spaces to single spaces, then replace instances of
user_settings_dir="./" # "-I " with "-I" (i.e. remove spaces between -I and the include path).
search_string=$(echo "$1" | sed -e 's/ */ /g' -e 's/-I /-I/g')
# First, see if user_settings.h is in the current directory. for token in $search_string
if test -e "user_settings.h"; then do
user_settings_path="user_settings.h" case "$token" in
else -I*)
search_string="$1" # Trim off the leading "-I".
# Compress multiple spaces to single spaces, then replace instances of path="${token#-I}"
# "-I " with "-I" (i.e. remove spaces between -I and the include path). # Trim off the trailing "/".
search_string=$(echo "$search_string" | sed -e 's/ */ /g' -e 's/-I /-I/g') path="${path%/}"
if test -e "$path/user_settings.h"; then
user_settings_dir="$path"
user_settings_path="$path/user_settings.h"
break
fi
;;
*)
;;
esac
done
for token in $search_string # Fall back to user_settings.h in the current directory.
do if test -z "${user_settings_path-}"; then
case "$token" in if test -e "user_settings.h"; then
-I*) user_settings_dir="."
# Trim off the leading "-I". user_settings_path="user_settings.h"
path=$(echo "$token" | cut -c 3-) fi
if test -e "$path/user_settings.h"; then
user_settings_dir="$path"
user_settings_path="$path/user_settings.h"
break
fi
;;
*)
;;
esac
done
fi fi
if test -z "$user_settings_path"; then if test -z "${user_settings_path-}"; then
echo "Unable to find user_settings.h." echo "Unable to find user_settings.h." 1>&2
exit 1 exit 1
else else
# Strip out anything from user_settings.h that isn't a preprocessor # Strip out anything from user_settings.h that isn't a preprocessor