Skip to content

Commit 469cb73

Browse files
committed
kconfig: add CC_IS_CLANG and CLANG_VERSION
This will be useful to describe the clang version dependency. Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Kees Cook <[email protected]>
1 parent a435389 commit 469cb73

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

init/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ config GCC_VERSION
1616
default $(shell,$(srctree)/scripts/gcc-version.sh -p $(CC) | sed 's/^0*//') if CC_IS_GCC
1717
default 0
1818

19+
config CC_IS_CLANG
20+
def_bool $(success,$(CC) --version | head -n 1 | grep -q clang)
21+
22+
config CLANG_VERSION
23+
int
24+
default $(shell,$(srctree)/scripts/clang-version.sh $(CC))
25+
1926
config CONSTRUCTORS
2027
bool
2128
depends on !UML

scripts/clang-version.sh

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,14 @@
1010
# clang-5.0.1 etc.
1111
#
1212

13-
if [ "$1" = "-p" ] ; then
14-
with_patchlevel=1;
15-
shift;
16-
fi
17-
1813
compiler="$*"
1914

20-
if [ ${#compiler} -eq 0 ]; then
21-
echo "Error: No compiler specified."
22-
printf "Usage:\n\t$0 <clang-command>\n"
15+
if !( $compiler --version | grep -q clang) ; then
16+
echo 0
2317
exit 1
2418
fi
2519

2620
MAJOR=$(echo __clang_major__ | $compiler -E -x c - | tail -n 1)
2721
MINOR=$(echo __clang_minor__ | $compiler -E -x c - | tail -n 1)
28-
if [ "x$with_patchlevel" != "x" ] ; then
29-
PATCHLEVEL=$(echo __clang_patchlevel__ | $compiler -E -x c - | tail -n 1)
30-
printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL
31-
else
32-
printf "%02d%02d\\n" $MAJOR $MINOR
33-
fi
22+
PATCHLEVEL=$(echo __clang_patchlevel__ | $compiler -E -x c - | tail -n 1)
23+
printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL

0 commit comments

Comments
 (0)