[PATCH master] kbuild: don't define _GNU_SOURCE if already defined
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed Jul 2 03:59:31 PDT 2025
When built with PTXdist, compilation of some files like
scripts/kconfig/lxdialog/yesno.c ends up with multiple differing definitions
for _GNU_SOURCE:
gcc [...] -std=gnu11 -D_GNU_SOURCE="" -D_GNU_SOURCE -I/usr/include/ncursesw
This leads to ugly warnings when running ptxdist menuconfig.
This is due to a hardcoded `echo -D_GNU_SOURCE > ${cflags}` we fall back
to in mconf-cfg.sh, when there is no pkg-config file for ncurses, which
seems to be the case for PTXdist.
Fix the warnings by defining _GNU_SOURCE only if it's not already
defined.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
Makefile | 2 +-
scripts/include/defines.h | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
create mode 100644 scripts/include/defines.h
diff --git a/Makefile b/Makefile
index d9bfaa8cce1b..59531a326d81 100644
--- a/Makefile
+++ b/Makefile
@@ -406,7 +406,7 @@ endif
KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
-O2 -fomit-frame-pointer -std=gnu11 \
- -D_GNU_SOURCE=""
+ -include $(srctree)/scripts/include/defines.h
KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)
KBUILD_USERLDFLAGS := $(USERLDFLAGS)
diff --git a/scripts/include/defines.h b/scripts/include/defines.h
new file mode 100644
index 000000000000..dd28765f9e7d
--- /dev/null
+++ b/scripts/include/defines.h
@@ -0,0 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* This file is autoincluded for all user programs */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
--
2.39.5
More information about the barebox
mailing list