Hi, Kéléfa Sané
Thank you for the patch.
On Mon, May 26, 2025 at 5:04 PM <devel-request(a)lists.crash-utility.osci.io>
wrote:
Date: Mon, 26 May 2025 11:03:24 +0200
From: kelefa.sane(a)smile.fr
Subject: [Crash-utility] [meta-oe][PATCH v2] Use CC env var to get
compiler version
To: devel(a)lists.crash-utility.osci.io
Cc: Kéléfa Sané <kelefa.sane(a)smile.fr>
Message-ID: <20250526090324.3113589-1-kelefa.sane(a)smile.fr>
Content-Type: text/plain; charset=UTF-8
From: Kéléfa Sané <kelefa.sane(a)smile.fr>
The source file build_data.c generated at compilation time define a
variable compiler_version which is obtained by calling "gcc --version"
cmd. This call retrieve the native gcc compiler install on host build
machine but not necessarily the compiler use to build the project (ex:
cross compilation).
Good findings.
The CC env variable commonly used in Makefile project define the
compiler to use at build, so this is the appropriate way to retrieve the
compiler version, when the CC env var is define.
If the CC env variable is not set, this is still a problem. We should not
expect that the CC env variable is always defined(or set).
I would suggest parsing the GDB_CONF_FLAGS to get the target gcc version,
which is visible in the configure.c
What do you think?
Thanks
Lianbo
Signed-off-by: Kéléfa Sané <kelefa.sane(a)smile.fr>
---
configure.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/configure.c b/configure.c
index 4668c9a..4b65bd7 100644
--- a/configure.c
+++ b/configure.c
@@ -1362,7 +1362,17 @@ make_build_data(char *target)
fp1 = popen("date", "r");
fp2 = popen("id", "r");
- fp3 = popen("gcc --version", "r");
+
+ const char *cc_env = getenv("CC");
+ if(NULL == cc_env) {
+ fp3 = popen("gcc --version", "r");
+ }
+ else {
+ char compiler_version_cmd[512];
+
+ snprintf(compiler_version_cmd,
sizeof(compiler_version_cmd), "%s --version", cc_env);
+ fp3 = popen(compiler_version_cmd, "r");
+ }
if ((fp4 = fopen("build_data.c", "w")) == NULL) {
perror("build_data.c");