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

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