Add RPM macros for compiler/linker flags
This commit is contained in:
parent
222670e2e7
commit
fa08f0e5a1
@ -5,8 +5,9 @@ and how to use them.
|
||||
|
||||
# Using RPM build flags
|
||||
|
||||
At present, the only supported way is to use the `%configure` macro to
|
||||
obtain the full complement of flags, like this:
|
||||
For packages which use autoconf to set up the build environment, use
|
||||
the `%configure` macro to obtain the full complement of flags, like
|
||||
this:
|
||||
|
||||
%configure
|
||||
|
||||
@ -15,9 +16,36 @@ This will invoke the `./configure` with arguments (such as
|
||||
|
||||
As a side effect, this will set the environment variables `CFLAGS`,
|
||||
`CXXFLAGS`, `FFLAGS`, `FCFLAGS`, and `LDFLAGS`, so they can be used by
|
||||
makefiles and other build tools.
|
||||
makefiles and other build tools. (However, existing values for this
|
||||
variables are not overwritten.)
|
||||
|
||||
For some other build tools besides `autoconf`, separate mechanisms exist:
|
||||
If your package does not use autoconf, you can still set the same
|
||||
environment variables using
|
||||
|
||||
%set_build_flags
|
||||
|
||||
early in the `%build` section. (Again, existing environment variables
|
||||
are not overwritten.)
|
||||
|
||||
Individual build flags are also available through RPM macros:
|
||||
|
||||
* `%{build_cflags}` for the C compiler flags (also known as the
|
||||
`CFLAGS` variable). Also historically available as `%{optflags}`.
|
||||
Furthermore, at the start of the `%build` section, the environment
|
||||
variable `RPM_OPT_FLAGS` is set to this value.
|
||||
* `%{build_cxxflags} for the C++ compiler flags (usually assigned to
|
||||
the `CXXFLAGS` shell variable).
|
||||
* `%{build_fflags} for `FFLAGS` (the Fortran compiler flags, also
|
||||
known as the `FCFLAGS` variable).
|
||||
* `{%build_ldflags}` for the link editor (ld) flags, usually known as
|
||||
`LDFLAGS`. Note that the contents quotes linker arguments using
|
||||
`-Wl`, so this variable is intended for use with the `gcc` compiler
|
||||
driver. At the start of the `%build` section, the environment
|
||||
variable `RPM_LD_FLAGS` is set to this value.
|
||||
|
||||
These RPM macros do not alter shell environment variables.
|
||||
|
||||
For some other build tools separate mechanisms exist:
|
||||
|
||||
* CMake builds use the the `%cmake` macro from the `cmake-rpm-macros`
|
||||
package.
|
||||
|
52
macros
52
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 %{_ld_symbols_flags} %{_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 ; \
|
||||
@ -178,12 +214,6 @@
|
||||
|
||||
%__global_compiler_flags -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches %{_hardened_cflags} %{_annotated_cflags}
|
||||
|
||||
%__global_cflags %{optflags}
|
||||
%__global_cxxflags %{optflags}
|
||||
%__global_fflags %{optflags} -I%_fmoddir
|
||||
%__global_fcflags %{optflags} -I%_fmoddir
|
||||
%__global_ldflags -Wl,-z,relro %{_ld_symbols_flags} %{_hardened_ldflags}
|
||||
|
||||
#==============================================================================
|
||||
# ---- Generic auto req/prov filtering macros
|
||||
#
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
Summary: Red Hat specific rpm configuration files
|
||||
Name: redhat-rpm-config
|
||||
Version: 93
|
||||
Version: 94
|
||||
Release: 1%{?dist}
|
||||
# No version specified.
|
||||
License: GPL+
|
||||
@ -183,6 +183,9 @@ install -p -m 755 -t %{buildroot}%{_rpmconfigdir} kmod.prov
|
||||
%{_rpmconfigdir}/macros.d/macros.kmp
|
||||
|
||||
%changelog
|
||||
* Sun Feb 4 2018 Florian Weimer <fweimer@redhat.com> - 94-1
|
||||
- Add RPM macros for compiler/linker flags
|
||||
|
||||
* Sat Feb 03 2018 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 93-1
|
||||
- Use newly available /usr/bin/grep
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user