#!/bin/sh1# SPDX-License-Identifier: GPL-2.0-only2#3# Print the assembler name and its version in a 5 or 6-digit form.4# Also, perform the minimum version check.5# (If it is the integrated assembler, return 0 as the version, and6# skip the version check.)78set -e910# Convert the version string x.y.z to a canonical 5 or 6-digit form.11get_canonical_version()12{13IFS=.14set -- $11516# If the 2nd or 3rd field is missing, fill it with a zero.17#18# The 4th field, if present, is ignored.19# This occurs in development snapshots as in 2.35.1.2020111620echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))21}2223# Clang fails to handle -Wa,--version unless -fno-integrated-as is given.24# We check -fintegrated-as, expecting it is explicitly passed in for the25# integrated assembler case.26check_integrated_as()27{28while [ $# -gt 0 ]; do29if [ "$1" = -fintegrated-as ]; then30# For the integrated assembler, we do not check the31# version here. It is the same as the clang version, and32# it has been already checked by scripts/cc-version.sh.33echo LLVM 034exit 035fi36shift37done38}3940check_integrated_as "$@"4142orig_args="$@"4344# Get the first line of the --version output.45IFS='46'47set -- $(LC_ALL=C "$@" -Wa,--version -c -x assembler-with-cpp /dev/null -o /dev/null 2>/dev/null)4849# Split the line on spaces.50IFS=' '51set -- $15253min_tool_version=$(dirname $0)/min-tool-version.sh5455if [ "$1" = GNU -a "$2" = assembler ]; then56shift $(($# - 1))57version=$158min_version=$($min_tool_version binutils)59name=GNU60else61echo "$orig_args: unknown assembler invoked" >&262exit 163fi6465# Some distributions append a package release number, as in 2.34-4.fc3266# Trim the hyphen and any characters that follow.67version=${version%-*}6869cversion=$(get_canonical_version $version)70min_cversion=$(get_canonical_version $min_version)7172if [ "$cversion" -lt "$min_cversion" ]; then73echo >&2 "***"74echo >&2 "*** Assembler is too old."75echo >&2 "*** Your $name assembler version: $version"76echo >&2 "*** Minimum $name assembler version: $min_version"77echo >&2 "***"78exit 179fi8081echo $name $cversion828384