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

e65fa3
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
e65fa3
From: Benjamin Marzinski <bmarzins@redhat.com>
e65fa3
Date: Wed, 19 Apr 2017 06:10:01 -0500
e65fa3
Subject: [PATCH] RH: use rpm optflags if present
e65fa3
e65fa3
Use the passed in optflags when compiling as an RPM, and keep the
e65fa3
default flags as close as possible to the current fedora flags, while
e65fa3
still being generic.
e65fa3
e65fa3
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
e65fa3
---
e65fa3
 Makefile.inc | 26 +++++++++++++++++++-------
e65fa3
 1 file changed, 19 insertions(+), 7 deletions(-)
e65fa3
e65fa3
diff --git a/Makefile.inc b/Makefile.inc
e65fa3
index 2a75dc9c..5ac660de 100644
e65fa3
--- a/Makefile.inc
e65fa3
+++ b/Makefile.inc
e65fa3
@@ -92,23 +92,35 @@ TEST_CC_OPTION = $(shell \
e65fa3
 		echo "$(2)"; \
e65fa3
 	fi)
e65fa3
 
e65fa3
-STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
e65fa3
 ERROR_DISCARDED_QUALIFIERS := $(call TEST_CC_OPTION,-Werror=discarded-qualifiers,)
e65fa3
 WNOCLOBBERED := $(call TEST_CC_OPTION,-Wno-clobbered -Wno-error=clobbered,)
e65fa3
 WFORMATOVERFLOW := $(call TEST_CC_OPTION,-Wformat-overflow=2,)
e65fa3
 
e65fa3
-OPTFLAGS	:= -O2 -g $(STACKPROT) --param=ssp-buffer-size=4
e65fa3
-WARNFLAGS	:= -Werror -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) -Werror=implicit-int \
e65fa3
+ifndef RPM_OPT_FLAGS
e65fa3
+	STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)
e65fa3
+	OPTFLAGS := -O2 -g -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions \
e65fa3
+		    $(STACKPROT) -grecord-gcc-switches \
e65fa3
+		    -fasynchronous-unwind-tables --param=ssp-buffer-size=4
e65fa3
+	ifeq ($(shell test -f /usr/lib/rpm/redhat/redhat-hardened-cc1 && echo 1),1)
e65fa3
+		OPTFLAGS += -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
e65fa3
+	endif
e65fa3
+	ifeq ($(shell test -f /usr/lib/rpm/redhat/redhat-annobin-cc1 && echo 1),1)
e65fa3
+		OPTFLAGS += -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1
e65fa3
+	endif
e65fa3
+else
e65fa3
+	OPTFLAGS := $(RPM_OPT_FLAGS) --param=ssp-buffer-size=4
e65fa3
+endif
e65fa3
+WARNFLAGS	:= -Werror -Wextra -Wformat=2 $(WFORMATOVERFLOW) -Werror=implicit-int \
e65fa3
 		  -Werror=implicit-function-declaration -Werror=format-security \
e65fa3
-		  $(WNOCLOBBERED) -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS)
e65fa3
-CPPFLAGS	:= -Wp,-D_FORTIFY_SOURCE=2
e65fa3
+		  $(WNOCLOBBERED) -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
e65fa3
+		  -Wstrict-prototypes
e65fa3
 CFLAGS		:= --std=gnu99 $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe \
e65fa3
 		   -DBIN_DIR=\"$(bindir)\" -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" \
e65fa3
 		   -MMD -MP
e65fa3
 BIN_CFLAGS	= -fPIE -DPIE
e65fa3
 LIB_CFLAGS	= -fPIC
e65fa3
 SHARED_FLAGS	= -shared
e65fa3
-LDFLAGS		:= $(LDFLAGS) -Wl,-z,relro -Wl,-z,now -Wl,-z,defs
e65fa3
+LDFLAGS		:= $(LDFLAGS) $(RPM_LD_FLAGS) -Wl,-z,relro -Wl,-z,now -Wl,-z,defs
e65fa3
 BIN_LDFLAGS	= -pie
e65fa3
 
e65fa3
 # Check whether a function with name $1 has been declared in header file $2.
e65fa3
@@ -139,4 +151,4 @@ check_file = $(shell \
e65fa3
 
e65fa3
 %.o:	%.c
e65fa3
 	@echo building $@ because of $?
e65fa3
-	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
e65fa3
+	$(CC) $(CFLAGS) -c -o $@ $<