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