as-version.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-only
  3. #
  4. # Print the assembler name and its version in a 5 or 6-digit form.
  5. # Also, perform the minimum version check.
  6. # (If it is the integrated assembler, return 0 as the version, and
  7. # skip the version check.)
  8. set -e
  9. # Convert the version string x.y.z to a canonical 5 or 6-digit form.
  10. get_canonical_version()
  11. {
  12. IFS=.
  13. set -- $1
  14. # If the 2nd or 3rd field is missing, fill it with a zero.
  15. #
  16. # The 4th field, if present, is ignored.
  17. # This occurs in development snapshots as in 2.35.1.20201116
  18. echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
  19. }
  20. # Clang fails to handle -Wa,--version unless -fno-integrated-as is given.
  21. # We check -fintegrated-as, expecting it is explicitly passed in for the
  22. # integrated assembler case.
  23. check_integrated_as()
  24. {
  25. while [ $# -gt 0 ]; do
  26. if [ "$1" = -fintegrated-as ]; then
  27. # For the integrated assembler, we do not check the
  28. # version here. It is the same as the clang version, and
  29. # it has been already checked by scripts/cc-version.sh.
  30. echo LLVM 0
  31. exit 0
  32. fi
  33. shift
  34. done
  35. }
  36. check_integrated_as "$@"
  37. orig_args="$@"
  38. # Get the first line of the --version output.
  39. IFS='
  40. '
  41. set -- $(LC_ALL=C "$@" -Wa,--version -c -x assembler /dev/null -o /dev/null 2>/dev/null)
  42. # Split the line on spaces.
  43. IFS=' '
  44. set -- $1
  45. if [ "$1" = GNU -a "$2" = assembler ]; then
  46. shift $(($# - 1))
  47. version=$1
  48. name=GNU
  49. else
  50. echo "$orig_args: unknown assembler invoked" >&2
  51. exit 1
  52. fi
  53. # Some distributions append a package release number, as in 2.34-4.fc32
  54. # Trim the hyphen and any characters that follow.
  55. version=${version%-*}
  56. cversion=$(get_canonical_version $version)
  57. echo $name $cversion