as-version.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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-with-cpp /dev/null -o /dev/null 2>/dev/null)
  42. # Split the line on spaces.
  43. IFS=' '
  44. set -- $1
  45. min_tool_version=$(dirname $0)/min-tool-version.sh
  46. if [ "$1" = GNU -a "$2" = assembler ]; then
  47. shift $(($# - 1))
  48. version=$1
  49. min_version=$($min_tool_version binutils)
  50. name=GNU
  51. else
  52. echo "$orig_args: unknown assembler invoked" >&2
  53. exit 1
  54. fi
  55. # Some distributions append a package release number, as in 2.34-4.fc32
  56. # Trim the hyphen and any characters that follow.
  57. version=${version%-*}
  58. cversion=$(get_canonical_version $version)
  59. min_cversion=$(get_canonical_version $min_version)
  60. if [ "$cversion" -lt "$min_cversion" ]; then
  61. echo >&2 "***"
  62. echo >&2 "*** Assembler is too old."
  63. echo >&2 "*** Your $name assembler version: $version"
  64. echo >&2 "*** Minimum $name assembler version: $min_version"
  65. echo >&2 "***"
  66. exit 1
  67. fi
  68. echo $name $cversion