Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0-only
0003 #
0004 # Print the assembler name and its version in a 5 or 6-digit form.
0005 # Also, perform the minimum version check.
0006 # (If it is the integrated assembler, return 0 as the version, and
0007 # skip the version check.)
0008 
0009 set -e
0010 
0011 # Convert the version string x.y.z to a canonical 5 or 6-digit form.
0012 get_canonical_version()
0013 {
0014         IFS=.
0015         set -- $1
0016 
0017         # If the 2nd or 3rd field is missing, fill it with a zero.
0018         #
0019         # The 4th field, if present, is ignored.
0020         # This occurs in development snapshots as in 2.35.1.20201116
0021         echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
0022 }
0023 
0024 # Clang fails to handle -Wa,--version unless -fno-integrated-as is given.
0025 # We check -fintegrated-as, expecting it is explicitly passed in for the
0026 # integrated assembler case.
0027 check_integrated_as()
0028 {
0029         while [ $# -gt 0 ]; do
0030                 if [ "$1" = -fintegrated-as ]; then
0031                         # For the integrated assembler, we do not check the
0032                         # version here. It is the same as the clang version, and
0033                         # it has been already checked by scripts/cc-version.sh.
0034                         echo LLVM 0
0035                         exit 0
0036                 fi
0037                 shift
0038         done
0039 }
0040 
0041 check_integrated_as "$@"
0042 
0043 orig_args="$@"
0044 
0045 # Get the first line of the --version output.
0046 IFS='
0047 '
0048 set -- $(LC_ALL=C "$@" -Wa,--version -c -x assembler /dev/null -o /dev/null 2>/dev/null)
0049 
0050 # Split the line on spaces.
0051 IFS=' '
0052 set -- $1
0053 
0054 min_tool_version=$(dirname $0)/min-tool-version.sh
0055 
0056 if [ "$1" = GNU -a "$2" = assembler ]; then
0057         shift $(($# - 1))
0058         version=$1
0059         min_version=$($min_tool_version binutils)
0060         name=GNU
0061 else
0062         echo "$orig_args: unknown assembler invoked" >&2
0063         exit 1
0064 fi
0065 
0066 # Some distributions append a package release number, as in 2.34-4.fc32
0067 # Trim the hyphen and any characters that follow.
0068 version=${version%-*}
0069 
0070 cversion=$(get_canonical_version $version)
0071 min_cversion=$(get_canonical_version $min_version)
0072 
0073 if [ "$cversion" -lt "$min_cversion" ]; then
0074         echo >&2 "***"
0075         echo >&2 "*** Assembler is too old."
0076         echo >&2 "***   Your $name assembler version:    $version"
0077         echo >&2 "***   Minimum $name assembler version: $min_version"
0078         echo >&2 "***"
0079         exit 1
0080 fi
0081 
0082 echo $name $cversion