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

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