From b43fdf40f1f90c4c313dda5b74955cc725a88b40 Mon Sep 17 00:00:00 2001 From: Yann Diorcet Date: Fri, 16 Nov 2012 15:25:57 +0100 Subject: 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 Message-Id: Patchwork-Id: 199645 diff --git a/config/global/build-behave.in b/config/global/build-behave.in index bb11e91..c98e0fa 100644 --- a/config/global/build-behave.in +++ b/config/global/build-behave.in @@ -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 diff --git a/scripts/build/binutils/binutils.sh b/scripts/build/binutils/binutils.sh index 0aeb393..38bea69 100644 --- a/scripts/build/binutils/binutils.sh +++ b/scripts/build/binutils/binutils.sh @@ -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} \ diff --git a/scripts/build/binutils/elf2flt.sh b/scripts/build/binutils/elf2flt.sh index d9d8e0e..f0dd690 100644 --- a/scripts/build/binutils/elf2flt.sh +++ b/scripts/build/binutils/elf2flt.sh @@ -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} \ diff --git a/scripts/build/cc/gcc.sh b/scripts/build/cc/gcc.sh index 03ffa3a..d7ba606 100644 --- a/scripts/build/cc/gcc.sh +++ b/scripts/build/cc/gcc.sh @@ -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. diff --git a/scripts/build/companion_libs/100-gmp.sh b/scripts/build/companion_libs/100-gmp.sh index ebc095b..8674f16 100644 --- a/scripts/build/companion_libs/100-gmp.sh +++ b/scripts/build/companion_libs/100-gmp.sh @@ -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} \ diff --git a/scripts/build/companion_libs/110-mpfr.sh b/scripts/build/companion_libs/110-mpfr.sh index 35a4849..1a917c2 100644 --- a/scripts/build/companion_libs/110-mpfr.sh +++ b/scripts/build/companion_libs/110-mpfr.sh @@ -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} \ diff --git a/scripts/build/companion_libs/120-ppl.sh b/scripts/build/companion_libs/120-ppl.sh index 90dcad3..93a07ca 100644 --- a/scripts/build/companion_libs/120-ppl.sh +++ b/scripts/build/companion_libs/120-ppl.sh @@ -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} \ diff --git a/scripts/build/companion_libs/130-cloog.sh b/scripts/build/companion_libs/130-cloog.sh index 6408782..06240e5 100644 --- a/scripts/build/companion_libs/130-cloog.sh +++ b/scripts/build/companion_libs/130-cloog.sh @@ -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} \ diff --git a/scripts/build/companion_libs/140-mpc.sh b/scripts/build/companion_libs/140-mpc.sh index b035f4d..9ceb7e5 100644 --- a/scripts/build/companion_libs/140-mpc.sh +++ b/scripts/build/companion_libs/140-mpc.sh @@ -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} \ diff --git a/scripts/build/companion_libs/200-libelf.sh b/scripts/build/companion_libs/200-libelf.sh index e7b140b..e404897 100644 --- a/scripts/build/companion_libs/200-libelf.sh +++ b/scripts/build/companion_libs/200-libelf.sh @@ -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} \ diff --git a/scripts/crosstool-NG.sh.in b/scripts/crosstool-NG.sh.in index 59cd971..782a407 100644 --- a/scripts/crosstool-NG.sh.in +++ b/scripts/crosstool-NG.sh.in @@ -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!). -- cgit v0.10.2-6-g49f6