user_settings_asm.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. if test $# -eq 0; then
  3. echo "user_settings_asm.sh requires one argument specifying compiler flags to pull include directories from." 1>&2
  4. exit 1
  5. fi
  6. # Compress multiple spaces to single spaces, then replace instances of
  7. # "-I " with "-I" (i.e. remove spaces between -I and the include path).
  8. search_string=$(echo "$1" | sed -e 's/ */ /g' -e 's/-I /-I/g')
  9. for token in $search_string
  10. do
  11. case "$token" in
  12. -I*)
  13. # Trim off the leading "-I".
  14. path="${token#-I}"
  15. # Trim off the trailing "/".
  16. path="${path%/}"
  17. if test -e "$path/user_settings.h"; then
  18. user_settings_dir="$path"
  19. user_settings_path="$path/user_settings.h"
  20. break
  21. fi
  22. ;;
  23. *)
  24. ;;
  25. esac
  26. done
  27. # Fall back to user_settings.h in the current directory.
  28. if test -z "${user_settings_path-}"; then
  29. if test -e "user_settings.h"; then
  30. user_settings_dir="."
  31. user_settings_path="user_settings.h"
  32. fi
  33. fi
  34. if test -z "${user_settings_path-}"; then
  35. echo "Unable to find user_settings.h." 1>&2
  36. exit 1
  37. else
  38. # Strip out anything from user_settings.h that isn't a preprocessor
  39. # directive (i.e. any lines not starting with #). Put the result in
  40. # user_settings_asm.h in the same directory as user_settings.h.
  41. # user_settings_asm.h is safe to include in assembly files (e.g. .S
  42. # files).
  43. sed -e '/^ *#/!d' -e :a -e '$!N;s/\\\n/ /;ta' -e 'P;D' < "$user_settings_path" > "$user_settings_dir/user_settings_asm.h"
  44. fi