gcc: Allow setting custom target CXXFLAGS

This commit adds two additional arguments (`cxxflags_for_target` and
`extra_cxxflags_for_target`) for the gcc backend build function that
can be used to specify custom target CXXFLAGS.

By default, the target CXXFLAGS is set to the target CFLAGS. When
`cxxflags_for_target` is specified however, it overrides that behaviour
and allows setting different target CXXFLAGS from the target CFLAGS.

The `extra_cxxflags_for_target` argument can be used to specify the
extra target CXXFLAGS to be appended to the target CXXFLAGS. This is
useful when it is necessary to append CXX-specific flags to the
existing CFLAGS to be used as the target CXXFLAGS.

A useful application of this is building full and nano versions of
libstdc++ with different target CXXFLAGS as necessitated by
`nano.specs`.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
This commit is contained in:
Stephanos Ioannidis 2021-06-07 14:42:06 +09:00
parent 3c637c1eec
commit fffa4c5aa5

View File

@ -295,7 +295,8 @@ do_gcc_core_backend() {
local enable_optspace
local complibs
local lang_list
local cflags cflags_for_build cflags_for_target
local cflags cflags_for_build cflags_for_target cxxflags_for_target
local extra_cxxflags_for_target
local ldflags
local build_step
local log_txt
@ -611,6 +612,16 @@ do_gcc_core_backend() {
# Assume '-O2' by default for building target libraries.
cflags_for_target="-g -O2 ${cflags_for_target}"
# Set target CXXFLAGS to CFLAGS if none is provided.
if [ -z "${cxxflags_for_target}" ]; then
cxxflags_for_target="${cflags_for_target}"
fi
# Append extra CXXFLAGS if provided.
if [ -n "${extra_cxxflags_for_target}" ]; then
cxxflags_for_target="${cxxflags_for_target} ${extra_cxxflags_for_target}"
fi
# Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532).
# Pass only user-specified CFLAGS/LDFLAGS in CFLAGS_FOR_TARGET/LDFLAGS_FOR_TARGET: during
# the build of, for example, libatomic, GCC tried to compile multiple variants for runtime
@ -624,7 +635,7 @@ do_gcc_core_backend() {
CXXFLAGS_FOR_BUILD="${cflags_for_build}" \
LDFLAGS="${core_LDFLAGS[*]}" \
CFLAGS_FOR_TARGET="${cflags_for_target}" \
CXXFLAGS_FOR_TARGET="${cflags_for_target}" \
CXXFLAGS_FOR_TARGET="${cxxflags_for_target}" \
LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}" \
${CONFIG_SHELL} \
"${CT_SRC_DIR}/gcc/configure" \
@ -940,6 +951,8 @@ do_gcc_backend() {
local cflags
local cflags_for_build
local cflags_for_target
local cxxflags_for_target
local extra_cxxflags_for_target
local ldflags
local build_manuals
local exec_prefix
@ -1225,6 +1238,16 @@ do_gcc_backend() {
# Assume '-O2' by default for building target libraries.
cflags_for_target="-g -O2 ${cflags_for_target}"
# Set target CXXFLAGS to CFLAGS if none is provided.
if [ -z "${cxxflags_for_target}" ]; then
cxxflags_for_target="${cflags_for_target}"
fi
# Append extra CXXFLAGS if provided.
if [ -n "${extra_cxxflags_for_target}" ]; then
cxxflags_for_target="${cxxflags_for_target} ${extra_cxxflags_for_target}"
fi
# NB: not using CT_ALL_TARGET_CFLAGS/CT_ALL_TARGET_LDFLAGS here!
# See do_gcc_core_backend for explanation.
CT_DoExecLog CFG \
@ -1235,7 +1258,7 @@ do_gcc_backend() {
CXXFLAGS_FOR_BUILD="${cflags_for_build}" \
LDFLAGS="${final_LDFLAGS[*]}" \
CFLAGS_FOR_TARGET="${cflags_for_target}" \
CXXFLAGS_FOR_TARGET="${cflags_for_target}" \
CXXFLAGS_FOR_TARGET="${cxxflags_for_target}" \
LDFLAGS_FOR_TARGET="${CT_TARGET_LDFLAGS}" \
${CONFIG_SHELL} \
"${CT_SRC_DIR}/gcc/configure" \