From 6e04472552cc4d64d43c43698139fd2bd20d3a4b Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Tue, 20 Feb 2018 08:25:04 +0100 Subject: [PATCH] Add RPM macros for compiler/linker flags Backport is quite useful so specs don't need to diverge between branches. Chery-Pick note: No documentation backport since there was no documentation back then in F27 so backporting means writing new one. (cherry picked from commit fa08f0e5a18d27663084a35e992083e8e38cc2a4) Reported-by: Jens Petersen Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1546643 Signed-off-by: Igor Gnatenko --- macros | 52 +++++++++++++++++++++++++++++++++--------- redhat-rpm-config.spec | 5 +++- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/macros b/macros index b2eeff0..fd53c16 100644 --- a/macros +++ b/macros @@ -24,6 +24,46 @@ %_debugsource_packages 1 %_debuginfo_subpackages 1 +#============================================================================== +# ---- compiler flags. + +# C compiler flags. This is traditionally called CFLAGS in makefiles. +# Historically also available as %%{optflags}, and %%build sets the +# environment variable RPM_OPT_FLAGS to this value. +%build_cflags %{optflags} + +# C++ compiler flags. This is traditionally called CXXFLAGS in makefiles. +%build_cxxflags %{optflags} + +# Fortran compiler flags. Makefiles use both FFLAGS and FCFLAGS as +# the corresponding variable names. +%build_fflags %{optflags} -I%{_fmoddir} + +# Link editor flags. This is usually called LDFLAGS in makefiles. +# (Some makefiles use LFLAGS instead.) The default value assumes that +# the flags, while intended for ld, are still passed through the gcc +# compiler driver. At the beginning of %%build, the environment +# variable RPM_LD_FLAGS to this value. +%build_ldflags -Wl,-z,relro %{_hardened_ldflags} + +# Expands to shell code to seot the compiler/linker environment +# variables CFLAGS, CXXFLAGS, FFLAGS, FCFLAGS, LDFLAGS if they have +# not been set already. RPM_OPT_FLAGS and RPM_LD_FLAGS have already +# been set implicitly at the start of the %%build section. +%set_build_flags \ + CFLAGS="${CFLAGS:-%{build_cflags}}" ; export CFLAGS ; \ + CXXFLAGS="${CXXFLAGS:-%{build_cxxflags}}" ; export CXXFLAGS ; \ + FFLAGS="${FFLAGS:-%{build_fflags}}" ; export FFLAGS ; \ + FCFLAGS="${FCFLAGS:-%{build_fflags}}" ; export FCFLAGS ; \ + LDFLAGS="${LDFLAGS:-%{build_ldflags}}" ; export LDFLAGS + +# Deprecated names. For backwards compatibility only. +%__global_cflags %{build_cflags} +%__global_cxxflags %{build_cxxflags} +%__global_fflags %{build_fflags} +%__global_fcflags %{build_fflags} +%__global_ldflags %{build_ldflags} + #============================================================================== # ---- configure and makeinstall. # @@ -35,11 +75,7 @@ # way to turn it back off. # %_configure_disable_silent_rules 1 %configure \ - CFLAGS="${CFLAGS:-%__global_cflags}" ; export CFLAGS ; \ - CXXFLAGS="${CXXFLAGS:-%__global_cxxflags}" ; export CXXFLAGS ; \ - FFLAGS="${FFLAGS:-%__global_fflags}" ; export FFLAGS ; \ - FCFLAGS="${FCFLAGS:-%__global_fcflags}" ; export FCFLAGS ; \ - LDFLAGS="${LDFLAGS:-%__global_ldflags}"; export LDFLAGS; \ + %{set_build_flags}; \ [ "%_configure_gnuconfig_hack" = 1 ] && for i in $(find $(dirname %{_configure}) -name config.guess -o -name config.sub) ; do \ [ -f /usr/lib/rpm/redhat/$(basename $i) ] && %{__rm} -f $i && %{__cp} -fv /usr/lib/rpm/redhat/$(basename $i) $i ; \ done ; \ @@ -150,12 +186,6 @@ %__global_compiler_flags -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches %{_hardened_cflags} -%__global_cflags %{optflags} -%__global_cxxflags %{optflags} -%__global_fflags %{optflags} -I%_fmoddir -%__global_fcflags %{optflags} -I%_fmoddir -%__global_ldflags -Wl,-z,relro %{_hardened_ldflags} - #============================================================================== # ---- Generic auto req/prov filtering macros # diff --git a/redhat-rpm-config.spec b/redhat-rpm-config.spec index be15487..1f90ac9 100644 --- a/redhat-rpm-config.spec +++ b/redhat-rpm-config.spec @@ -6,7 +6,7 @@ Summary: Red Hat specific rpm configuration files Name: redhat-rpm-config -Version: 70 +Version: 71 Release: 1%{?dist} # No version specified. License: GPL+ @@ -147,6 +147,9 @@ install -p -m 755 -t %{buildroot}%{_rpmconfigdir} kmod.prov %{_rpmconfigdir}/macros.d/macros.kmp %changelog +* Tue Feb 20 2018 Igor Gnatenko - 71-1 +- Backport %%set_build_flags + * Mon Jan 29 2018 Igor Gnatenko - 70-1 - Add macros.ldconfig