From 5544371deb70e091e86d07f2755396b8a49729d7 Mon Sep 17 00:00:00 2001
From: Liu Yiding <liuyd.fnst@fujitsu.com>
Date: Wed, 28 Jan 2026 09:56:19 +0000
Subject: [PATCH] RH: use rpm optflags if present

Use the passed in optflags when compiling as an RPM, and keep the
default flags as close as possible to the current fedora flags, while
still being generic.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>

Upstream-Status: Pending

[OP: Rebase to 0.9.3]
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>

Rebase to 0.9.8
Signed-off-by: Changqing Li <changqing.li@windriver.com>

Rebase to 0.10.0
Signed-off-by: Yi Zhao <yi.zhao@windriver.com>

Rebase to 0.12.1
Signed-off-by: Liu Yiding <liuyd.fnst@fujitsu.com>

Rebase to 0.12.2
Signed-off-by: Liu Yiding <liuyd.fnst@fujitsu.com>
---
 Makefile.inc | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/Makefile.inc b/Makefile.inc
index 7ca96e58..8e168dc8 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -108,7 +108,15 @@ SYSTEMD_LIBDEPS := $(if $(SYSTEMD),$(if $(shell test $(SYSTEMD) -gt 209 && echo
 MODPROBE_UNIT := $(shell test "0$(SYSTEMD)" -lt 245 2>/dev/null || \
 			echo "modprobe@dm_multipath.service")
 
-OPTFLAGS	:= $(OPT) -g $(STACKPROT) --param=ssp-buffer-size=4
+ifndef RPM_OPT_FLAGS
+       OPTFLAGS        := -O2 -g $(STACKPROT) --param=ssp-buffer-size=4
+else
+       OPTFLAGS = $(RPM_OPT_FLAGS)
+endif
+OPTFLAGS       += -Wextra -Wstrict-prototypes -Wformat=0 -Werror=implicit-int \
+                  -Werror=implicit-function-declaration -Wno-sign-compare \
+                  -Wno-unused-parameter -Werror=cast-qual \
+                  -Werror=discarded-qualifiers
 
 # Set WARN_ONLY=1 to avoid compilation erroring out due to warnings. Useful during development.
 WARN_ONLY       :=
@@ -127,7 +135,7 @@ CPPFLAGS	:= $(FORTIFY_OPT) $(CPPFLAGS) $(D_URCU_VERSION) $(D_CMOCKA_VERSION) \
 		   -DABSTRACT_SOCKET=\"$(abstract_socket)\" -DPATHNAME_SOCKET=\"$(pathname_socket)\" \
 		   -DWSTRINGOP_TRUNCATION=$(if $(WSTRINGOP_TRUNCATION),1,0) \
 		   -MMD -MP
-CFLAGS		:= -std=$(C_STD) $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe \
+CFLAGS         := -std=$(C_STD) $(CFLAGS) $(OPTFLAGS) -pipe \
 		   -fexceptions -fno-strict-aliasing $(if $(ASAN),-fsanitize=address)
 BIN_CFLAGS	:= -fPIE -DPIE
 LIB_CFLAGS	:= -fPIC
-- 
2.43.0

