Nathan Chancellor | d5750cd | 2020-11-19 13:46:58 -0700 | [diff] [blame] | 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 | |
Nathan Chancellor | df58fb4 | 2021-11-15 09:43:23 -0700 | [diff] [blame^] | 9 | set -e |
Nathan Chancellor | d5750cd | 2020-11-19 13:46:58 -0700 | [diff] [blame] | 10 | |
Nathan Chancellor | df58fb4 | 2021-11-15 09:43:23 -0700 | [diff] [blame^] | 11 | # Convert the version string x.y.z to a canonical 5 or 6-digit form. |
| 12 | get_canonical_version() |
| 13 | { |
| 14 | IFS=. |
| 15 | set -- $1 |
| 16 | |
| 17 | # If the 2nd or 3rd field is missing, fill it with a zero. |
| 18 | echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0})) |
| 19 | } |
| 20 | |
| 21 | # Get the first line of the --version output. |
| 22 | IFS=' |
| 23 | ' |
| 24 | set -- $(LC_ALL=C "$@" --version) |
| 25 | |
| 26 | # Split the line on spaces. |
| 27 | IFS=' ' |
| 28 | set -- $1 |
| 29 | |
| 30 | while [ $# -gt 1 -a "$1" != "LLD" ]; do |
| 31 | shift |
| 32 | done |
| 33 | if [ "$1" = LLD ]; then |
| 34 | echo $(get_canonical_version ${2%-*}) |
| 35 | else |
Nathan Chancellor | d5750cd | 2020-11-19 13:46:58 -0700 | [diff] [blame] | 36 | echo 0 |
Nathan Chancellor | d5750cd | 2020-11-19 13:46:58 -0700 | [diff] [blame] | 37 | fi |