Inherit as many flags as possible from redhat-rpm-config

This commit is contained in:
Florian Weimer 2018-02-28 12:40:17 +01:00
parent ee109af432
commit 081ef32d63

View File

@ -791,98 +791,38 @@ df
GCC=gcc
GXX=g++
##############################################################################
# %%build - x86 options.
##############################################################################
# On x86 we build for the specific target cpu rpm is using.
%ifarch %{ix86}
BuildFlags="-march=%{_target_cpu} -mtune=generic"
%endif
# We don't support building for i386. The generic i386 architecture lacks the
# atomic primitives required for NPTL support. However, when a user asks to
# build for i386 we interpret that as "for whatever works on x86" and we
# select i686. Thus we treat i386 as an alias for i686.
%ifarch i386 i686
BuildFlags="-march=i686 -mtune=generic"
%endif
%ifarch i486 i586
BuildFlags="$BuildFlags -mno-tls-direct-seg-refs"
%endif
%ifarch x86_64
BuildFlags="-mtune=generic"
%endif
# True if the compiler flag in the first argument is listed in
# redhat-rpm-config.
rpm_has_compiler_flag ()
{
echo " $RPM_OPT_FLAGS $RPM_LD_FLAGS " | grep -q -F " $1 "
}
##############################################################################
# %%build - s390 options.
##############################################################################
# The default is to tune for z13 (newer hardware), but build for zEC12.
%ifarch s390x
BuildFlags="-march=zEC12 -mtune=z13"
%endif
%ifarch s390
BuildFlags="-march=zEC12 -mtune=z13"
GCC="$GCC -m31"
GXX="$GXX -m31"
%endif
# Propagates the listed flags to BuildFlags if supplied by redhat-rpm-config.
BuildFlags="-O2 -g"
rpm_inherit_flags ()
{
local flag
for flag in "$@" ; do
if rpm_has_compiler_flag "$flag" ; then
BuildFlags="$BuildFlags $flag"
fi
done
}
##############################################################################
# %%build - SPARC options.
##############################################################################
%ifarch sparc
BuildFlags="-fcall-used-g6"
GCC="$GCC -m32"
GXX="$GXX -m32"
%endif
%ifarch sparcv9
BuildFlags="-mcpu=ultrasparc -fcall-used-g6"
GCC="$GCC -m32"
GXX="$GXX -m32"
%endif
%ifarch sparcv9v
BuildFlags="-mcpu=niagara -fcall-used-g6"
GCC="$GCC -m32"
GXX="$GXX -m32"
%endif
%ifarch sparc64
BuildFlags="-mcpu=ultrasparc -mvis -fcall-used-g6"
GCC="$GCC -m64"
GXX="$GXX -m64"
%endif
%ifarch sparc64v
BuildFlags="-mcpu=niagara -mvis -fcall-used-g6"
GCC="$GCC -m64"
GXX="$GXX -m64"
%endif
# Propgate select compiler flags from redhat-rpm-config. These flags
# are target-dependent, so we use only those which are specified in
# redhat-rpm-config. We do not replicate the -march=/-mtune=
# selection here because these match the defaults compiled into GCC.
# We keep the -m32/-m32/-m64 flags to support multilib builds.
##############################################################################
# %%build - POWER options.
##############################################################################
%ifarch %{power64}
BuildFlags=""
GCC="$GCC -m64"
GXX="$GXX -m64"
%ifarch ppc64p7
GCC="$GCC -mcpu=power7 -mtune=power7"
GXX="$GXX -mcpu=power7 -mtune=power7"
core_with_options="--with-cpu=power7"
%endif
%ifarch ppc64le
GCC="$GCC -mcpu=power8 -mtune=power8"
GXX="$GXX -mcpu=power8 -mtune=power8"
core_with_options="--with-cpu=power8"
%endif
%endif
##############################################################################
# %%build - MIPS options.
##############################################################################
%ifarch mips mipsel
BuildFlags="-march=mips32r2 -mfpxx"
%endif
%ifarch mips64 mips64el
# Without -mrelax-pic-calls ld.so segfaults when built with -O3
BuildFlags="-march=mips64r2 -mabi=64 -mrelax-pic-calls"
%endif
rpm_inherit_flags \
"-fasynchronous-unwind-tables" \
"-fstack-clash-protection" \
"-funwind-tables" \
"-m31" \
"-m32" \
"-m64" \
##############################################################################
# %%build - Generic options.
@ -901,19 +841,12 @@ echo "$GCC" > Gcc
##############################################################################
build()
{
builddir=build-%{target}${1:+-$1}
local builddir=build-%{target}${1:+-$1}
${1+shift}
rm -rf $builddir
mkdir $builddir
pushd $builddir
build_CFLAGS="$BuildFlags -g -O2 $*"
%ifnarch %{arm} riscv64
build_CFLAGS="$build_CFLAGS -fstack-clash-protection"
%endif
# Some configure checks can spuriously fail for some architectures if
# unwind info is present
configure_CFLAGS="$build_CFLAGS -fno-asynchronous-unwind-tables"
../configure CC="$GCC" CXX="$GXX" CFLAGS="$configure_CFLAGS" \
../configure CC="$GCC" CXX="$GXX" CFLAGS="$BuildFlags $*" \
--prefix=%{_prefix} \
--with-headers=%{_prefix}/include $EnableKernel \
--enable-bind-now \
@ -938,7 +871,7 @@ build()
--disable-nss-crypt ||
{ cat config.log; false; }
make %{?_smp_mflags} -O -r CFLAGS="$build_CFLAGS"
make %{?_smp_mflags} -O -r
popd
}