Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 23fb7597 authored by Sami Tolvanen's avatar Sami Tolvanen
Browse files

FROMLIST: kbuild: add __cc-ifversion and compiler-specific variants

This change adds macros for testing both compiler name and
version. Current cc-version, cc-ifversion etc. macros that test
gcc version are left unchanged to prevent compatibility issues
with existing tests.

Bug: 62093296
Bug: 67506682
Change-Id: I14965fcc21dae8dfe31881b172214bf6f8a9f440
(am from https://patchwork.kernel.org/patch/10085767/

)
Signed-off-by: default avatarSami Tolvanen <samitolvanen@google.com>
parent 85ccd0ce
Loading
Loading
Loading
Loading
+34 −3
Original line number Diff line number Diff line
@@ -142,6 +142,37 @@ cc-disable-warning = $(call try-run,\
# Expands to either gcc or clang
cc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)

# __cc-version
# Returns compiler version
__cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/$(cc-name)-version.sh $(CC))

# __cc-fullversion
# Returns full compiler version
__cc-fullversion = $(shell $(CONFIG_SHELL) \
	$(srctree)/scripts/$(cc-name)-version.sh -p $(CC))

# __cc-ifversion
# Matches compiler name and version
# Usage:  EXTRA_CFLAGS += $(call cc-if-name-version, gcc, -lt, 0402, -O1)
__cc-ifversion = $(shell [ $(cc-name) = $(1) ] && [ $(__cc-version) $(2) $(3) ] && echo $(4) || echo $(5))

# __cc-if-fullversion
# Matches compiler name and full version
# Usage:  EXTRA_CFLAGS += $(call cc-if-name-fullversion, gcc, -lt, 040502, -O1)
__cc-if-fullversion = $(shell [ $(cc-name) = $(1) ] && [ $(__cc-fullversion) $(2) $(3) ] && echo $(4) || echo $(5))

# gcc-ifversion
gcc-ifversion = $(call __cc-ifversion, gcc, $(1), $(2), $(3), $(4))

# gcc-if-fullversion
gcc-if-fullversion = (call __cc-if-fullversion, gcc, $(1), $(2), $(3), $(4))

# clang-ifversion
clang-ifversion =  $(call __cc-ifversion, clang, $(1), $(2), $(3), $(4))

# clang-if-fullversion
clang-if-fullversion = (call __cc-if-fullversion, clang, $(1), $(2), $(3), $(4))

# cc-version
cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))

@@ -149,9 +180,9 @@ cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
cc-fullversion = $(shell $(CONFIG_SHELL) \
	$(srctree)/scripts/gcc-version.sh -p $(CC))

# cc-ifversion
# Usage:  EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
cc-ifversion = $(shell [ $(cc-version) $(1) $(2) ] && echo $(3) || echo $(4))
# backward compatibility
cc-ifversion = $(gcc-ifversion)
cc-if-fullversion = $(gcc-if-fullversion)

# cc-if-fullversion
# Usage:  EXTRA_CFLAGS += $(call cc-if-fullversion, -lt, 040502, -O1)