lld-version.sh 697 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Usage: $ ./scripts/lld-version.sh ld.lld
  5. #
  6. # Print the linker version of `ld.lld' in a 5 or 6-digit form
  7. # such as `100001' for ld.lld 10.0.1 etc.
  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. echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
  16. }
  17. # Get the first line of the --version output.
  18. IFS='
  19. '
  20. set -- $(LC_ALL=C "$@" --version)
  21. # Split the line on spaces.
  22. IFS=' '
  23. set -- $1
  24. while [ $# -gt 1 -a "$1" != "LLD" ]; do
  25. shift
  26. done
  27. if [ "$1" = LLD ]; then
  28. echo $(get_canonical_version ${2%-*})
  29. else
  30. echo 0
  31. fi