From: Alejandro Colomar <alx@kernel.org>
To: liba2i@lists.linux.dev
Cc: Alejandro Colomar <alx@kernel.org>, Sam James <sam@gentoo.org>
Subject: [PATCH v1] share/mk/: CPPFLAGS: Only define _FORTIFY_SOURCE if it's not already defined
Date: Wed, 17 Jul 2024 19:08:24 +0200 [thread overview]
Message-ID: <20240717170814.21109-2-alx@kernel.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 1776 bytes --]
Reported-by: Sam James <sam@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
Hi Sam,
I've tested it and it seems to work as one would expect.
Cheers,
Alex
Range-diff against v0:
-: --------- > 1: 1415c5704 share/mk/: CPPFLAGS: Only define _FORTIFY_SOURCE if it's not already defined
share/mk/configure/build-depends/cpp/cpp.mk | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/share/mk/configure/build-depends/cpp/cpp.mk b/share/mk/configure/build-depends/cpp/cpp.mk
index 11ba5448d..ec8068458 100644
--- a/share/mk/configure/build-depends/cpp/cpp.mk
+++ b/share/mk/configure/build-depends/cpp/cpp.mk
@@ -6,15 +6,31 @@ ifndef MAKEFILE_CONFIGURE_BUILD_DEPENDS_CPP_CPP_INCLUDED
MAKEFILE_CONFIGURE_BUILD_DEPENDS_CPP_CPP_INCLUDED := 1
+include $(MAKEFILEDIR)/configure/build-depends/coreutils/echo.mk
include $(MAKEFILEDIR)/configure/build-depends/gcc/cc.mk
+include $(MAKEFILEDIR)/configure/build-depends/grep/grep.mk
include $(MAKEFILEDIR)/configure/build-depends/pkgconf/pkgconf.mk
include $(MAKEFILEDIR)/configure/verbose.mk
+CPP := $(CC) $(CFLAGS_) -E
+
+
+CPP_HAS_ALREADY_D_FORTIFY_SOURCE := \
+ $(shell \
+ $(CPP) -dM - -Wno-error </dev/null \
+ | $(GREP) '#define _FORTIFY_SOURCE ' >/dev/null \
+ && $(ECHO) yes \
+ || $(ECHO) no; \
+ )
+
+
DEFAULT_CPPFLAGS := \
$(shell $(PKGCONF_CMD) --cflags $(pc) $(HIDE_ERR)) \
- -D_FORTIFY_SOURCE=2 \
-I$(srcdir)/
+ifeq ($(CPP_HAS_ALREADY_D_FORTIFY_SOURCE),no)
+DEFAULT_CPPFLAGS += -D_FORTIFY_SOURCE=2
+endif
CPPFLAGS :=
CPPFLAGS_ := $(DEFAULT_CPPFLAGS) $(CPPFLAGS)
CPP := $(CC) $(CFLAGS_) -E
base-commit: a264f9442e64d555451104257538124f831db854
--
2.45.2
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next reply other threads:[~2024-07-17 17:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-17 17:08 Alejandro Colomar [this message]
2024-07-17 17:19 ` [PATCH v1] share/mk/: CPPFLAGS: Only define _FORTIFY_SOURCE if it's not already defined Alejandro Colomar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240717170814.21109-2-alx@kernel.org \
--to=alx@kernel.org \
--cc=liba2i@lists.linux.dev \
--cc=sam@gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.