From 27fed7e5f01495ce25dd605bb031954ed186f614 Mon Sep 17 00:00:00 2001 From: Ray Donnelly Date: Sat, 12 Apr 2014 13:18:15 +0100 Subject: crosstool-NG.sh.in: Don't make lots of symlinks to lib folder For 4 different folders: ${CT_PREFIX_DIR} ${CT_SYSROOT_DIR} ${CT_SYSROOT_DIR}/usr ${CT_PREFIX_DIR}/${CT_TARGET} .. symlinks from 'lib32' and 'lib64' to 'lib' were created. This was untidy and incorrect for multilib (the bitness of the libraries in 'lib32' and 'lib64' will not be the same) We can not know which folders this toolchain configuration will require at this time so let them be created on-demand instead. Changed by Alexey Neyman: original change removed too much; we still need to create the default directories because the os directories are based off them (e.g. `lib/../lib64'). Signed-off-by: Ray Donnelly Signed-off-by: Alexey Neyman --- scripts/build/cc/100-gcc.sh | 74 ++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 31 deletions(-) (limited to 'scripts/build/cc') diff --git a/scripts/build/cc/100-gcc.sh b/scripts/build/cc/100-gcc.sh index 7bb3610f..57e46f93 100644 --- a/scripts/build/cc/100-gcc.sh +++ b/scripts/build/cc/100-gcc.sh @@ -201,6 +201,9 @@ do_gcc_core_backend() { local -a core_targets_install local -a extra_user_config local arg + local dir + local flags + local osdir for arg in "$@"; do eval "${arg// /\\ }" @@ -560,23 +563,30 @@ do_gcc_core_backend() { CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${prefix}/bin/${CT_TARGET}-cc${ext}" fi - if [ "${CT_MULTILIB}" = "y" ]; then - if [ "${CT_CANADIAN}" = "y" -a "${mode}" = "baremetal" \ - -a "${host}" = "${CT_HOST}" ]; then - CT_DoLog WARN "Canadian Cross unable to confirm multilibs configured correctly" + if [ "${CT_CANADIAN}" = "y" -a "${mode}" = "baremetal" \ + -a "${host}" = "${CT_HOST}" ]; then + CT_DoLog EXTRA "Canadian Cross unable to confirm multilibs configured correctly" + else + multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib ) ) + if [ ${#multilibs[@]} -ne 0 ]; then + CT_DoLog EXTRA "gcc configured with these multilibs (including the default):" + for i in "${multilibs[@]}"; do + dir="${i%%;*}" + flags="${i#*;}" + flags=${flags//@/ -} + osdir=$( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-os-directory ${flags} ) + CT_DoLog EXTRA " '${flags}' --> lib/${dir}/ (gcc) lib/${osdir} (os)" + # When building core GCC, create the necessary directories for libc & friends. + case "${build_step}" in + core1|core2) + CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/lib/${osdir}" + CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/lib/${osdir}" + CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib/${osdir}" + ;; + esac + done else - multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib \ - |tail -n +2 ) ) - if [ ${#multilibs[@]} -ne 0 ]; then - CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):" - for i in "${multilibs[@]}"; do - dir="${i%%;*}" - flags="${i#*;}" - CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/" - done - else - CT_DoLog WARN "gcc configured for multilib, but none available" - fi + CT_DoLog WARN "no multilib configuration: GCC unusable?" fi fi } @@ -685,6 +695,9 @@ do_gcc_backend() { local -a final_LDFLAGS local tmp local arg + local dir + local flags + local osdir for arg in "$@"; do eval "${arg// /\\ }" @@ -968,22 +981,21 @@ do_gcc_backend() { CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-cc${ext}" fi - if [ "${CT_MULTILIB}" = "y" ]; then - if [ "${CT_CANADIAN}" = "y" ]; then - CT_DoLog WARN "Canadian Cross unable to confirm multilibs configured correctly" + if [ "${CT_CANADIAN}" = "y" ]; then + CT_DoLog EXTRA "Canadian Cross unable to confirm multilibs configured correctly" + else + multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib ) ) + if [ ${#multilibs[@]} -ne 0 ]; then + CT_DoLog EXTRA "gcc configured with these multilibs (including the default):" + for i in "${multilibs[@]}"; do + dir="${i%%;*}" + flags="${i#*;}" + flags=${flags//@/ -} + osdir=$( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-os-directory $flags ) + CT_DoLog EXTRA " '${flags}' --> lib/${dir}/ (gcc) lib/${osdir} (os)" + done else - multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib \ - |tail -n +2 ) ) - if [ ${#multilibs[@]} -ne 0 ]; then - CT_DoLog EXTRA "gcc configured with these multilibs (besides the default):" - for i in "${multilibs[@]}"; do - dir="${i%%;*}" - flags="${i#*;}" - CT_DoLog EXTRA " ${flags//@/ -} --> ${dir}/" - done - else - CT_DoLog WARN "gcc configured for multilib, but none available" - fi + CT_DoLog WARN "no multilib configuration: GCC unusable?" fi fi } -- cgit v1.2.3 From 82072d0cbc238000fd1547551deb198aa8c8d466 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Wed, 30 Mar 2016 12:15:54 -0700 Subject: multilib: Determine which options may pass through. On some arches (e.g. MIPS) the options like -mabi do not work if specified more than once (see the comment in 100-gcc.sh). Therefore, we need to determine which of the options produced by .sh can be passed to multilib builds and which must be removed (i.e., which options vary among the multilibs). This presents a chicken-and-egg problem. GCC developers, in their infinite wisdom, do not allow arbitrary multilib specification to be supplied to GCC's configure. Instead, the target (and sometimes some extra options) determine the set of multilibs - which may include different CPUs, different ABIs, different endianness, different FPUs, different floating-point ABIs, ... That is, we don't know which parts vary until we build GCC and ask it. So, the solution implemented here is: - For multilib builds, start with empty CT_ARCH_TARGET_CFLAGS/LDFLAGS. - For multilib builds, require core pass 1. Pass 1 does not build any target binaries, so at that point, our target options have not been used yet. - Provide an API to modify the environment variables for the steps that follow the current one. - As a part of multilib-related housekeeping, determine the variable part of multilibs and filter out these options; pass the rest into CT_TARGET_CFLAGS/LDFLAGS. This still does not handle extra dependencies between GCC options (like -ma implying -mcpu=X -mtune=Y, etc.) but I feel that would complicate matters too much. Let's leave this until there's a compelling case for it. Also, query GCC's sysroot suffix for targets that use it (SuperH, for example) - the default multilib may not work if the command line specifies the default option explicitly (%sysroot_suffix_spec is not aware of multilib defaults). Signed-off-by: Alexey Neyman --- config/target.in | 4 + scripts/build/cc/100-gcc.sh | 218 +++++++++++++++++++++++++++++++++----------- scripts/build/libc/glibc.sh | 22 ++++- scripts/crosstool-NG.sh.in | 10 +- scripts/functions | 25 +++++ 5 files changed, 224 insertions(+), 55 deletions(-) (limited to 'scripts/build/cc') diff --git a/config/target.in b/config/target.in index 8cbaabc0..e8f0fe7d 100644 --- a/config/target.in +++ b/config/target.in @@ -65,9 +65,13 @@ config ARCH_REQUIRES_MULTILIB bool select MULTILIB +# Multilib requires 1st core pass (i.e., pass without building libgcc) +# to determine which target cflags vary with multilib and which must be +# passed from the arch configuration. config MULTILIB bool prompt "Build a multilib toolchain (READ HELP!!!)" + select CC_CORE_PASS_1_NEEDED help If you say 'y' here, then the toolchain will also contain the C library optimised for some variants of the selected architecture, besides the diff --git a/scripts/build/cc/100-gcc.sh b/scripts/build/cc/100-gcc.sh index 57e46f93..72e9dd0a 100644 --- a/scripts/build/cc/100-gcc.sh +++ b/scripts/build/cc/100-gcc.sh @@ -84,6 +84,167 @@ cc_gcc_lang_list() { printf "%s" "${lang_list}" } +#------------------------------------------------------------------------------ +# Return a value of a requested GCC spec +cc_gcc_get_spec() { + local spec=$1 + local cc_and_cflags=$2 + + # GCC does not provide a facility to request a value of a spec string. + # The only way to do that I found was to augment the spec file with + # some dummy suffix handler that does nothing except printing it. + touch temp-input.spec_eval + { + echo ".spec_eval:" + echo "echo %(${spec})" + } > "tmp-specs-${spec}" + ${cc_and_cflags} -specs="tmp-specs-${spec}" -E temp-input.spec_eval +} + +#------------------------------------------------------------------------------ +# Report the type of a GCC option +cc_gcc_classify_opt() { + # Options present in multiple architectures + case "${1}" in + -march=*) echo "arch"; return;; + -mabi=*) echo "abi"; return;; + -mcpu=*|-mmcu=*) echo "cpu"; return;; + -mtune=*) echo "tune"; return;; + -mfpu=*) echo "fpu"; return;; + -mhard-float|-msoft-float|-mno-soft-float|-mno-float|-mfloat-abi=*|\ + -mfpu|-mno-fpu) echo "float"; return;; + -EB|-EL|-mbig-endian|-mlittle-endian|-mbig|-mlittle|-meb|-mel|-mb|-ml) echo "endian"; return;; + -mthumb|-marm) echo "mode"; return;; + esac + + # Arch-specific options and aliases + case "${CT_ARCH}" in + m68k) + case "${1}" in + -m68881) echo "float"; return;; + -m5[234]*|-mcfv4e) echo "cpu"; return;; + -m68*|-mc68*) echo "arch"; return;; + esac + ;; + mips) + case "${1}" in + -mips[1234]|-mips32|-mips32r*|-mips64|-mips64r*) echo "cpu"; return;; + esac + ;; + sh) + case "${1}" in + -m[12345]*) echo "cpu"; return;; + esac + esac + + # All tried and failed + echo "unknown" +} + +#------------------------------------------------------------------------------ +# This function lists the multilibs configured in the compiler (even if multilib +# is disabled - so that it lists the default GCC/OS directory, which may differ +# from the default 'lib'). It then performs a few multilib checks/quirks: +# +# 1. On SuperH target, configuring with default CPU (e.g. by supplying the target +# name as 'sh4', which is what CT-NG does) results in the compiler being unable to +# run if that same switch is passed to the resulting gcc (e.g. 'gcc -m4'). The reason +# for this behavior is that the script that determines the sysroot suffix is not +# aware of the default multilib selection, so it generates /m4 as the +# suffixed sysroot. But the main driver, knowing that -m4 is the default, does not +# even attempt to fall back to the non-suffixed sysroot (as it does with non-default +# multilibs) - as a result, gcc fails to find any library if invoked with -m4. +# The right solution would be to drop the default CPU from the multilib list +# completely, or make the print-sysroot-suffix.sh script aware of the defaults +# (which is not easy, as the defaults are not in tmake_file, but rather in tm_file...) +# +# 2. On MIPS target, gcc (or rather, ld, which it invokes under the hood) chokes +# if supplied with two -mabi=* options. I.e., 'gcc -mabi=n32' and 'gcc -mabi=32' both +# work, but 'gcc -mabi=32 -mabi=n32' produces an internal error in ld. Thus we do +# not supply target's CFLAGS in multilib builds - and after compiling pass-1 gcc, +# attempt to determine which CFLAGS need to be filtered out. +cc_gcc_multilib_housekeeping() { + local cc host + local flags osdir dir multilibs i f + local multilib_defaults + local suffix sysroot base lnk + local ml_arch ml_abi ml_cpu ml_tune ml_fpu ml_float ml_endian ml_mode ml_unknown ml + local new_cflags + + for arg in "$@"; do + eval "${arg// /\\ }" + done + + if [ \( "${CT_CANADIAN}" = "y" -o "${CT_CROSS_NATIVE}" = "y" \) -a "${host}" = "${CT_HOST}" ]; then + CT_DoLog EXTRA "Canadian Cross/Cross-native unable to confirm multilibs configuration "\ + "directly; will use build-compiler for housekeeping." + # Since we cannot run the desired compiler, substitute build-CC with the assumption + # that the host-CC is configured in the same way. + cc="${CT_BUILDTOOLS_PREFIX_DIR}/bin/${CT_TARGET}-gcc" + fi + + # sed: prepend dashes or do nothing if default is empty string + multilib_defaults=( $( cc_gcc_get_spec multilib_defaults "${cc}" | \ + ${sed} 's/\(^\|[[:space:]]\+\)\([^[:space:]]\)/ -\2/g' ) ) + CT_DoLog EXTRA "gcc default flags: '${multilib_defaults}'" + + multilibs=( $( "${cc}" -print-multi-lib ) ) + if [ ${#multilibs[@]} -ne 0 ]; then + CT_DoLog EXTRA "gcc configured with these multilibs (including the default):" + for i in "${multilibs[@]}"; do + dir="${i%%;*}" + flags="${i#*;}" + flags=${flags//@/ -} + osdir=$( "${cc}" -print-multi-os-directory ${flags} ) + CT_DoLog EXTRA " '${flags}' --> lib/${dir}/ (gcc) lib/${osdir} (os)" + for f in ${flags}; do + eval ml_`cc_gcc_classify_opt ${f}`=seen + done + done + else + CT_DoLog WARN "no multilib configuration: GCC unusable?" + fi + + # Filtering out some of the options provided in CT-NG config. Then *prepend* + # them to CT_TARGET_CFLAGS, like scripts/crosstool-NG.sh does. Zero out + # the stashed MULTILIB flags so that we don't process them again in the passes + # that follow. + CT_DoLog DEBUG "Configured target CFLAGS: '${CT_ARCH_TARGET_CFLAGS_MULTILIB}'" + ml_unknown= # Pass through anything we don't know about + for f in ${CT_ARCH_TARGET_CFLAGS_MULTILIB}; do + eval ml=\$ml_`cc_gcc_classify_opt ${f}` + if [ "${ml}" != "seen" ]; then + new_cflags="${new_cflags} ${f}" + fi + done + CT_DoLog DEBUG "Filtered target CFLAGS: '${new_cflags}'" + CT_EnvModify CT_TARGET_CFLAGS "${new_cflags} ${CT_TARGET_CFLAGS}" + CT_EnvModify CT_ARCH_TARGET_CFLAGS_MULTILIB "" + + # Currently, the only LDFLAGS are endianness-related + CT_DoLog DEBUG "Configured target LDFLAGS: '${CT_ARCH_TARGET_LDFLAGS_MULTILIB}'" + if [ "${ml_endian}" != "seen" ]; then + CT_EnvModify CT_TARGET_LDFLAGS "${CT_ARCH_TARGET_LDFLAGS_MULTILIB} ${CT_TARGET_LDFLAGS}" + CT_EnvModify CT_ARCH_TARGET_LDFLAGS_MULTILIB "" + fi + CT_DoLog DEBUG "Filtered target LDFLAGS: '${CT_ARCH_TARGET_LDFLAGS_MULTILIB}'" + + # Sysroot suffix fixup for the multilib default. + suffix=$( cc_gcc_get_spec sysroot_suffix_spec "${cc} ${multilib_defaults}" ) + if [ -n "${suffix}" ]; then + base=${suffix%/*} + sysroot=$( "${cc}" -print-sysroot ) + if [ -n "${base}" ]; then + CT_DoExecLog ALL mkdir -p "${sysroot}${base}" + lnk=$( echo "${base#/}" | ${sed} -e 's,[^/]*,..,g' ) + else + lnk=. + fi + CT_DoExecLog ALL rm -f "${sysroot}${suffix}" + CT_DoExecLog ALL ln -sfv "${lnk}" "${sysroot}${suffix}" + fi +} + #------------------------------------------------------------------------------ # Core gcc pass 1 do_gcc_core_pass_1() { @@ -201,9 +362,6 @@ do_gcc_core_backend() { local -a core_targets_install local -a extra_user_config local arg - local dir - local flags - local osdir for arg in "$@"; do eval "${arg// /\\ }" @@ -542,7 +700,7 @@ do_gcc_core_backend() { # tree makes the libtoolized utilities that are built next assume # that, for example, libsupc++ is an "accessory library", and not include # -lsupc++ to the link flags. That breaks ltrace, for example. - CT_DoLog EXTRA "Housekeeping for final gcc compiler" + CT_DoLog EXTRA "Housekeeping for core gcc compiler" CT_Pushd "${prefix}" find . -type f -name "*.la" -exec rm {} \; |CT_DoLog ALL CT_Popd @@ -563,32 +721,8 @@ do_gcc_core_backend() { CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${prefix}/bin/${CT_TARGET}-cc${ext}" fi - if [ "${CT_CANADIAN}" = "y" -a "${mode}" = "baremetal" \ - -a "${host}" = "${CT_HOST}" ]; then - CT_DoLog EXTRA "Canadian Cross unable to confirm multilibs configured correctly" - else - multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib ) ) - if [ ${#multilibs[@]} -ne 0 ]; then - CT_DoLog EXTRA "gcc configured with these multilibs (including the default):" - for i in "${multilibs[@]}"; do - dir="${i%%;*}" - flags="${i#*;}" - flags=${flags//@/ -} - osdir=$( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-os-directory ${flags} ) - CT_DoLog EXTRA " '${flags}' --> lib/${dir}/ (gcc) lib/${osdir} (os)" - # When building core GCC, create the necessary directories for libc & friends. - case "${build_step}" in - core1|core2) - CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/lib/${osdir}" - CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/lib/${osdir}" - CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib/${osdir}" - ;; - esac - done - else - CT_DoLog WARN "no multilib configuration: GCC unusable?" - fi - fi + cc_gcc_multilib_housekeeping cc="${prefix}/bin/${CT_TARGET}-gcc" \ + host="${host}" } #------------------------------------------------------------------------------ @@ -695,9 +829,6 @@ do_gcc_backend() { local -a final_LDFLAGS local tmp local arg - local dir - local flags - local osdir for arg in "$@"; do eval "${arg// /\\ }" @@ -978,24 +1109,9 @@ do_gcc_backend() { file="$( ls -1 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc."* 2>/dev/null || true )" [ -z "${file}" ] || ext=".${file##*.}" if [ -f "${CT_PREFIX_DIR}/bin/${CT_TARGET}-gcc${ext}" ]; then - CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-cc${ext}" + CT_DoExecLog ALL ln -sfv "${CT_TARGET}-gcc${ext}" "${prefix}/bin/${CT_TARGET}-cc${ext}" fi - if [ "${CT_CANADIAN}" = "y" ]; then - CT_DoLog EXTRA "Canadian Cross unable to confirm multilibs configured correctly" - else - multilibs=( $( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-lib ) ) - if [ ${#multilibs[@]} -ne 0 ]; then - CT_DoLog EXTRA "gcc configured with these multilibs (including the default):" - for i in "${multilibs[@]}"; do - dir="${i%%;*}" - flags="${i#*;}" - flags=${flags//@/ -} - osdir=$( "${prefix}/bin/${CT_TARGET}-gcc" -print-multi-os-directory $flags ) - CT_DoLog EXTRA " '${flags}' --> lib/${dir}/ (gcc) lib/${osdir} (os)" - done - else - CT_DoLog WARN "no multilib configuration: GCC unusable?" - fi - fi + cc_gcc_multilib_housekeeping cc="${prefix}/bin/${CT_TARGET}-gcc" \ + host="${host}" } diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index cff6d95e..c419603a 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -111,13 +111,29 @@ do_libc_backend() { # (default target, not multilib) multi_last=y fi + + # GCC makes the distinction between: + # multilib (-print-multi-lib or -print-multi-directory) and + # multilib-os (--print-multi-os-directory) + # as the gcc library and gcc sysroot library paths, respectively. + # For example, on x86_64: + # multilib: -m32=32 -m64=. + # multilib-os: -m32=../lib -m64=../lib64 + # Moreover, while some multilibs can coexist in the same sysroot (e.g. + # on x86), some have a "sysroot suffix" to separate incompatible variants. + # Such sysroot suffixes combine with multilib-os directories, e.g. + # on sh4 with -m4a multilib, the search order in sysroot is (dropping some + # directories for brevity: + # /m4a/lib/m4a/ + # /m4a/usr/lib/m4a/ + # /m4a/lib/ + # /m4a/usr/lib/ + multi_flags=$( echo "${multilib#*;}" | ${sed} -r -e 's/@/ -/g;' ) multi_dir="${multilib%%;*}" if [ "${multi_dir}" != "." ]; then CT_DoStep INFO "Building for multilib subdir='${multi_dir}'" - extra_flags="$( echo "${multilib#*;}" \ - |${sed} -r -e 's/@/ -/g;' \ - )" + extra_flags="${multi_flags}" extra_dir="/${multi_dir}" # glibc install its files in ${extra_dir}/{usr/,}lib diff --git a/scripts/crosstool-NG.sh.in b/scripts/crosstool-NG.sh.in index 6ae9d5d8..9a4091ab 100644 --- a/scripts/crosstool-NG.sh.in +++ b/scripts/crosstool-NG.sh.in @@ -292,7 +292,7 @@ if [ -z "${CT_RESTART}" ]; then */*) CT_Abort "Sysroot name contains forbidden slash(es): '${CT_SYSROOT_NAME}'";; esac - # Arrange paths depending on wether we use sysroot or not. + # Arrange paths depending on whether we use sysroot or not. if [ "${CT_USE_SYSROOT}" = "y" ]; then CT_SYSROOT_REL_DIR="${CT_SYSROOT_DIR_PREFIX:+${CT_SYSROOT_DIR_PREFIX}/}${CT_SYSROOT_NAME}" CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/${CT_SYSROOT_REL_DIR}" @@ -628,6 +628,14 @@ if [ "${CT_ONLY_DOWNLOAD}" != "y" -a "${CT_ONLY_EXTRACT}" != "y" ]; then # sub-shell ending with !0. bash-3 does not, while bash-4 does, # so the following line is for bash-3; bash-4 would choke above. [ $? -eq 0 ] + # Pick up environment changes. + if [ -r "${CT_BUILD_DIR}/env.modify.sh" ]; then + CT_DoLog DEBUG "Step '${step}' modified the environment:" + CT_DoExecLog DEBUG cat "${CT_BUILD_DIR}/env.modify.sh" + . "${CT_BUILD_DIR}/env.modify.sh" + CT_DoExecLog DEBUG rm -f "${CT_BUILD_DIR}/env.modify.sh" + + fi if [ "${CT_STOP}" = "${step}" ]; then do_stop=1 fi diff --git a/scripts/functions b/scripts/functions index 62d264e3..557c0282 100644 --- a/scripts/functions +++ b/scripts/functions @@ -1183,6 +1183,14 @@ CT_DoConfigSub() { fi } +# Normally, each step is executed in a sub-shell and thus cannot modify the +# environment for the next step(s). When this is needed, it can do so by +# invoking this function. +# Usage: CT_EnvModify VAR VALUE +CT_EnvModify() { + echo "${1}=\"${2}\"" >> "${CT_BUILD_DIR}/env.modify.sh" +} + # Compute the target tuple from what is provided by the user # Usage: CT_DoBuildTargetTuple # In fact this function takes the environment variables to build the target @@ -1303,6 +1311,23 @@ CT_DoBuildTargetTuple() { # Now on for the target LDFLAGS CT_ARCH_TARGET_LDFLAGS="${CT_ARCH_TARGET_LDFLAGS} ${CT_ARCH_ENDIAN_LDFLAG}" + + # Now, a multilib quirk. We may not be able to pass CT_ARCH_TARGET_CFLAGS + # and CT_ARCH_TARGET_LDFLAGS to gcc: even though GCC build appends the multilib + # flags afterwards, on some architectures the build breaks because some + # flags do not completely override each other. For example, on mips target, + # 'gcc -mabi=32' and 'gcc -mabi=n32' both work, but 'gcc -mabi=32 -mabi=n32' + # triggers an internal linker error. Likely a bug in GNU binutils, but we + # have to work it around for now: *do not pass the CT_ARCH_TARGET_ flags*. + # Instead, save them into a different variable here. Then, after the first + # core pass, we'll know which of them vary with multilibs (i.e. must be + # filtered out). + if [ "${CT_MULTILIB}" = "y" ]; then + CT_ARCH_TARGET_CFLAGS_MULTILIB="${CT_ARCH_TARGET_CFLAGS}" + CT_ARCH_TARGET_CFLAGS= + CT_ARCH_TARGET_LDFLAGS_MULTILIB="${CT_ARCH_TARGET_LDFLAGS}" + CT_ARCH_TARGET_LDFLAGS= + fi } # This function determines the target tuple for a given set of compiler -- cgit v1.2.3 From 43c303c946c61469181d633cd5620cb92e44c329 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Mon, 21 Mar 2016 11:18:53 -0700 Subject: libc/*.sh: handle combinations of multilib root/dir. Install startfiles for libc variants into the most specific combination (suffixed sysroot, if applicable + suffixed multi-os dir, if applicable). Install headers once in every suffixed sysroot (although it seems that GCC picks up headers from top-level sysroot, GCC manual claims that sysroot suffix affects headers search path). In uClibc, this requires a better sanitization of the directory: it creates symlinks from {sysroot}/usr/lib/{multi_os_dir} to {sysroot}/lib/{multi_os_dir} and to do so, it counts the number of path components in the libdir. This breaks if one of such components is `..' - symlinks contain an extra `../..' then. Since such sanitization had to be implemented anyway, use it in other places to print more sensible directory names. Also, fix the description of configure --host/--target per musl's configure help message (and its actual code). Signed-off-by: Alexey Neyman --- scripts/build/cc/100-gcc.sh | 8 +- scripts/build/libc/glibc.sh | 190 +++++++++++++++++-------------------------- scripts/build/libc/musl.sh | 42 ++++++---- scripts/build/libc/uClibc.sh | 70 ++++++++++------ scripts/crosstool-NG.sh.in | 4 +- scripts/functions | 54 ++++++++++-- 6 files changed, 197 insertions(+), 171 deletions(-) (limited to 'scripts/build/cc') diff --git a/scripts/build/cc/100-gcc.sh b/scripts/build/cc/100-gcc.sh index 72e9dd0a..db147287 100644 --- a/scripts/build/cc/100-gcc.sh +++ b/scripts/build/cc/100-gcc.sh @@ -192,11 +192,13 @@ cc_gcc_multilib_housekeeping() { if [ ${#multilibs[@]} -ne 0 ]; then CT_DoLog EXTRA "gcc configured with these multilibs (including the default):" for i in "${multilibs[@]}"; do - dir="${i%%;*}" + dir="lib/${i%%;*}" flags="${i#*;}" flags=${flags//@/ -} - osdir=$( "${cc}" -print-multi-os-directory ${flags} ) - CT_DoLog EXTRA " '${flags}' --> lib/${dir}/ (gcc) lib/${osdir} (os)" + flags=$( echo ${flags} ) + osdir="lib/"$( "${cc}" -print-multi-os-directory ${flags} ) + CT_SanitizeVarDir dir osdir + CT_DoLog EXTRA " '${flags}' --> ${dir} (gcc) ${osdir} (os)" for f in ${flags}; do eval ml_`cc_gcc_classify_opt ${f}`=seen done diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index c419603a..c3926bf4 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -70,14 +70,8 @@ do_libc_backend() { local libc_mode local -a multilibs local multilib - local multi_dir - local multi_flags - local multi_last + local multi_dir multi_os_dir multi_flags multi_last local target - local extra_dir - local target - local libc_headers libc_startfiles libc_full - local hdr local arg for arg in "$@"; do @@ -87,17 +81,13 @@ do_libc_backend() { case "${libc_mode}" in startfiles) CT_DoStep INFO "Installing C library headers & start files" - hdr=y - libc_startfiles=y - libc_full= ;; final) CT_DoStep INFO "Installing C library" - hdr= - libc_startfiles= - libc_full=y ;; - *) CT_Abort "Unsupported (or unset) libc_mode='${libc_mode}'";; + *) + CT_Abort "Unsupported (or unset) libc_mode='${libc_mode}'" + ;; esac # If gcc is not configured for multilib, it still prints @@ -130,37 +120,8 @@ do_libc_backend() { # /m4a/usr/lib/ multi_flags=$( echo "${multilib#*;}" | ${sed} -r -e 's/@/ -/g;' ) multi_dir="${multilib%%;*}" - if [ "${multi_dir}" != "." ]; then - CT_DoStep INFO "Building for multilib subdir='${multi_dir}'" - - extra_flags="${multi_flags}" - extra_dir="/${multi_dir}" - - # glibc install its files in ${extra_dir}/{usr/,}lib - # while gcc expects them in {,usr/}lib/${extra_dir}. - # Prepare some symlinks so glibc installs in fact in - # the proper place - # We do it in the start-files step, so it is not needed - # to do it in the final step, as the symlinks will - # already exist - if [ "${libc_mode}" = "startfiles" ]; then - CT_Pushd "${CT_SYSROOT_DIR}" - CT_DoExecLog ALL mkdir -p "lib/${multi_dir}" \ - "usr/lib/${multi_dir}" \ - "${multi_dir}" \ - "${multi_dir}/usr" - CT_DoExecLog ALL ln -sf "../lib/${multi_dir}" "${multi_dir}/lib" - CT_DoExecLog ALL ln -sf "../../usr/lib/${multi_dir}" "${multi_dir}/usr/lib" - CT_Popd - fi - libc_headers= - else - extra_dir= - extra_flags= - libc_headers="${hdr}" - fi - - CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-${libc_mode}${extra_dir//\//_}" + multi_os_dir=$( "${CT_TARGET}-gcc" -print-multi-os-directory ${multi_flags} ) + multi_root=$( "${CT_TARGET}-gcc" -print-sysroot ${multi_flags} ) target=$( CT_DoMultilibTarget "${CT_TARGET}" ${extra_flags} ) case "${target}" in @@ -186,18 +147,21 @@ do_libc_backend() { ;; esac - do_libc_backend_once extra_dir="${extra_dir}" \ - extra_flags="${extra_flags}" \ - libc_headers="${libc_headers}" \ - libc_startfiles="${libc_startfiles}" \ - libc_full="${libc_full}" \ - libc_target="${target}" \ - multi_last="${multi_last}" + CT_DoStep INFO "Building for multilib '${multi_flags}'" + + # Ensure sysroot (with suffix, if applicable) exists + CT_DoExecLog ALL mkdir -p "${multi_root}" + CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-${libc_mode}${multi_dir//\//_}" + do_libc_backend_once multi_dir="${multi_dir}" \ + multi_os_dir="${multi_os_dir}" \ + multi_flags="${multi_flags}" \ + multi_root="${multi_root}" \ + multi_last="${multi_last}" \ + libc_mode="${libc_mode}" \ + libc_target="${target}" CT_Popd - if [ "${multi_dir}" != "." ]; then - CT_EndStep - fi + CT_EndStep done @@ -206,23 +170,17 @@ do_libc_backend() { # This backend builds the C library once # Usage: do_libc_backend_once param=value [...] -# Parameter : Definition : Type : Default -# libc_headers : Build libc headers : bool : n -# libc_startfiles : Build libc start-files : bool : n -# libc_target : Build libc target triplet : string : ${CT_TARGET} -# libc_full : Build full libc : bool : n -# extra_flags : Extra CFLAGS to use (for multilib) : string : (empty) -# extra_dir : Extra subdir for multilib : string : (empty) +# Parameter : Definition : Type +# libc_mode : 'startfiles' or 'final' : string : (empty) +# libc_target : Build libc target triplet : string : (empty) +# multi_root : Installation root, chosen for multilib: string : (empty) +# multi_flags : Extra CFLAGS to use (for multilib) : string : (empty) +# multi_dir : Extra subdir for multilib (gcc) : string : (empty) +# multi_os_dir : Extra subdir for multilib (os) : string : (empty) # multi_last : The last multilib target : bool : n do_libc_backend_once() { - local libc_headers - local libc_startfiles - local libc_full - local extra_flags - local extra_dir - local extraos_dir - local lib_dir - local install_root + local multi_flags multi_dir multi_os_dir multi_root multi_last multi_root + local startfiles_dir local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}" local extra_cc_args local -a extra_config @@ -231,13 +189,32 @@ do_libc_backend_once() { local float_extra local endian_extra local libc_target="${CT_TARGET}" - local multi_last local arg for arg in "$@"; do eval "${arg// /\\ }" done + # Glibc seems to be smart enough to know about the cases that can coexist + # in the same root and installs them into proper multilib-os directory; all + # we need is to point to the right root. We do need to handle multilib-os + # here, though, for the first pass where we install crt*.o and a dummy + # libc.so; we therefore install it to the most specific location of + # //usr/lib/ where it is least likely to clash + # with other multilib variants. We then remove these temporary files at + # the beginning of the libc-final step and allow glibc to install them + # where it thinks is proper. + startfiles_dir="${multi_root}/usr/lib/${multi_os_dir}" + CT_SanitizeVarDir startfiles_dir + + if [ "${libc_mode}" = "final" ]; then + CT_DoLog EXTRA "Cleaning up start files" + CT_DoExecLog ALL rm -f "${startfiles_dir}/crt1.o" \ + "${startfiles_dir}/crti.o" \ + "${startfiles_dir}/crtn.o" \ + "${startfiles_dir}/libc.so" + fi + CT_DoLog EXTRA "Configuring C library" case "${CT_LIBC}" in @@ -253,7 +230,7 @@ do_libc_backend_once() { extra_config+=( --enable-obsolete-rpc ) # Add some default glibc config options if not given by user. - # We don't need to be conditional on wether the user did set different + # We don't need to be conditional on whether the user did set different # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY is passed after # extra_config @@ -275,7 +252,7 @@ do_libc_backend_once() { *) extra_config+=("--disable-shared");; esac - float_extra="$( echo "${extra_flags}" \ + float_extra="$( echo "${multi_flags}" \ |${sed} -r -e '/^(.*[[:space:]])?-m(hard|soft)-float([[:space:]].*)?$/!d;' \ -e 's//\2/;' \ )" @@ -309,11 +286,11 @@ do_libc_backend_once() { # Extract the endianness options if any # This should cover all possible endianness options # in gcc, but it is prone to bit-rot... :-( - endian_extra="$( echo "${extra_flags}" \ + endian_extra="$( echo "${multi_flags}" \ |${sed} -r -e '/^(.*[[:space:]])?-(E[BL]|m((big|little)(-endian)?|e?[bl]))([[:space:]].*)?$/!d;' \ -e 's//\2/;' \ )" - # If extra_flags contained an endianness option, no need to add it again. Otherwise, + # If multi_flags contained an endianness option, no need to add it again. Otherwise, # add the option from the configuration. case "${endian_extra}" in EB|mbig-endian|mbig|meb|mb) @@ -333,8 +310,7 @@ do_libc_backend_once() { # Pre-seed the configparms file with values from the config option printf "%s\n" "${CT_LIBC_GLIBC_CONFIGPARMS}" > configparms - cross_cc=$(CT_Which "${CT_TARGET}-gcc") - extra_cc_args+=" ${extra_flags}" + extra_cc_args+=" ${multi_flags}" case "${CT_LIBC_ENABLE_FORTIFIED_BUILD}" in y) ;; @@ -355,24 +331,6 @@ do_libc_backend_once() { # or even after they get installed... echo "ac_cv_path_BASH_SHELL=/bin/bash" >>config.cache - - # GCC makes the distinction between: - # multilib (-print-multi-lib) and - # multilib-os (--print-multi-os-directory) - # as the gcc library and gcc sysroot library paths, respecitively. - # For example: - # multilib: -m32=32 -m64=. - # multilib-os: -m32=../lib -m64=../lib64 - if "${cross_cc}" -print-multi-os-directory ${extra_cc_args} > /dev/null 2>&1; then - lib_dir=/usr/lib/$("${cross_cc}" -print-multi-os-directory ${extra_cc_args}) - install_root="${CT_SYSROOT_DIR}" - else - # maintain the previous behaviour if -print-multi-os-directory doesn't work. - lib_dir=/usr/lib - install_root="${CT_SYSROOT_DIR}${extra_dir}" - fi - extraos_dir="${install_root}${lib_dir}" - # Configure with --prefix the way we want it on the target... # There are a whole lot of settings here. You'll probably want # to read up on what they all mean, and customize a bit, possibly by setting GLIBC_EXTRA_CONFIG_ARRAY @@ -383,14 +341,12 @@ do_libc_backend_once() { # Run explicitly through CONFIG_SHELL, or the build breaks badly (loop-of-death) # when the shell is not bash... Sigh... :-( - CT_DoLog DEBUG "Using gcc for target : '${cross_cc}'" CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'" CT_DoLog DEBUG "Extra config args passed : '${extra_config[*]}'" CT_DoLog DEBUG "Extra CC args passed : '${glibc_cflags}'" - CT_DoLog DEBUG "Extra flags (multilib) : '${extra_flags}'" - CT_DoLog DEBUG "Multilib os dir : '${extraos_dir}'" + CT_DoLog DEBUG "Extra flags (multilib) : '${multi_flags}'" + CT_DoLog DEBUG "Placing startfiles into : '${startfiles_dir}'" CT_DoLog DEBUG "Configuring with --host : '${libc_target}'" - CT_DoLog DEBUG "Configuring with --libdir: '${lib_dir}'" CT_DoExecLog CFG \ BUILD_CC="${CT_BUILD}-gcc" \ @@ -408,7 +364,6 @@ do_libc_backend_once() { --disable-profile \ --without-gd \ --with-headers="${CT_HEADERS_DIR}" \ - --libdir=${lib_dir} \ "${extra_config[@]}" \ "${CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY[@]}" @@ -439,13 +394,14 @@ do_libc_backend_once() { ;; esac - if [ "${libc_headers}" = "y" ]; then + if [ "${libc_mode}" = "startfiles" -a ! -r "${multi_root}/.libc_headers_installed" ]; then CT_DoLog EXTRA "Installing C library headers" + CT_DoExecLog ALL touch "${multi_root}/.libc_headers_installed" # use the 'install-headers' makefile target to install the # headers CT_DoExecLog ALL ${make} ${JOBSFLAGS} \ - install_root=${install_root} \ + install_root=${multi_root} \ install-bootstrap-headers=yes \ "${extra_make_args[@]}" \ install-headers @@ -486,35 +442,37 @@ do_libc_backend_once() { ;; esac fi - fi # libc_headers == y + elif [ "${libc_mode}" = "final" -a -r "${multi_root}/.libc_headers_installed" ]; then + CT_DoExecLog ALL rm -f "${multi_root}/.libc_headers_installed" + fi # installing headers - if [ "${libc_startfiles}" = "y" ]; then + if [ "${libc_mode}" = "startfiles" ]; then if [ "${CT_THREADS}" = "nptl" ]; then CT_DoLog EXTRA "Installing C library start files" # there are a few object files needed to link shared libraries, # which we build and install by hand - CT_DoExecLog ALL mkdir -p "${extraos_dir}" + CT_DoExecLog ALL mkdir -p "${startfiles_dir}" CT_DoExecLog ALL ${make} ${JOBSFLAGS} \ "${extra_make_args[@]}" \ csu/subdir_lib CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \ - "${extraos_dir}" + "${startfiles_dir}" # Finally, 'libgcc_s.so' requires a 'libc.so' to link against. # However, since we will never actually execute its code, # it doesn't matter what it contains. So, treating '/dev/null' # as a C source file, we produce a dummy 'libc.so' in one step - CT_DoExecLog ALL "${cross_cc}" ${extra_flags} \ - -nostdlib \ - -nostartfiles \ - -shared \ - -x c /dev/null \ - -o "${extraos_dir}/libc.so" + CT_DoExecLog ALL "${CT_TARGET}-gcc" ${multi_flags} \ + -nostdlib \ + -nostartfiles \ + -shared \ + -x c /dev/null \ + -o "${startfiles_dir}/libc.so" fi # threads == nptl - fi # libc_headers == y + fi # libc_mode = startfiles - if [ "${libc_full}" = "y" ]; then + if [ "${libc_mode}" = "final" ]; then CT_DoLog EXTRA "Building C library" CT_DoExecLog ALL ${make} ${JOBSFLAGS} \ "${extra_make_args[@]}" \ @@ -523,7 +481,7 @@ do_libc_backend_once() { CT_DoLog EXTRA "Installing C library" CT_DoExecLog ALL ${make} ${JOBSFLAGS} \ "${extra_make_args[@]}" \ - install_root="${install_root}" \ + install_root="${multi_root}" \ install if [ "${CT_BUILD_MANUALS}" = "y" -a "${multi_last}" = "y" ]; then @@ -543,7 +501,7 @@ do_libc_backend_once() { if [ "${CT_LIBC_LOCALES}" = "y" -a "${multi_last}" = "y" ]; then do_libc_locales fi - fi # libc_full == y + fi # libc_mode = final } # Build up the addons list, separated with $1 diff --git a/scripts/build/libc/musl.sh b/scripts/build/libc/musl.sh index 2699d795..e0e9c63b 100644 --- a/scripts/build/libc/musl.sh +++ b/scripts/build/libc/musl.sh @@ -46,6 +46,7 @@ do_libc_backend() { local -a extra_config local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}" local libc_headers libc_startfiles libc_full + local multi_os_dir multi_root multilib_dir for arg in "$@"; do eval "${arg// /\\ }" @@ -67,6 +68,12 @@ do_libc_backend() { *) CT_Abort "Unsupported (or unset) libc_mode='${libc_mode}'";; esac + multi_root=$( "${CT_TARGET}-gcc" -print-sysroot ) + multi_os_dir=$( "${CT_TARGET}-gcc" -print-multi-os-directory ) + multilib_dir="/usr/lib/${multi_os_dir}" + CT_SanitizeVarDir multilib_dir + CT_DoExecLog ALL mkdir -p "${multi_root}${multilib_dir}" + # From buildroot: # gcc constant folding bug with weak aliases workaround # See http://www.openwall.com/lists/musl/2014/05/15/1 @@ -89,37 +96,44 @@ do_libc_backend() { # NOTE: musl handles the build/host/target a little bit differently # then one would expect: # build : not used - # host : the machine building musl + # host : same as --target # target : the machine musl runs on - CT_DoExecLog CFG \ - CFLAGS="${extra_cflags[@]}" \ - CROSS_COMPILE="${CT_TARGET}-" \ - ${src_dir}/configure \ - --host="${CT_TARGET}" \ - --target="${CT_TARGET}" \ - --prefix="/usr" \ - --disable-gcc-wrapper \ + CT_DoExecLog CFG \ + CFLAGS="${extra_cflags[@]}" \ + CROSS_COMPILE="${CT_TARGET}-" \ + ${src_dir}/configure \ + --host="${CT_TARGET}" \ + --target="${CT_TARGET}" \ + --prefix="/usr" \ + --libdir="${multilib_dir}" \ + --disable-gcc-wrapper \ "${extra_config[@]}" if [ "${libc_headers}" = "y" ]; then CT_DoLog EXTRA "Installing C library headers" - CT_DoExecLog ALL ${make} DESTDIR="${CT_SYSROOT_DIR}" install-headers + CT_DoExecLog ALL ${make} DESTDIR="${multi_root}" install-headers fi if [ "${libc_startfiles}" = "y" ]; then CT_DoLog EXTRA "Building C library start files" - CT_DoExecLog ALL ${make} DESTDIR="${CT_SYSROOT_DIR}" \ + CT_DoExecLog ALL ${make} DESTDIR="${multi_root}" \ obj/crt/crt1.o obj/crt/crti.o obj/crt/crtn.o CT_DoLog EXTRA "Installing C library start files" - CT_DoExecLog ALL cp -av obj/crt/crt*.o "${CT_SYSROOT_DIR}/usr/lib" + CT_DoExecLog ALL cp -av obj/crt/crt*.o "${multi_root}${multilib_dir}" CT_DoExecLog ALL ${CT_TARGET}-gcc -nostdlib \ - -nostartfiles -shared -x c /dev/null -o "${CT_SYSROOT_DIR}/usr/lib/libc.so" + -nostartfiles -shared -x c /dev/null -o "${multi_root}${multilib_dir}/libc.so" fi if [ "${libc_full}" = "y" ]; then + CT_DoLog EXTRA "Cleaning up start files" + CT_DoExecLog ALL rm -f "${multi_root}${multilib_dir}/crt1.o" \ + "${multi_root}${multilib_dir}/crti.o" \ + "${multi_root}${multilib_dir}/crtn.o" \ + "${multi_root}${multilib_dir}/libc.so" + CT_DoLog EXTRA "Building C library" CT_DoExecLog ALL ${make} ${JOBSFLAGS} CT_DoLog EXTRA "Installing C library" - CT_DoExecLog ALL ${make} DESTDIR="${CT_SYSROOT_DIR}" install + CT_DoExecLog ALL ${make} DESTDIR="${multi_root}" install fi CT_EndStep diff --git a/scripts/build/libc/uClibc.sh b/scripts/build/libc/uClibc.sh index 422412c9..7903a762 100644 --- a/scripts/build/libc/uClibc.sh +++ b/scripts/build/libc/uClibc.sh @@ -73,63 +73,62 @@ do_libc_check_config() { # Build and install headers and start files do_libc_start_files() { - local cross + local multi_os_dir multi_root startfiles_dir CT_DoStep INFO "Installing C library headers" # Simply copy files until uClibc has the ability to build out-of-tree CT_DoLog EXTRA "Copying sources to build dir" - CT_DoExecLog ALL cp -av "${CT_SRC_DIR}/${uclibc_name}-${CT_LIBC_VERSION}" \ + CT_DoExecLog ALL cp -a "${CT_SRC_DIR}/${uclibc_name}-${CT_LIBC_VERSION}" \ "${CT_BUILD_DIR}/build-libc-headers" cd "${CT_BUILD_DIR}/build-libc-headers" # Retrieve the config file CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config - # uClibc uses the CROSS environment variable as a prefix to the - # compiler tools to use. Setting it to the empty string forces - # use of the native build host tools, which we need at this - # stage, as we don't have target tools yet. - # BUT! With NPTL, we need a cross-compiler (and we have it) - if [ "${CT_THREADS}" = "nptl" ]; then - cross="${CT_TARGET}-" - fi + multi_os_dir=$( "${CT_TARGET}-gcc" -print-multi-os-directory ) + multi_root=$( "${CT_TARGET}-gcc" -print-sysroot ) + startfiles_dir="${multi_root}/usr/lib/${multi_os_dir}" + CT_SanitizeVarDir startfiles_dir + CT_DoExecLog ALL mkdir -p "${startfiles_dir}" # Force the date of the pregen locale data, as the # newer ones that are referenced are not available CT_DoLog EXTRA "Applying configuration" CT_DoYes "" |CT_DoExecLog ALL \ - ${make} CROSS_COMPILE="${cross}" \ + ${make} CROSS_COMPILE="${CT_TARGET}-" \ UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ + PREFIX="${multi_root}/" \ LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ oldconfig CT_DoLog EXTRA "Building headers" CT_DoExecLog ALL \ ${make} ${CT_LIBC_UCLIBC_VERBOSITY} \ - CROSS_COMPILE="${cross}" \ + CROSS_COMPILE="${CT_TARGET}-" \ UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ + PREFIX="${multi_root}/" \ LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ headers CT_DoLog EXTRA "Installing headers" CT_DoExecLog ALL \ ${make} ${CT_LIBC_UCLIBC_VERBOSITY} \ - CROSS_COMPILE="${cross}" \ + CROSS_COMPILE="${CT_TARGET}-" \ UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ + PREFIX="${multi_root}/" \ LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ install_headers + # The check might look bogus, but it is the same condition as is used + # by GCC build script to enable/disable shared library support. if [ "${CT_THREADS}" = "nptl" ]; then CT_DoLog EXTRA "Building start files" CT_DoExecLog ALL \ ${make} ${CT_LIBC_UCLIBC_PARALLEL:+${JOBSFLAGS}} \ - CROSS_COMPILE="${cross}" \ + CROSS_COMPILE="${CT_TARGET}-" \ UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ + PREFIX="${multi_root}/" \ STRIPTOOL=true \ ${CT_LIBC_UCLIBC_VERBOSITY} \ LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ @@ -139,7 +138,7 @@ do_libc_start_files() { # libm.so is needed for ppc, as libgcc is linked against libm.so # No problem to create it for other archs. CT_DoLog EXTRA "Building dummy shared libs" - CT_DoExecLog ALL "${cross}gcc" -nostdlib \ + CT_DoExecLog ALL "${CT_TARGET}-gcc" -nostdlib \ -nostartfiles \ -shared \ -x c /dev/null \ @@ -147,11 +146,11 @@ do_libc_start_files() { CT_DoLog EXTRA "Installing start files" CT_DoExecLog ALL ${install} -m 0644 lib/crt1.o lib/crti.o lib/crtn.o \ - "${CT_SYSROOT_DIR}/usr/lib" + "${startfiles_dir}" CT_DoLog EXTRA "Installing dummy shared libs" - CT_DoExecLog ALL ${install} -m 0755 libdummy.so "${CT_SYSROOT_DIR}/usr/lib/libc.so" - CT_DoExecLog ALL ${install} -m 0755 libdummy.so "${CT_SYSROOT_DIR}/usr/lib/libm.so" + CT_DoExecLog ALL ${install} -m 0755 libdummy.so "${startfiles_dir}/libc.so" + CT_DoExecLog ALL ${install} -m 0755 libdummy.so "${startfiles_dir}/libm.so" fi # CT_THREADS == nptl CT_EndStep @@ -159,6 +158,8 @@ do_libc_start_files() { # This function build and install the full uClibc do_libc() { + local multi_os_dir multi_root multilib_dir startfiles_dir + CT_DoStep INFO "Installing C library" # Simply copy files until uClibc has the ability to build out-of-tree @@ -170,6 +171,20 @@ do_libc() { # Retrieve the config file CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config + multi_os_dir=$( "${CT_TARGET}-gcc" -print-multi-os-directory ) + multi_root=$( "${CT_TARGET}-gcc" -print-sysroot ) + startfiles_dir="${multi_root}/usr/lib/${multi_os_dir}" + + CT_DoLog EXTRA "Cleaning up startfiles" + CT_DoExecLog ALL rm -f "${startfiles_dir}/crt1.o" \ + "${startfiles_dir}/crti.o" \ + "${startfiles_dir}/crtn.o" \ + "${startfiles_dir}/libc.so" \ + "${startfiles_dir}/libm.so" + + multilib_dir="lib/${multi_os_dir}" + CT_SanitizeVarDir multilib_dir + # uClibc uses the CROSS environment variable as a prefix to the compiler # tools to use. The newly built tools should be in our path, so we need # only give the correct name for them. @@ -181,7 +196,7 @@ do_libc() { CT_DoYes "" |CT_DoExecLog CFG \ ${make} CROSS_COMPILE=${CT_TARGET}- \ UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ + PREFIX="${multi_root}/" \ LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ oldconfig @@ -193,7 +208,7 @@ do_libc() { ${make} -j1 \ CROSS_COMPILE=${CT_TARGET}- \ UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ + PREFIX="${multi_root}/" \ STRIPTOOL=true \ ${CT_LIBC_UCLIBC_VERBOSITY} \ LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ @@ -202,7 +217,7 @@ do_libc() { ${make} ${CT_LIBC_UCLIBC_PARALLEL:+${JOBSFLAGS}} \ CROSS_COMPILE=${CT_TARGET}- \ UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ + PREFIX="${multi_root}/" \ STRIPTOOL=true \ ${CT_LIBC_UCLIBC_VERBOSITY} \ LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ @@ -220,16 +235,17 @@ do_libc() { # We do _not_ want to strip anything for now, in case we specifically # asked for a debug toolchain, hence the STRIPTOOL= assignment # - # Note: JOBSFLAGS is not usefull for installation. + # Note: JOBSFLAGS is not useful for installation. # CT_DoLog EXTRA "Installing C library" CT_DoExecLog ALL \ ${make} CROSS_COMPILE=${CT_TARGET}- \ UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${CT_SYSROOT_DIR}/" \ + PREFIX="${multi_root}/" \ STRIPTOOL=true \ ${CT_LIBC_UCLIBC_VERBOSITY} \ LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ + MULTILIB_DIR="${multilib_dir}" \ install CT_EndStep diff --git a/scripts/crosstool-NG.sh.in b/scripts/crosstool-NG.sh.in index 9a4091ab..b49c68e5 100644 --- a/scripts/crosstool-NG.sh.in +++ b/scripts/crosstool-NG.sh.in @@ -298,7 +298,7 @@ if [ -z "${CT_RESTART}" ]; then CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/${CT_SYSROOT_REL_DIR}" CT_DEBUGROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/${CT_SYSROOT_DIR_PREFIX}/debug-root" CT_HEADERS_DIR="${CT_SYSROOT_DIR}/usr/include" - CT_SanitiseVarDir CT_SYSROOT_REL_DIR CT_SYSROOT_DIR CT_DEBUGROOT_DIR CT_HEADERS_DIR + CT_SanitizeVarDir CT_SYSROOT_REL_DIR CT_SYSROOT_DIR CT_DEBUGROOT_DIR CT_HEADERS_DIR BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}" CC_CORE_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}" CC_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}" @@ -312,7 +312,7 @@ if [ -z "${CT_RESTART}" ]; then CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}" CT_DEBUGROOT_DIR="${CT_SYSROOT_DIR}" CT_HEADERS_DIR="${CT_SYSROOT_DIR}/include" - CT_SanitiseVarDir CT_SYSROOT_DIR CT_DEBUGROOT_DIR CT_HEADERS_DIR + CT_SanitizeVarDir CT_SYSROOT_DIR CT_DEBUGROOT_DIR CT_HEADERS_DIR # hack! Always use --with-sysroot for binutils. # binutils 2.14 and later obey it, older binutils ignore it. # Lets you build a working 32->64 bit cross gcc diff --git a/scripts/functions b/scripts/functions index 557c0282..2331557b 100644 --- a/scripts/functions +++ b/scripts/functions @@ -1,6 +1,6 @@ # -*- mode: sh; tab-width: 4 -*- # vi: ts=4:sw=4:sts=4:et -# This file contains some usefull common functions +# This file contains some useful common functions # Copyright 2007 Yann E. MORIN # Licensed under the GPL v2. See COPYING in the root of this package @@ -308,21 +308,57 @@ CT_SanitizePath() { PATH="${new}" } -# Sanitise the directory name contained in the variable passed as argument: +# Sanitize the directory name contained in the variable passed as argument: # - remove duplicate / -# Usage: CT_SanitiseVarDir CT_PREFIX_DIR -CT_SanitiseVarDir() { +# - remove . (current dir) at the beginning, in the middle or at the end +# - resolve .. (parent dir) if there is a previous component +# - remove .. (parent dir) if at the root +# +# Usage: CT_SanitizeVarDir CT_PREFIX_DIR +CT_SanitizeVarDir() { local var local old_dir - local new_dir + local new_dir tmp for var in "$@"; do eval "old_dir=\"\${${var}}\"" - new_dir="$( printf "${old_dir}" \ - |${sed} -r -e 's:/+:/:g;' \ - )" + new_dir=$( echo "${old_dir}" | ${awk} ' +{ + isabs = $1 == "" # Started with a slash + trail = $NF == "" # Ending with a slash + ncomp = 0 # Components in a path so far + for (i = 1; i <= NF; i++) { + # Double-slash or current dir? Ignore + if ($i == "" || $i == ".") { + continue; + } + # .. pops the last component unless it is at the beginning + if ($i == ".." && ncomp != 0 && comps[ncomp] != "..") { + ncomp--; + continue; + } + comps[++ncomp] = $i; + } + seencomp = 0 + for (i = 1; i <= ncomp; i++) { + if (comps[i] == ".." && isabs) { + # /../ at the beginning is equivalent to / + continue; + } + printf "%s%s", isabs || i != 1 ? "/" : "", comps[i]; + seencomp = 1; + } + if (!seencomp && !isabs && !trail) { + # Eliminated all components, but no trailing slash - + # if the result is appened with /foo, must not become absolute + printf "."; + } + if ((!seencomp && isabs) || (seencomp && trail)) { + printf "/"; + } +}' FS=/ ) eval "${var}=\"${new_dir}\"" - CT_DoLog DEBUG "Sanitised '${var}': '${old_dir}' -> '${new_dir}'" + CT_DoLog DEBUG "Sanitized '${var}': '${old_dir}' -> '${new_dir}'" done } -- cgit v1.2.3