Sami Tolvanen | ae0c553 | 2017-11-30 15:38:26 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: GPL-2.0 |
| 3 | # |
| 4 | # clang-version [-p] clang-command |
| 5 | # |
| 6 | # Prints the compiler version of `clang-command' in a canonical 4-digit form |
| 7 | # such as `0500' for clang-5.0 etc. |
| 8 | # |
| 9 | # With the -p option, prints the patchlevel as well, for example `050001' for |
| 10 | # clang-5.0.1 etc. |
| 11 | # |
| 12 | |
Sami Tolvanen | ae0c553 | 2017-11-30 15:38:26 -0800 | [diff] [blame] | 13 | compiler="$*" |
| 14 | |
Michael Forney | b5f8cb9 | 2018-08-15 17:13:50 -0700 | [diff] [blame^] | 15 | if ! ( $compiler --version | grep -q clang) ; then |
Masahiro Yamada | 469cb73 | 2018-05-28 18:22:02 +0900 | [diff] [blame] | 16 | echo 0 |
Sami Tolvanen | ae0c553 | 2017-11-30 15:38:26 -0800 | [diff] [blame] | 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | MAJOR=$(echo __clang_major__ | $compiler -E -x c - | tail -n 1) |
| 21 | MINOR=$(echo __clang_minor__ | $compiler -E -x c - | tail -n 1) |
Masahiro Yamada | 469cb73 | 2018-05-28 18:22:02 +0900 | [diff] [blame] | 22 | PATCHLEVEL=$(echo __clang_patchlevel__ | $compiler -E -x c - | tail -n 1) |
| 23 | printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL |