使用 gcc micros 获取版本号
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用 gcc micros 获取版本号相关的知识,希望对你有一定的参考价值。
最近尝试在 openSUSE Tumbleweed 上编译 dpdk-2.2.0,mk/toolchain/gcc/rte.toolchain-compat.mk 报错,说 gcc 版本低于 4.X;看了一下,gcc 版本为 5.X。而 upstream 版本没有这个问题
对比了一下 upstream 的改动,顺便学习如何在 Makefile 中直接使用 gcc micros 来获取版本号信息:
commit a5c5b9f76767badb3f198326bd5cbbebba803e36
Author: Markos Chandras <[email protected]>
Date: Tue Mar 22 17:13:36 2016 +0000
mk: fix gcc-5 version on Suse
In openSUSE Tumbleweed (and in any other SUSE distribution which
uses (or will use) gcc >= 5), gcc -dumpversion returns ‘5‘. This is on
purpose as discussed in https://bugzilla.opensuse.org/show_bug.cgi?id=941428
As a result of which, the gcc-4.x comparison (40 against 5) does not
work leading to tons of warnings and failures during build.
This patch aims to change the way the gcc version is obtained by using
the gcc macros directly.
This is similar to what‘s being used in the Linux kernel. Querying the
GCC macros directly gives more accurate results compared to -dumpversion
which could vary across distributions.
Signed-off-by: Markos Chandras <[email protected]>
Acked-by: Thomas Monjalon <[email protected]>
diff --git a/mk/toolchain/gcc/rte.toolchain-compat.mk b/mk/toolchain/gcc/rte.toolchain-compat.mk
index e144216..6eed20c 100644
--- a/mk/toolchain/gcc/rte.toolchain-compat.mk
+++ b/mk/toolchain/gcc/rte.toolchain-compat.mk
@@ -38,7 +38,9 @@
#find out GCC version
-GCC_VERSION = $(subst .,,$(shell $(CC) -dumpversion | cut -f1-2 -d.))
+GCC_MAJOR = $(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
+GCC_MINOR = $(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1)
+GCC_VERSION = $(GCC_MAJOR)$(GCC_MINOR)
Author: Markos Chandras <[email protected]>
Date: Tue Mar 22 17:13:36 2016 +0000
mk: fix gcc-5 version on Suse
In openSUSE Tumbleweed (and in any other SUSE distribution which
uses (or will use) gcc >= 5), gcc -dumpversion returns ‘5‘. This is on
purpose as discussed in https://bugzilla.opensuse.org/show_bug.cgi?id=941428
As a result of which, the gcc-4.x comparison (40 against 5) does not
work leading to tons of warnings and failures during build.
This patch aims to change the way the gcc version is obtained by using
the gcc macros directly.
This is similar to what‘s being used in the Linux kernel. Querying the
GCC macros directly gives more accurate results compared to -dumpversion
which could vary across distributions.
Signed-off-by: Markos Chandras <[email protected]>
Acked-by: Thomas Monjalon <[email protected]>
diff --git a/mk/toolchain/gcc/rte.toolchain-compat.mk b/mk/toolchain/gcc/rte.toolchain-compat.mk
index e144216..6eed20c 100644
--- a/mk/toolchain/gcc/rte.toolchain-compat.mk
+++ b/mk/toolchain/gcc/rte.toolchain-compat.mk
@@ -38,7 +38,9 @@
#find out GCC version
-GCC_VERSION = $(subst .,,$(shell $(CC) -dumpversion | cut -f1-2 -d.))
+GCC_MAJOR = $(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
+GCC_MINOR = $(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1)
+GCC_VERSION = $(GCC_MAJOR)$(GCC_MINOR)
以上是关于使用 gcc micros 获取版本号的主要内容,如果未能解决你的问题,请参考以下文章