18c2ecf20Sopenharmony_ci#!/bin/sh 28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only 38c2ecf20Sopenharmony_ci# 48c2ecf20Sopenharmony_ci# Print the assembler name and its version in a 5 or 6-digit form. 58c2ecf20Sopenharmony_ci# Also, perform the minimum version check. 68c2ecf20Sopenharmony_ci# (If it is the integrated assembler, return 0 as the version, and 78c2ecf20Sopenharmony_ci# skip the version check.) 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciset -e 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci# Convert the version string x.y.z to a canonical 5 or 6-digit form. 128c2ecf20Sopenharmony_ciget_canonical_version() 138c2ecf20Sopenharmony_ci{ 148c2ecf20Sopenharmony_ci IFS=. 158c2ecf20Sopenharmony_ci set -- $1 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci # If the 2nd or 3rd field is missing, fill it with a zero. 188c2ecf20Sopenharmony_ci # 198c2ecf20Sopenharmony_ci # The 4th field, if present, is ignored. 208c2ecf20Sopenharmony_ci # This occurs in development snapshots as in 2.35.1.20201116 218c2ecf20Sopenharmony_ci echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0})) 228c2ecf20Sopenharmony_ci} 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci# Clang fails to handle -Wa,--version unless -fno-integrated-as is given. 258c2ecf20Sopenharmony_ci# We check -fintegrated-as, expecting it is explicitly passed in for the 268c2ecf20Sopenharmony_ci# integrated assembler case. 278c2ecf20Sopenharmony_cicheck_integrated_as() 288c2ecf20Sopenharmony_ci{ 298c2ecf20Sopenharmony_ci while [ $# -gt 0 ]; do 308c2ecf20Sopenharmony_ci if [ "$1" = -fintegrated-as ]; then 318c2ecf20Sopenharmony_ci # For the integrated assembler, we do not check the 328c2ecf20Sopenharmony_ci # version here. It is the same as the clang version, and 338c2ecf20Sopenharmony_ci # it has been already checked by scripts/cc-version.sh. 348c2ecf20Sopenharmony_ci echo LLVM 0 358c2ecf20Sopenharmony_ci exit 0 368c2ecf20Sopenharmony_ci fi 378c2ecf20Sopenharmony_ci shift 388c2ecf20Sopenharmony_ci done 398c2ecf20Sopenharmony_ci} 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cicheck_integrated_as "$@" 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ciorig_args="$@" 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci# Get the first line of the --version output. 468c2ecf20Sopenharmony_ciIFS=' 478c2ecf20Sopenharmony_ci' 488c2ecf20Sopenharmony_ciset -- $(LC_ALL=C "$@" -Wa,--version -c -x assembler /dev/null -o /dev/null 2>/dev/null) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci# Split the line on spaces. 518c2ecf20Sopenharmony_ciIFS=' ' 528c2ecf20Sopenharmony_ciset -- $1 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ciif [ "$1" = GNU -a "$2" = assembler ]; then 558c2ecf20Sopenharmony_ci shift $(($# - 1)) 568c2ecf20Sopenharmony_ci version=$1 578c2ecf20Sopenharmony_ci name=GNU 588c2ecf20Sopenharmony_cielse 598c2ecf20Sopenharmony_ci echo "$orig_args: unknown assembler invoked" >&2 608c2ecf20Sopenharmony_ci exit 1 618c2ecf20Sopenharmony_cifi 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci# Some distributions append a package release number, as in 2.34-4.fc32 648c2ecf20Sopenharmony_ci# Trim the hyphen and any characters that follow. 658c2ecf20Sopenharmony_civersion=${version%-*} 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cicversion=$(get_canonical_version $version) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ciecho $name $cversion 70