diff options
author | Sami Tolvanen <samitolvanen@google.com> | 2017-11-17 15:38:23 -0800 |
---|---|---|
committer | Bruno Martins <bgcngm@gmail.com> | 2022-10-28 15:57:23 +0100 |
commit | 3d01e1eba86b176412d8c962997f04e36dcb869c (patch) | |
tree | 5d9808651431e986f1040dea23f7763a0e494af7 /scripts/clang-version.sh | |
parent | 18dd378ab56327216e0fa6bd04e8d89213b159fc (diff) |
BACKPORT: FROMLIST: kbuild: add clang-version.sh
Based on gcc-version.sh, clang-version.sh prints out the correct
version of clang.
Bug: 62093296
Bug: 67506682
Change-Id: I399ed4cfbe30f6ac93e519abd84dd4c7cb96e32c
(am from https://patchwork.kernel.org/patch/10085763/)
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
(cherry picked from commit b7ee59ba3390b5c5766abed375bc51b0fd66a2f3)
Signed-off-by: Dan Aloni <daloni@magicleap.com>
Signed-off-by: Davide Garberi <dade.garberi@gmail.com>
Diffstat (limited to 'scripts/clang-version.sh')
-rwxr-xr-x | scripts/clang-version.sh | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/clang-version.sh b/scripts/clang-version.sh new file mode 100755 index 000000000000..9780efa56980 --- /dev/null +++ b/scripts/clang-version.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# clang-version [-p] clang-command +# +# Prints the compiler version of `clang-command' in a canonical 4-digit form +# such as `0500' for clang-5.0 etc. +# +# With the -p option, prints the patchlevel as well, for example `050001' for +# clang-5.0.1 etc. +# + +if [ "$1" = "-p" ] ; then + with_patchlevel=1; + shift; +fi + +compiler="$*" + +if [ ${#compiler} -eq 0 ]; then + echo "Error: No compiler specified." + printf "Usage:\n\t$0 <clang-command>\n" + exit 1 +fi + +MAJOR=$(echo __clang_major__ | $compiler -E -x c - | tail -n 1) +MINOR=$(echo __clang_minor__ | $compiler -E -x c - | tail -n 1) +if [ "x$with_patchlevel" != "x" ] ; then + PATCHLEVEL=$(echo __clang_patchlevel__ | $compiler -E -x c - | tail -n 1) + printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL +else + printf "%02d%02d\\n" $MAJOR $MINOR +fi |