Commit | Line | Data |
---|---|---|
ba64beb1 MY |
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 | ||
9 | set -e | |
10 | ||
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 | # | |
19 | # The 4th field, if present, is ignored. | |
20 | # This occurs in development snapshots as in 2.35.1.20201116 | |
21 | echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0})) | |
22 | } | |
23 | ||
2185a7e4 NC |
24 | # Clang fails to handle -Wa,--version unless -fno-integrated-as is given. |
25 | # We check -fintegrated-as, expecting it is explicitly passed in for the | |
ba64beb1 MY |
26 | # integrated assembler case. |
27 | check_integrated_as() | |
28 | { | |
29 | while [ $# -gt 0 ]; do | |
2185a7e4 NC |
30 | if [ "$1" = -fintegrated-as ]; then |
31 | # For the integrated assembler, we do not check the | |
ba64beb1 MY |
32 | # version here. It is the same as the clang version, and |
33 | # it has been already checked by scripts/cc-version.sh. | |
34 | echo LLVM 0 | |
35 | exit 0 | |
36 | fi | |
37 | shift | |
38 | done | |
39 | } | |
40 | ||
41 | check_integrated_as "$@" | |
42 | ||
43 | orig_args="$@" | |
44 | ||
45 | # Get the first line of the --version output. | |
46 | IFS=' | |
47 | ' | |
48 | set -- $(LC_ALL=C "$@" -Wa,--version -c -x assembler /dev/null -o /dev/null 2>/dev/null) | |
49 | ||
50 | # Split the line on spaces. | |
51 | IFS=' ' | |
52 | set -- $1 | |
53 | ||
54 | min_tool_version=$(dirname $0)/min-tool-version.sh | |
55 | ||
56 | if [ "$1" = GNU -a "$2" = assembler ]; then | |
57 | shift $(($# - 1)) | |
58 | version=$1 | |
59 | min_version=$($min_tool_version binutils) | |
60 | name=GNU | |
61 | else | |
62 | echo "$orig_args: unknown assembler invoked" >&2 | |
63 | exit 1 | |
64 | fi | |
65 | ||
66 | # Some distributions append a package release number, as in 2.34-4.fc32 | |
67 | # Trim the hyphen and any characters that follow. | |
68 | version=${version%-*} | |
69 | ||
70 | cversion=$(get_canonical_version $version) | |
71 | min_cversion=$(get_canonical_version $min_version) | |
72 | ||
73 | if [ "$cversion" -lt "$min_cversion" ]; then | |
74 | echo >&2 "***" | |
75 | echo >&2 "*** Assembler is too old." | |
76 | echo >&2 "*** Your $name assembler version: $version" | |
77 | echo >&2 "*** Minimum $name assembler version: $min_version" | |
78 | echo >&2 "***" | |
79 | exit 1 | |
80 | fi | |
81 | ||
82 | echo $name $cversion |