scripts: add BUILD/HOST extra cflags/ldflags

On some hosts, and for certain toolchains (eg. toolchain targetting
the upcoming Darwin), it may be necessary to pass arbitrary CFLAGS
and/or LDFLAGS when building the components.

And necessary infrastructure:
  - EXTRA_{CFLAGS,LDFLAGS}_FOR_{BUILD,HOST} as config options
  - pass those extra flags to components

Fix-up a slight typo in elf2flt at the same time (misnamed cflags).

Signed-off-by: Yann Diorcet <diorcet.yann@gmail.com>
Message-Id: <d24043276c9243a35421.1353077450@macbook-smorlat.local>
Patchwork-Id: 199645
This commit is contained in:
Yann Diorcet 2012-11-16 15:25:57 +01:00
parent 1af4a119d2
commit b43fdf40f1
11 changed files with 114 additions and 15 deletions

View File

@ -41,7 +41,27 @@ config USE_PIPES
Use gcc's option -pipe to use pipes rather than temp files when building
the toolchain.
config EXTRA_FLAGS_FOR_HOST
config EXTRA_CFLAGS_FOR_BUILD
string
prompt "Extra build compiler flags"
default ""
help
Extra flags to pass to the build C and C++ compiler.
May be used to change the default features of the build
compiler such as turning off the stack protector or fortify.
config EXTRA_LDFLAGS_FOR_BUILD
string
prompt "Extra build linker flags"
default ""
help
Extra flags to pass to the build linker.
May be used to change the default features of the build
linker.
config EXTRA_CFLAGS_FOR_HOST
string
prompt "Extra host compiler flags"
default ""
@ -50,6 +70,16 @@ config EXTRA_FLAGS_FOR_HOST
May be used to change the default features of the host
compiler such as turning off the stack protector or fortify.
config EXTRA_LDFLAGS_FOR_HOST
string
prompt "Extra host linker flags"
default ""
help
Extra flags to pass to the host linker.
May be used to change the default features of the host
linker.
choice
bool

View File

@ -39,6 +39,8 @@ do_binutils_for_build() {
binutils_opts+=( "host=${CT_BUILD}" )
binutils_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
binutils_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
binutils_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
do_binutils_backend "${binutils_opts[@]}"
@ -58,6 +60,7 @@ do_binutils_for_host() {
binutils_opts+=( "prefix=${CT_PREFIX_DIR}" )
binutils_opts+=( "static_build=${CT_STATIC_TOOLCHAIN}" )
binutils_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
binutils_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
binutils_opts+=( "build_manuals=${CT_BUILD_MANUALS}" )
do_binutils_backend "${binutils_opts[@]}"
@ -99,13 +102,15 @@ do_binutils_for_host() {
# host : machine to run on : tuple : (none)
# prefix : prefix to install into : dir : (none)
# static_build : build statcially : bool : no
# cflags : host cflags to use : string : (empty)
# cflags : cflags to use : string : (empty)
# ldflags : ldflags to use : string : (empty)
# build_manuals : whether to build manuals : bool : no
do_binutils_backend() {
local host
local prefix
local static_build
local cflags
local ldflags
local build_manuals=no
local -a extra_config
local -a extra_make_flags
@ -158,6 +163,7 @@ do_binutils_backend() {
CT_DoExecLog CFG \
CFLAGS="${cflags}" \
CXXFLAGS="${cflags}" \
LDFLAGS="${ldflags}" \
"${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}/configure" \
--build=${CT_BUILD} \
--host=${host} \

View File

@ -49,6 +49,8 @@ do_elf2flt_for_build() {
elf2flt_opts+=( "host=${CT_BUILD}" )
elf2flt_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
elf2flt_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
elf2flt_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
elf2flt_opts+=( "binutils_bld=${CT_BUILD_DIR}/build-binutils-build-${CT_HOST}" )
do_elf2flt_backend "${elf2flt_opts[@]}"
@ -68,6 +70,7 @@ do_elf2flt_for_host() {
elf2flt_opts+=( "prefix=${CT_PREFIX_DIR}" )
elf2flt_opts+=( "static_build=${CT_STATIC_TOOLCHAIN}" )
elf2flt_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
elf2flt_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
elf2flt_opts+=( "binutils_bld=${CT_BUILD_DIR}/build-binutils-host-${CT_HOST}" )
do_elf2flt_backend "${elf2flt_opts[@]}"
@ -102,12 +105,14 @@ do_elf2flt_for_host() {
# host : machine to run on : tuple : (none)
# prefix : prefix to install into : dir : (none)
# static_build : build statcially : bool : no
# cflags : host cflags to use : string : (empty)
# cflags : cflags to use : string : (empty)
# ldflags : ldflags to use : string : (empty)
do_elf2flt_backend() {
local host
local prefix
local static_build
local cflags
local ldflags
local binutils_bld
local binutils_src
local arg
@ -120,7 +125,8 @@ do_elf2flt_backend() {
CT_DoLog EXTRA "Configuring elf2flt"
CT_DoExecLog CFG \
CFLAGS="${host_cflags}" \
CFLAGS="${cflags}" \
LDFLAGS="${ldflags}" \
"${CT_SRC_DIR}/elf2flt-${CT_ELF2FLT_VERSION}/configure" \
--build=${CT_BUILD} \
--host=${host} \

View File

@ -88,6 +88,7 @@ do_cc_core_pass_1() {
core_opts+=( "complibs=${CT_BUILDTOOLS_PREFIX_DIR}" )
core_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
core_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
core_opts+=( "lang_list=c" )
CT_DoStep INFO "Installing pass-1 core C compiler"
@ -108,6 +109,7 @@ do_cc_core_pass_2() {
core_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
core_opts+=( "complibs=${CT_BUILDTOOLS_PREFIX_DIR}" )
core_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
core_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
core_opts+=( "lang_list=c" )
# Different conditions are at stake here:
@ -155,7 +157,8 @@ do_cc_core_pass_2() {
# build_libstdcxx : build libstdc++ or not : bool : no
# build_staticlinked : build statically linked or not : bool : no
# build_manuals : whether to build manuals or not : bool : no
# cflags : host CFLAGS to use : string : (empty)
# cflags : cflags to use : string : (empty)
# ldflags : ldflags to use : string : (empty)
# Usage: do_cc_core_backend mode=[static|shared|baremetal] build_libgcc=[yes|no] build_staticlinked=[yes|no]
do_cc_core_backend() {
local mode
@ -168,6 +171,7 @@ do_cc_core_backend() {
local complibs
local lang_list
local cflags
local ldflags
local tmp
local -a host_libstdcxx_flags
local -a extra_config
@ -227,6 +231,8 @@ do_cc_core_backend() {
extra_config+=("--disable-__cxa_atexit")
fi
core_LDFLAGS+=("${ldflags}")
# *** WARNING ! ***
# Keep this full if-else-if-elif-fi-fi block in sync
# with the same block in do_cc, below.
@ -521,6 +527,7 @@ do_cc_for_host() {
final_opts+=( "prefix=${CT_PREFIX_DIR}" )
final_opts+=( "complibs=${CT_HOST_COMPLIBS_DIR}" )
final_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
final_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
final_opts+=( "lang_list=$( cc_gcc_lang_list )" )
if [ "${CT_BUILD_MANUALS}" = "y" ]; then
final_opts+=( "build_manuals=yes" )
@ -553,7 +560,8 @@ do_cc_for_host() {
# host : the host we run onto : tuple : (none)
# prefix : the runtime prefix : dir : (none)
# complibs : the companion libraries prefix : dir : (none)
# cflags : the host CFLAGS : string : (empty)
# cflags : cflags to use : string : (empty)
# ldflags : ldflags to use : string : (empty)
# lang_list : the list of languages to build : string : (empty)
# build_manuals : whether to build manuals or not : bool : no
do_cc_backend() {
@ -561,6 +569,7 @@ do_cc_backend() {
local prefix
local complibs
local cflags
local ldflags
local lang_list
local build_manuals
local -a host_libstdcxx_flags
@ -628,6 +637,8 @@ do_cc_backend() {
fi
fi
final_LDFLAGS+=("${ldflags}")
# *** WARNING ! ***
# Keep this full if-else-if-elif-fi-fi block in sync
# with the same block in do_cc_core, above.

View File

@ -37,6 +37,8 @@ do_gmp_for_build() {
gmp_opts+=( "host=${CT_BUILD}" )
gmp_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
gmp_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
gmp_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
do_gmp_backend "${gmp_opts[@]}"
CT_Popd
@ -53,6 +55,7 @@ do_gmp_for_host() {
gmp_opts+=( "host=${CT_HOST}" )
gmp_opts+=( "prefix=${CT_HOST_COMPLIBS_DIR}" )
gmp_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
gmp_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
do_gmp_backend "${gmp_opts[@]}"
CT_Popd
@ -63,11 +66,13 @@ do_gmp_for_host() {
# Parameter : description : type : default
# host : machine to run on : tuple : (none)
# prefix : prefix to install into : dir : (none)
# cflags : host cflags to use : string : (empty)
# cflags : cflags to use : string : (empty)
# ldflags : ldflags to use : string : (empty)
do_gmp_backend() {
local host
local prefix
local cflags
local ldflags
local arg
for arg in "$@"; do
@ -78,6 +83,7 @@ do_gmp_backend() {
CT_DoExecLog CFG \
CFLAGS="${cflags} -fexceptions" \
LDFLAGS="${ldflags}" \
"${CT_SRC_DIR}/gmp-${CT_GMP_VERSION}/configure" \
--build=${CT_BUILD} \
--host=${host} \

View File

@ -80,6 +80,8 @@ do_mpfr_for_build() {
mpfr_opts+=( "host=${CT_BUILD}" )
mpfr_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
mpfr_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
mpfr_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
do_mpfr_backend "${mpfr_opts[@]}"
CT_Popd
@ -96,6 +98,7 @@ do_mpfr_for_host() {
mpfr_opts+=( "host=${CT_HOST}" )
mpfr_opts+=( "prefix=${CT_HOST_COMPLIBS_DIR}" )
mpfr_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
mpfr_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
do_mpfr_backend "${mpfr_opts[@]}"
CT_Popd
@ -106,11 +109,13 @@ do_mpfr_for_host() {
# Parameter : description : type : default
# host : machine to run on : tuple : (none)
# prefix : prefix to install into : dir : (none)
# cflags : host cflags to use : string : (empty)
# cflags : cflags to use : string : (empty)
# ldflags : ldflags to use : string : (empty)
do_mpfr_backend() {
local host
local prefix
local cflags
local ldflags
local arg
for arg in "$@"; do
@ -128,7 +133,8 @@ do_mpfr_backend() {
CT_DoLog EXTRA "Configuring MPFR"
CT_DoExecLog CFG \
CC="${host}-gcc" \
CFLAGS="${CT_CFLAGS_FOR_HOST}" \
CFLAGS="${cflags}" \
LDFLAGS="${ldflags}" \
"${CT_SRC_DIR}/mpfr-${CT_MPFR_VERSION}/configure" \
--build=${CT_BUILD} \
--host=${host} \

View File

@ -40,6 +40,8 @@ do_ppl_for_build() {
ppl_opts+=( "host=${CT_BUILD}" )
ppl_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
ppl_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
ppl_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
do_ppl_backend "${ppl_opts[@]}"
CT_Popd
@ -56,6 +58,7 @@ do_ppl_for_host() {
ppl_opts+=( "host=${CT_HOST}" )
ppl_opts+=( "prefix=${CT_HOST_COMPLIBS_DIR}" )
ppl_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
ppl_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
do_ppl_backend "${ppl_opts[@]}"
CT_Popd
@ -66,11 +69,13 @@ do_ppl_for_host() {
# Parameter : description : type : default
# host : machine to run on : tuple : (none)
# prefix : prefix to install into : dir : (none)
# cflags : host cflags to use : string : (empty)
# cflags : cflags to use : string : (empty)
# ldflags : ldflags to use : string : (empty)
do_ppl_backend() {
local host
local prefix
local cflags
local ldflags
local arg
for arg in "$@"; do
@ -82,6 +87,7 @@ do_ppl_backend() {
CT_DoExecLog CFG \
CFLAGS="${cflags}" \
CXXFLAGS="${cflags}" \
LDFLAGS="${ldflags}" \
"${CT_SRC_DIR}/ppl-${CT_PPL_VERSION}/configure" \
--build=${CT_BUILD} \
--host=${host} \

View File

@ -53,6 +53,8 @@ do_cloog_for_build() {
cloog_opts+=( "host=${CT_BUILD}" )
cloog_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
cloog_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
cloog_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
do_cloog_backend "${cloog_opts[@]}"
CT_Popd
@ -69,6 +71,7 @@ do_cloog_for_host() {
cloog_opts+=( "host=${CT_HOST}" )
cloog_opts+=( "prefix=${CT_HOST_COMPLIBS_DIR}" )
cloog_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
cloog_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
do_cloog_backend "${cloog_opts[@]}"
CT_Popd
@ -79,11 +82,13 @@ do_cloog_for_host() {
# Parameter : description : type : default
# host : machine to run on : tuple : (none)
# prefix : prefix to install into : dir : (none)
# cflags : host cflags to use : string : (empty)
# cflags : cflags to use : string : (empty)
# ldflags : ldflags to use : string : (empty)
do_cloog_backend() {
local host
local prefix
local cflags
local ldflags
local cloog_src_dir="${CT_SRC_DIR}/cloog-ppl-${CT_CLOOG_VERSION}"
local arg
@ -95,6 +100,7 @@ do_cloog_backend() {
CT_DoExecLog CFG \
CFLAGS="${cflags}" \
LDFLAGS="${ldflags}" \
LIBS="-lm" \
"${cloog_src_dir}/configure" \
--build=${CT_BUILD} \

View File

@ -38,6 +38,8 @@ do_mpc_for_build() {
mpc_opts+=( "host=${CT_BUILD}" )
mpc_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
mpc_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
mpc_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
do_mpc_backend "${mpc_opts[@]}"
CT_Popd
@ -54,6 +56,7 @@ do_mpc_for_host() {
mpc_opts+=( "host=${CT_HOST}" )
mpc_opts+=( "prefix=${CT_HOST_COMPLIBS_DIR}" )
mpc_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
mpc_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
do_mpc_backend "${mpc_opts[@]}"
CT_Popd
@ -64,11 +67,13 @@ do_mpc_for_host() {
# Parameter : description : type : default
# host : machine to run on : tuple : (none)
# prefix : prefix to install into : dir : (none)
# cflags : host cflags to use : string : (empty)
# cflags : cflags to use : string : (empty)
# ldflags : ldflags to use : string : (empty)
do_mpc_backend() {
local host
local prefix
local cflags
local ldflags
local arg
for arg in "$@"; do
@ -79,6 +84,7 @@ do_mpc_backend() {
CT_DoExecLog CFG \
CFLAGS="${cflags}" \
LDFLAGS="${ldflags}" \
"${CT_SRC_DIR}/mpc-${CT_MPC_VERSION}/configure" \
--build=${CT_BUILD} \
--host=${host} \

View File

@ -38,6 +38,8 @@ do_libelf_for_build() {
libelf_opts+=( "host=${CT_BUILD}" )
libelf_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
libelf_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
libelf_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
do_libelf_backend "${libelf_opts[@]}"
CT_Popd
@ -54,6 +56,7 @@ do_libelf_for_host() {
libelf_opts+=( "host=${CT_HOST}" )
libelf_opts+=( "prefix=${CT_HOST_COMPLIBS_DIR}" )
libelf_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
libelf_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
do_libelf_backend "${libelf_opts[@]}"
CT_Popd
@ -87,13 +90,15 @@ fi # CT_LIBELF_TARGET
# destdir : out-of-tree install dir : string : /
# host : machine to run on : tuple : (none)
# prefix : prefix to install into : dir : (none)
# cflags : host cflags to use : string : (empty)
# cflags : cflags to use : string : (empty)
# ldflags : ldflags to use : string : (empty)
# shared : also buils shared lib : bool : n
do_libelf_backend() {
local destdir="/"
local host
local prefix
local cflags
local ldflags
local shared
local -a extra_config
local arg
@ -114,6 +119,7 @@ do_libelf_backend() {
CC="${host}-gcc" \
RANLIB="${host}-ranlib" \
CFLAGS="${cflags} -fPIC" \
LDFLAGS="${ldflags}" \
"${CT_SRC_DIR}/libelf-${CT_LIBELF_VERSION}/configure" \
--build=${CT_BUILD} \
--host=${host} \

View File

@ -487,12 +487,22 @@ if [ -z "${CT_RESTART}" ]; then
rm -f "${tmp}"
fi
# Help gcc
# Help build gcc
# Explicitly optimise, else the lines below will overide the
# package's default optimisation flags
CT_CFLAGS_FOR_BUILD="-O2 -g"
CT_CFLAGS_FOR_BUILD+=" ${CT_EXTRA_CFLAGS_FOR_BUILD}"
CT_LDFLAGS_FOR_BUILD=
CT_LDFLAGS_FOR_BUILD+=" ${CT_EXTRA_LDFLAGS_FOR_BUILD}"
# Help host gcc
# Explicitly optimise, else the lines below will overide the
# package's default optimisation flags
CT_CFLAGS_FOR_HOST="-O2 -g"
[ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST+=" -pipe"
CT_CFLAGS_FOR_HOST+=" ${CT_EXTRA_FLAGS_FOR_HOST}"
CT_CFLAGS_FOR_HOST+=" ${CT_EXTRA_CFLAGS_FOR_HOST}"
CT_LDFLAGS_FOR_HOST=
CT_LDFLAGS_FOR_HOST+=" ${CT_EXTRA_LDFLAGS_FOR_HOST}"
# Set the shell to be used by ./configure scripts and by Makefiles (those
# that support it!).