Blame SOURCES/0017-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
---
ebef98
 Makefile.inc | 26 +++++++++++++++++++-------
ebef98
 1 file changed, 19 insertions(+), 7 deletions(-)
68b27c
68b27c
diff --git a/Makefile.inc b/Makefile.inc
ebef98
index 2a75dc9c..5ac660de 100644
68b27c
--- a/Makefile.inc
68b27c
+++ b/Makefile.inc
ebef98
@@ -92,23 +92,35 @@ 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,)
ebef98
 WFORMATOVERFLOW := $(call TEST_CC_OPTION,-Wformat-overflow=2,)
68b27c
 
68b27c
-OPTFLAGS	:= -O2 -g $(STACKPROT) --param=ssp-buffer-size=4
ebef98
-WARNFLAGS	:= -Werror -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) -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
ebef98
+WARNFLAGS	:= -Werror -Wextra -Wformat=2 $(WFORMATOVERFLOW) -Werror=implicit-int \
68b27c
 		  -Werror=implicit-function-declaration -Werror=format-security \
68b27c
-		  $(WNOCLOBBERED) -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS)
ebef98
-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
ebef98
 BIN_CFLAGS	= -fPIE -DPIE
ebef98
 LIB_CFLAGS	= -fPIC
ebef98
 SHARED_FLAGS	= -shared
ebef98
-LDFLAGS		:= $(LDFLAGS) -Wl,-z,relro -Wl,-z,now -Wl,-z,defs
ebef98
+LDFLAGS		:= $(LDFLAGS) $(RPM_LD_FLAGS) -Wl,-z,relro -Wl,-z,now -Wl,-z,defs
ebef98
 BIN_LDFLAGS	= -pie
ebef98
 
ebef98
 # Check whether a function with name $1 has been declared in header file $2.
ebef98
@@ -139,4 +151,4 @@ check_file = $(shell \
68b27c
 
68b27c
 %.o:	%.c
68b27c
 	@echo building $@ because of $?
68b27c
-	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
68b27c
+	$(CC) $(CFLAGS) -c -o $@ $<