Blame SOURCES/0014-RH-use-rpm-optflags-if-present.patch

5c2e41
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
5c2e41
From: Benjamin Marzinski <bmarzins@redhat.com>
5c2e41
Date: Wed, 19 Apr 2017 06:10:01 -0500
5c2e41
Subject: [PATCH] RH: use rpm optflags if present
5c2e41
5c2e41
Use the passed in optflags when compiling as an RPM, and keep the
5c2e41
default flags as close as possible to the current fedora flags, while
5c2e41
still being generic.
5c2e41
5c2e41
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
5c2e41
---
96a22b
 Makefile.inc | 29 +++++++++++++++++++++--------
96a22b
 1 file changed, 21 insertions(+), 8 deletions(-)
5c2e41
5c2e41
diff --git a/Makefile.inc b/Makefile.inc
96a22b
index 034752d9..c2abd301 100644
5c2e41
--- a/Makefile.inc
5c2e41
+++ b/Makefile.inc
96a22b
@@ -89,16 +89,29 @@ TEST_CC_OPTION = $(shell \
5c2e41
 		echo "$(2)"; \
5c2e41
 	fi)
5c2e41
 
5c2e41
-STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
5c2e41
 ERROR_DISCARDED_QUALIFIERS := $(call TEST_CC_OPTION,-Werror=discarded-qualifiers,)
96a22b
 WNOCLOBBERED := $(call TEST_CC_OPTION,-Wno-clobbered -Wno-error=clobbered,)
5c2e41
+ifndef RPM_OPT_FLAGS
5c2e41
+	STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
5c2e41
+	OPTFLAGS	= -O2 -g -pipe -Wall -Werror=format-security \
5c2e41
+			  -Wp,-D_FORTIFY_SOURCE=2 -fexceptions \
96a22b
+			  $(STACKPROT) -grecord-gcc-switches \
96a22b
+			  -fasynchronous-unwind-tables
5c2e41
+	ifeq ($(shell test -f /usr/lib/rpm/redhat/redhat-hardened-cc1 && echo 1),1)
5c2e41
+		OPTFLAGS += -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
5c2e41
+	endif
96a22b
+	ifeq ($(shell test -f /usr/lib/rpm/redhat/redhat-annobin-cc1 && echo 1),1)
96a22b
+		OPTFLAGS += -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1
96a22b
+	endif
5c2e41
+else
5c2e41
+	OPTFLAGS = $(RPM_OPT_FLAGS)
5c2e41
+endif
96a22b
+OPTFLAGS	+= -Werror -Wextra -Wstrict-prototypes -Wformat=2 \
96a22b
+		   -Werror=implicit-int -Werror=implicit-function-declaration \
96a22b
+		   $(WNOCLOBBERED) \
96a22b
+		   -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
96a22b
+		   --param=ssp-buffer-size=4
5c2e41
 
96a22b
-OPTFLAGS	= -O2 -g -pipe -Werror -Wall -Wextra -Wformat=2 -Werror=implicit-int \
96a22b
-		  -Werror=implicit-function-declaration -Werror=format-security \
96a22b
-		  $(WNOCLOBBERED) \
96a22b
-		  -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
96a22b
-		  $(STACKPROT) --param=ssp-buffer-size=4
96a22b
-CPPFLAGS	:= -Wp,-D_FORTIFY_SOURCE=2 
5c2e41
 CFLAGS		:= $(OPTFLAGS) -DBIN_DIR=\"$(bindir)\" -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" \
5c2e41
 		   -MMD -MP $(CFLAGS)
96a22b
 BIN_CFLAGS	= -fPIE -DPIE
96a22b
@@ -135,4 +148,4 @@ check_file = $(shell \
96a22b
 
96a22b
 %.o:	%.c
96a22b
 	@echo building $@ because of $?
96a22b
-	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
96a22b
+	$(CC) $(CFLAGS) -c -o $@ $<
5c2e41
-- 
a1c519
2.17.2
5c2e41