1ba64beb1SMasahiro Yamada#!/bin/sh 2ba64beb1SMasahiro Yamada# SPDX-License-Identifier: GPL-2.0-only 3ba64beb1SMasahiro Yamada# 4ba64beb1SMasahiro Yamada# Print the assembler name and its version in a 5 or 6-digit form. 5ba64beb1SMasahiro Yamada# Also, perform the minimum version check. 6ba64beb1SMasahiro Yamada# (If it is the integrated assembler, return 0 as the version, and 7ba64beb1SMasahiro Yamada# skip the version check.) 8ba64beb1SMasahiro Yamada 9ba64beb1SMasahiro Yamadaset -e 10ba64beb1SMasahiro Yamada 11ba64beb1SMasahiro Yamada# Convert the version string x.y.z to a canonical 5 or 6-digit form. 12ba64beb1SMasahiro Yamadaget_canonical_version() 13ba64beb1SMasahiro Yamada{ 14ba64beb1SMasahiro Yamada IFS=. 15ba64beb1SMasahiro Yamada set -- $1 16ba64beb1SMasahiro Yamada 17ba64beb1SMasahiro Yamada # If the 2nd or 3rd field is missing, fill it with a zero. 18ba64beb1SMasahiro Yamada # 19ba64beb1SMasahiro Yamada # The 4th field, if present, is ignored. 20ba64beb1SMasahiro Yamada # This occurs in development snapshots as in 2.35.1.20201116 21ba64beb1SMasahiro Yamada echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0})) 22ba64beb1SMasahiro Yamada} 23ba64beb1SMasahiro Yamada 24*2185a7e4SNathan Chancellor# Clang fails to handle -Wa,--version unless -fno-integrated-as is given. 25*2185a7e4SNathan Chancellor# We check -fintegrated-as, expecting it is explicitly passed in for the 26ba64beb1SMasahiro Yamada# integrated assembler case. 27ba64beb1SMasahiro Yamadacheck_integrated_as() 28ba64beb1SMasahiro Yamada{ 29ba64beb1SMasahiro Yamada while [ $# -gt 0 ]; do 30*2185a7e4SNathan Chancellor if [ "$1" = -fintegrated-as ]; then 31*2185a7e4SNathan Chancellor # For the integrated assembler, we do not check the 32ba64beb1SMasahiro Yamada # version here. It is the same as the clang version, and 33ba64beb1SMasahiro Yamada # it has been already checked by scripts/cc-version.sh. 34ba64beb1SMasahiro Yamada echo LLVM 0 35ba64beb1SMasahiro Yamada exit 0 36ba64beb1SMasahiro Yamada fi 37ba64beb1SMasahiro Yamada shift 38ba64beb1SMasahiro Yamada done 39ba64beb1SMasahiro Yamada} 40ba64beb1SMasahiro Yamada 41ba64beb1SMasahiro Yamadacheck_integrated_as "$@" 42ba64beb1SMasahiro Yamada 43ba64beb1SMasahiro Yamadaorig_args="$@" 44ba64beb1SMasahiro Yamada 45ba64beb1SMasahiro Yamada# Get the first line of the --version output. 46ba64beb1SMasahiro YamadaIFS=' 47ba64beb1SMasahiro Yamada' 48ba64beb1SMasahiro Yamadaset -- $(LC_ALL=C "$@" -Wa,--version -c -x assembler /dev/null -o /dev/null 2>/dev/null) 49ba64beb1SMasahiro Yamada 50ba64beb1SMasahiro Yamada# Split the line on spaces. 51ba64beb1SMasahiro YamadaIFS=' ' 52ba64beb1SMasahiro Yamadaset -- $1 53ba64beb1SMasahiro Yamada 54ba64beb1SMasahiro Yamadamin_tool_version=$(dirname $0)/min-tool-version.sh 55ba64beb1SMasahiro Yamada 56ba64beb1SMasahiro Yamadaif [ "$1" = GNU -a "$2" = assembler ]; then 57ba64beb1SMasahiro Yamada shift $(($# - 1)) 58ba64beb1SMasahiro Yamada version=$1 59ba64beb1SMasahiro Yamada min_version=$($min_tool_version binutils) 60ba64beb1SMasahiro Yamada name=GNU 61ba64beb1SMasahiro Yamadaelse 62ba64beb1SMasahiro Yamada echo "$orig_args: unknown assembler invoked" >&2 63ba64beb1SMasahiro Yamada exit 1 64ba64beb1SMasahiro Yamadafi 65ba64beb1SMasahiro Yamada 66ba64beb1SMasahiro Yamada# Some distributions append a package release number, as in 2.34-4.fc32 67ba64beb1SMasahiro Yamada# Trim the hyphen and any characters that follow. 68ba64beb1SMasahiro Yamadaversion=${version%-*} 69ba64beb1SMasahiro Yamada 70ba64beb1SMasahiro Yamadacversion=$(get_canonical_version $version) 71ba64beb1SMasahiro Yamadamin_cversion=$(get_canonical_version $min_version) 72ba64beb1SMasahiro Yamada 73ba64beb1SMasahiro Yamadaif [ "$cversion" -lt "$min_cversion" ]; then 74ba64beb1SMasahiro Yamada echo >&2 "***" 75ba64beb1SMasahiro Yamada echo >&2 "*** Assembler is too old." 76ba64beb1SMasahiro Yamada echo >&2 "*** Your $name assembler version: $version" 77ba64beb1SMasahiro Yamada echo >&2 "*** Minimum $name assembler version: $min_version" 78ba64beb1SMasahiro Yamada echo >&2 "***" 79ba64beb1SMasahiro Yamada exit 1 80ba64beb1SMasahiro Yamadafi 81ba64beb1SMasahiro Yamada 82ba64beb1SMasahiro Yamadaecho $name $cversion 83