diff options
author | Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org> | 2012-07-14 13:30:30 +0159 |
---|---|---|
committer | Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org> | 2012-12-01 01:12:40 +0100 |
commit | b6887664b07f6d638b4d4d9b79cb80e0be863bd4 (patch) | |
tree | 729f41e00dc90bb60d2ab0e3336a35067265c15d | |
parent | 4e667d6eb79e93f89580fab7badddb7d92b5d111 (diff) | |
download | build-b6887664b07f6d638b4d4d9b79cb80e0be863bd4.tar.gz |
build/core: Add linaro_compilerchecks.mk
Add linaro_compilerchecks.mk, allowing to run some checks on the
compiler version and supported flags before setting them
Change-Id: I96e1277e74c0ea3457677bef39644aaece01f653
Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
-rw-r--r-- | core/linaro_compilerchecks.mk | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/core/linaro_compilerchecks.mk b/core/linaro_compilerchecks.mk new file mode 100644 index 0000000000..d172703ab2 --- /dev/null +++ b/core/linaro_compilerchecks.mk @@ -0,0 +1,43 @@ +# The try-run, cc-version, cc-ifversion and cc-option macros are inspired +# by the Linux kernel build system's versions of the macros with the same +# name. +# +# The implementations here are rewritten to avoid license clashes, and +# they're a lot simpler than their kernel counterparts because, at least +# for now, we don't need to support all the compilers the kernel supports, +# and we don't need to be aware of all the details the kernel checks for. +# +# Usage examples: +# echo "GCC version $(cc-version)" [e.g. 46 for 4.6] +# echo $(call cc-ifversion, -lt, 46, GCC older than 4.6) +# # Use -mcpu=cortex-a9 if supported, otherwise -mcpu=cortex-a8 +# echo $(call cc-option, -mcpu=cortex-a9, -mcpu=cortex-a8) +# # Use -mcpu=cortex-a9 if supported, otherwise -mcpu=cortex-a8 +# # if supported, otherwise nothing +# echo $(call cc-option, -mcpu=cortex-a9, $(call cc-option, -mcpu=cortex-a8)) +# + +# We have to do our own version of setting TARGET_CC because we can be +# included before TARGET_CC is set, but we may want to use cc-option and +# friends in the same file that sets TARGET_CC... + +ifeq ($(strip $(TARGET_TOOLS_PREFIX)),) +LINARO_COMPILERCHECK_CC := prebuilts/gcc/$(HOST_PREBUILT_TAG)/arm/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-gcc$(HOST_EXECUTABLE_SUFFIX) +else +LINARO_COMPILERCHECK_CC := $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX) +endif + +try-run = $(shell set -e; \ + if ($(1)) >/dev/null 2>&1; then \ + echo "$(2)"; \ + else \ + echo "$(3)"; \ + fi) + +cc-version = $(shell echo '__GNUC__ __GNUC_MINOR__' \ + |$(LINARO_COMPILERCHECK_CC) -E -xc - |tail -n1 |sed -e 's, ,,g') + +cc-ifversion = $(shell [ $(call cc-version) $(1) $(2) ] && echo $(3)) + +cc-option = $(call try-run, echo -e "$(1)" \ + |$(LINARO_COMPILERCHECK_CC) $(1) -c -xc /dev/null -o /dev/null,$(1),$(2)) |