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 --- scripts/functions | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'scripts/functions') 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/functions') 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 From 3ebc5d0c1e72e95f05a02818a3e2c642663d4b74 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sat, 2 Apr 2016 00:12:41 -0700 Subject: libc/*.sh: Deprecate libc_check_config step. This step was only used in uClibc. However, with upcoming multilib, the config management will have to be done for each variant differently, anyway. uClibc was the only user of libc_check_config step, as well as CT_CONFIG_DIR directory. Retire these. Two other clean-ups in uClibc.sh: - KERNEL_HEADERS check seems to be bogus, this config option is not present even in 0.9.30 - which is not supported already. - SHARED_LIB_LOADER_PREFIX was renamed to MULTILIB_DIR in 0.9.31, according to ChangeLog - and MULTILIB_DIR is passed from command line instead. Signed-off-by: Alexey Neyman --- scripts/build/arch.sh | 24 ++++++++++++++++++++++++ scripts/build/arch/alpha.sh | 11 ----------- scripts/build/arch/arm.sh | 11 ----------- scripts/build/arch/m68k.sh | 15 --------------- scripts/build/arch/microblaze.sh | 11 ----------- scripts/build/arch/mips.sh | 11 ----------- scripts/build/arch/nios2.sh | 1 - scripts/build/arch/powerpc.sh | 1 + scripts/build/arch/sh.sh | 11 ----------- scripts/build/arch/sparc.sh | 34 ++++++++++++++++++++++++++++++++++ scripts/build/arch/x86.sh | 24 ++++++++++++++++++++++++ scripts/build/libc/avr-libc.sh | 4 ---- scripts/build/libc/glibc.sh | 29 ++--------------------------- scripts/build/libc/mingw.sh | 4 ---- scripts/build/libc/musl.sh | 4 ---- scripts/build/libc/newlib.sh | 4 ---- scripts/build/libc/none.sh | 4 ---- scripts/build/libc/uClibc.sh | 32 ++++++++------------------------ scripts/crosstool-NG.sh.in | 4 +--- scripts/functions | 2 -- steps.mk | 4 ++-- 21 files changed, 96 insertions(+), 149 deletions(-) create mode 100644 scripts/build/arch.sh (limited to 'scripts/functions') diff --git a/scripts/build/arch.sh b/scripts/build/arch.sh new file mode 100644 index 00000000..48da2d6d --- /dev/null +++ b/scripts/build/arch.sh @@ -0,0 +1,24 @@ +# This file provides the default implementations of arch-specific functions. + +# Set up the target tuple +CT_DoArchTupleValues() { + :; +} + +# Multilib: change the target triplet according to CFLAGS +CT_DoArchMultilibTarget() { + local multi_flags="${1}" + local target="${2}" + + echo "${target}" +} + +# Multilib: Adjust target tuple for GLIBC +CT_DoArchGlibcAdjustTuple() { + local target="${1}" + + echo "${target}" +} + +# Override from the actual arch implementation as needed. +. "${CT_LIB_DIR}/scripts/build/arch/${CT_ARCH}.sh" diff --git a/scripts/build/arch/alpha.sh b/scripts/build/arch/alpha.sh index ffceae3d..cf6d40d9 100644 --- a/scripts/build/arch/alpha.sh +++ b/scripts/build/arch/alpha.sh @@ -4,14 +4,3 @@ CT_DoArchTupleValues () { # The architecture part of the tuple: CT_TARGET_ARCH="${CT_ARCH}${CT_ARCH_SUFFIX:-${CT_ARCH_ALPHA_VARIANT}}" } - -#------------------------------------------------------------------------------ -# Get multilib architecture-specific target -# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" -CT_DoArchMultilibTarget () -{ - local target="${1}"; shift - local -a multi_flags=( "$@" ) - - echo "${target}" -} diff --git a/scripts/build/arch/arm.sh b/scripts/build/arch/arm.sh index 338392c3..5f6ce2fc 100644 --- a/scripts/build/arch/arm.sh +++ b/scripts/build/arch/arm.sh @@ -39,14 +39,3 @@ CT_DoArchTupleValues() { CT_TARGET_SYS="${CT_TARGET_SYS}hf" fi } - -#------------------------------------------------------------------------------ -# Get multilib architecture-specific target -# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" -CT_DoArchMultilibTarget () -{ - local target="${1}"; shift - local -a multi_flags=( "$@" ) - - echo "${target}" -} diff --git a/scripts/build/arch/m68k.sh b/scripts/build/arch/m68k.sh index a6eb010e..052e4a7c 100644 --- a/scripts/build/arch/m68k.sh +++ b/scripts/build/arch/m68k.sh @@ -1,16 +1 @@ # Compute M68k-specific values - -CT_DoArchTupleValues() { - : -} - -#------------------------------------------------------------------------------ -# Get multilib architecture-specific target -# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" -CT_DoArchMultilibTarget () -{ - local target="${1}"; shift - local -a multi_flags=( "$@" ) - - echo "${target}" -} diff --git a/scripts/build/arch/microblaze.sh b/scripts/build/arch/microblaze.sh index 93ecc9a2..456a6e3a 100644 --- a/scripts/build/arch/microblaze.sh +++ b/scripts/build/arch/microblaze.sh @@ -19,14 +19,3 @@ CT_DoArchTupleValues () { esac } - -#------------------------------------------------------------------------------ -# Get multilib architecture-specific target -# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" -CT_DoArchMultilibTarget () -{ - local target="${1}"; shift - local -a multi_flags=( "$@" ) - - echo "${target}" -} diff --git a/scripts/build/arch/mips.sh b/scripts/build/arch/mips.sh index 68ad4faa..4d732be9 100644 --- a/scripts/build/arch/mips.sh +++ b/scripts/build/arch/mips.sh @@ -14,14 +14,3 @@ CT_DoArchTupleValues() { CT_ARCH_ABI_CFLAG="-mabi=${CT_ARCH_mips_ABI}" CT_ARCH_WITH_ABI="--with-abi=${CT_ARCH_mips_ABI}" } - -#------------------------------------------------------------------------------ -# Get multilib architecture-specific target -# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" -CT_DoArchMultilibTarget () -{ - local target="${1}"; shift - local -a multi_flags=( "$@" ) - - echo "${target}" -} diff --git a/scripts/build/arch/nios2.sh b/scripts/build/arch/nios2.sh index 8c7d4451..24c556bf 100644 --- a/scripts/build/arch/nios2.sh +++ b/scripts/build/arch/nios2.sh @@ -9,5 +9,4 @@ CT_DoArchTupleValues() { CT_ARCH_WITH_FPU= CT_ARCH_WITH_FLOAT= CT_TARGET_SYS=elf - } diff --git a/scripts/build/arch/powerpc.sh b/scripts/build/arch/powerpc.sh index 77bbc8a2..964dd25e 100644 --- a/scripts/build/arch/powerpc.sh +++ b/scripts/build/arch/powerpc.sh @@ -26,6 +26,7 @@ CT_DoArchTupleValues () { CT_ARCH_CC_EXTRA_CONFIG="--enable-e500_double" fi } + #------------------------------------------------------------------------------ # Get multilib architecture-specific target # Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" diff --git a/scripts/build/arch/sh.sh b/scripts/build/arch/sh.sh index e7f4f1a4..7780e40f 100644 --- a/scripts/build/arch/sh.sh +++ b/scripts/build/arch/sh.sh @@ -35,14 +35,3 @@ CT_DoArchTupleValues () { esac CT_ARCH_FLOAT_CFLAG= } - -#------------------------------------------------------------------------------ -# Get multilib architecture-specific target -# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" -CT_DoArchMultilibTarget () -{ - local target="${1}"; shift - local -a multi_flags=( "$@" ) - - echo "${target}" -} diff --git a/scripts/build/arch/sparc.sh b/scripts/build/arch/sparc.sh index 2d3baa35..189cebe2 100644 --- a/scripts/build/arch/sparc.sh +++ b/scripts/build/arch/sparc.sh @@ -25,5 +25,39 @@ CT_DoArchMultilibTarget () local target="${1}"; shift local -a multi_flags=( "$@" ) + local m32=false + local m64=false + + for m in "${multi_flags[@]}"; do + case "$m" in + -m32) m32=true ;; + -m64) m64=true ;; + esac + done + + # Fix up bitness + case "${target}" in + sparc-*) $m64 && target=${target/#sparc-/sparc64-} ;; + sparc64-*) $m32 && target=${target/#sparc64-/sparc-} ;; + esac + + echo "${target}" +} + +# Special tuple adjustment for glibc. +CT_DoArchGlibcAdjustTuple() { + local target="${1}" + + case "${target}" in + # SPARC quirk: glibc 2.23 and newer dropped support for SPARCv8 and + # earlier (corresponding pthread barrier code is missing). Until this + # support is reintroduced, configure as sparcv9. + sparc-*) + if [ "${CT_LIBC_GLIBC_2_23_or_later}" = y ]; then + target=${target/#sparc-/sparcv9-} + fi + ;; + esac + echo "${target}" } diff --git a/scripts/build/arch/x86.sh b/scripts/build/arch/x86.sh index ca0f08bf..0e41d67f 100644 --- a/scripts/build/arch/x86.sh +++ b/scripts/build/arch/x86.sh @@ -68,3 +68,27 @@ CT_DoArchMultilibTarget () echo "${target}" } + +# Adjust target tuple for GLIBC +CT_DoArchGlibcAdjustTuple() { + local target="${1}" + + case "${target}" in + # x86 quirk: architecture name is i386, but glibc expects i[4567]86 - to + # indicate the desired optimization. If it was a multilib variant of x86_64, + # then it targets at least NetBurst a.k.a. i786, but we'll follow the model + # above # and set the optimization to i686. Otherwise, replace with the most + # conservative choice, i486. + i386-*) + if [ "${CT_TARGET_ARCH}" = "x86_64" ]; then + target=${target/#i386-/i686-} + elif [ "${CT_TARGET_ARCH}" != "i386" ]; then + target=${target/#i386-/${CT_TARGET_ARCH}-} + else + target=${target/#i386-/i486-} + fi + ;; + esac + + echo "${target}" +} diff --git a/scripts/build/libc/avr-libc.sh b/scripts/build/libc/avr-libc.sh index b73f990b..3dc91a42 100644 --- a/scripts/build/libc/avr-libc.sh +++ b/scripts/build/libc/avr-libc.sh @@ -18,10 +18,6 @@ do_libc_extract() { CT_Patch "avr-libc" "${CT_LIBC_VERSION}" } -do_libc_check_config() { - : -} - do_libc_configure() { CT_DoLog EXTRA "Configuring C library" diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index dcd9e159..a08ed973 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -41,10 +41,6 @@ do_libc_extract() { CT_Popd } -do_libc_check_config() { - : -} - # Build and install headers and start files do_libc_start_files() { # Start files and Headers should be configured the same way as the @@ -123,30 +119,9 @@ do_libc_backend() { multi_os_dir=$( "${CT_TARGET}-gcc" -print-multi-os-directory ${multi_flags} ) multi_root=$( "${CT_TARGET}-gcc" -print-sysroot ${multi_flags} ) + # Adjust target tuple according to CFLAGS + any GLIBC quirks target=$( CT_DoMultilibTarget "${CT_TARGET}" ${extra_flags} ) - case "${target}" in - # SPARC quirk: glibc 2.23 and newer dropped support for SPARCv8 and - # earlier (corresponding pthread barrier code is missing). Until this - # support is reintroduced, configure as sparcv9. - sparc-*) - if [ "${CT_LIBC_GLIBC_2_23_or_later}" = y ]; then - target=${target/#sparc-/sparcv9-} - fi - ;; - # x86 quirk: architecture name is i386, but glibc expects i[4567]86 - to - # indicate the desired optimization. If it was a multilib variant of x86_64, - # then it targets at least NetBurst a.k.a. i786, but we'll follow arch/x86.sh - # and set the optimization to i686. Otherwise, replace with the most - # conservative choice, i486. - i386-*) - if [ "${CT_TARGET_ARCH}" = "x86_64" ]; then - target=${target/#i386-/i686-} - else - target=${target/#i386-/i486-} - fi - ;; - esac - + target=$( CT_DoArchGlibcAdjustTuple "${target}" ) CT_DoStep INFO "Building for multilib '${multi_flags}'" # Ensure sysroot (with suffix, if applicable) exists diff --git a/scripts/build/libc/mingw.sh b/scripts/build/libc/mingw.sh index 964a11d9..44ca008e 100644 --- a/scripts/build/libc/mingw.sh +++ b/scripts/build/libc/mingw.sh @@ -23,10 +23,6 @@ do_libc_extract() { CT_Popd } -do_libc_check_config() { - : -} - do_set_mingw_install_prefix(){ MINGW_INSTALL_PREFIX=/usr/${CT_TARGET} if [[ ${CT_WINAPI_VERSION} == 2* ]]; then diff --git a/scripts/build/libc/musl.sh b/scripts/build/libc/musl.sh index e0e9c63b..e31d1101 100644 --- a/scripts/build/libc/musl.sh +++ b/scripts/build/libc/musl.sh @@ -16,10 +16,6 @@ do_libc_extract() { CT_Patch "musl" "${CT_LIBC_VERSION}" } -do_libc_check_config() { - : -} - # Build and install headers and start files do_libc_start_files() { # Start files and Headers should be configured the same way as the diff --git a/scripts/build/libc/newlib.sh b/scripts/build/libc/newlib.sh index e70b6690..d9bda06f 100644 --- a/scripts/build/libc/newlib.sh +++ b/scripts/build/libc/newlib.sh @@ -38,10 +38,6 @@ do_libc_extract() { fi } -do_libc_check_config() { - : -} - do_libc_start_files() { CT_DoStep INFO "Installing C library headers & start files" CT_DoExecLog ALL cp -a "${CT_SRC_DIR}/newlib-${CT_LIBC_VERSION}/newlib/libc/include/." \ diff --git a/scripts/build/libc/none.sh b/scripts/build/libc/none.sh index d4bf7dcb..8537a8ea 100644 --- a/scripts/build/libc/none.sh +++ b/scripts/build/libc/none.sh @@ -10,10 +10,6 @@ do_libc_extract() { : } -do_libc_check_config() { - : -} - do_libc_start_files() { : } diff --git a/scripts/build/libc/uClibc.sh b/scripts/build/libc/uClibc.sh index edd82f6a..c59d5fa2 100644 --- a/scripts/build/libc/uClibc.sh +++ b/scripts/build/libc/uClibc.sh @@ -51,26 +51,6 @@ do_libc_extract() { return 0 } -# Check that uClibc has been previously configured -do_libc_check_config() { - CT_DoStep INFO "Checking C library configuration" - - # Use the default config if the user did not provide one. - if [ -z "${CT_LIBC_UCLIBC_CONFIG_FILE}" ]; then - CT_LIBC_UCLIBC_CONFIG_FILE="${CT_LIB_DIR}/contrib/uClibc-defconfigs/${uclibc_name}.config" - fi - - if ${grep} -E '^KERNEL_SOURCE=' "${CT_LIBC_UCLIBC_CONFIG_FILE}" >/dev/null 2>&1; then - CT_DoLog WARN "Your uClibc version refers to the kernel _sources_, which is bad." - CT_DoLog WARN "I can't guarantee that our little hack will work. Please try to upgrade." - fi - - CT_DoLog EXTRA "Manage uClibc configuration" - manage_uClibc_config "${CT_LIBC_UCLIBC_CONFIG_FILE}" "${CT_CONFIG_DIR}/uClibc.config" - - CT_EndStep -} - # Build and install headers and start files do_libc_start_files() { # Start files and Headers should be configured the same way as the @@ -131,12 +111,17 @@ do_libc_backend() { ${CT_LIBC_UCLIBC_VERBOSITY} \ ) - # Retrieve the config file - CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config - # Force the date of the pregen locale data, as the # newer ones that are referenced are not available CT_DoLog EXTRA "Applying configuration" + + # Use the default config if the user did not provide one. + if [ -z "${CT_LIBC_UCLIBC_CONFIG_FILE}" ]; then + CT_LIBC_UCLIBC_CONFIG_FILE="${CT_LIB_DIR}/contrib/uClibc-defconfigs/${uclibc_name}.config" + fi + + manage_uClibc_config "${CT_LIBC_UCLIBC_CONFIG_FILE}" .config + CT_DoYes | CT_DoExecLog ALL ${make} "${make_args[@]}" oldconfig if [ "${libc_mode}" = "startfiles" ]; then @@ -347,7 +332,6 @@ manage_uClibc_config() { # which is the correct value of ${PREFIX}/${TARGET}. CT_KconfigSetOption "DEVEL_PREFIX" "\"/usr/\"" "${dst}" CT_KconfigSetOption "RUNTIME_PREFIX" "\"/\"" "${dst}" - CT_KconfigSetOption "SHARED_LIB_LOADER_PREFIX" "\"/lib/\"" "${dst}" CT_KconfigSetOption "KERNEL_HEADERS" "\"${CT_HEADERS_DIR}\"" "${dst}" # Locales support diff --git a/scripts/crosstool-NG.sh.in b/scripts/crosstool-NG.sh.in index b49c68e5..01fe07cf 100644 --- a/scripts/crosstool-NG.sh.in +++ b/scripts/crosstool-NG.sh.in @@ -141,7 +141,7 @@ CT_DoLog INFO "Building environment variables" # Include sub-scripts instead of calling them: that way, we do not have to # export any variable, nor re-parse the configuration and functions files. . "${CT_LIB_DIR}/scripts/build/internals.sh" -. "${CT_LIB_DIR}/scripts/build/arch/${CT_ARCH}.sh" +. "${CT_LIB_DIR}/scripts/build/arch.sh" . "${CT_LIB_DIR}/scripts/build/companion_tools.sh" . "${CT_LIB_DIR}/scripts/build/kernel/${CT_KERNEL}.sh" . "${CT_LIB_DIR}/scripts/build/companion_libs.sh" @@ -181,7 +181,6 @@ CT_SRC_DIR="${CT_WORK_DIR}/src" CT_BUILD_DIR="${CT_WORK_DIR}/${CT_TARGET}/build" CT_BUILDTOOLS_PREFIX_DIR="${CT_WORK_DIR}/${CT_TARGET}/buildtools" CT_STATE_DIR="${CT_WORK_DIR}/${CT_TARGET}/state" -CT_CONFIG_DIR="${CT_BUILD_DIR}/configs" # Note about HOST_COMPLIBS_DIR: it's always gonna be in the buildtools dir, or a # sub-dir. So we won't have to save/restore it, not even create it. # In case of cross or native, host-complibs are used for build-complibs; @@ -266,7 +265,6 @@ CT_DoExecLog ALL mkdir -p "${CT_TARBALLS_DIR}" CT_DoExecLog ALL mkdir -p "${CT_SRC_DIR}" CT_DoExecLog ALL mkdir -p "${CT_BUILD_DIR}" CT_DoExecLog ALL mkdir -p "${CT_BUILDTOOLS_PREFIX_DIR}/bin" -CT_DoExecLog ALL mkdir -p "${CT_CONFIG_DIR}" CT_DoExecLog ALL mkdir -p "${CT_INSTALL_DIR}" CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}" CT_DoExecLog ALL mkdir -p "${CT_HOST_COMPLIBS_DIR}" diff --git a/scripts/functions b/scripts/functions index 2331557b..49b06869 100644 --- a/scripts/functions +++ b/scripts/functions @@ -1474,7 +1474,6 @@ CT_DoSaveState() { /^(FUNCNAME|GROUPS|PPID|SHELLOPTS)=/d;' >"${state_dir}/env.sh" CT_DoTarballIfExists "${CT_BUILDTOOLS_PREFIX_DIR}" "${state_dir}/buildtools_dir" - CT_DoTarballIfExists "${CT_CONFIG_DIR}" "${state_dir}/config_dir" CT_DoTarballIfExists "${CT_PREFIX_DIR}" "${state_dir}/prefix_dir" --exclude '*.log' CT_DoLog STATE " Saving log file" @@ -1504,7 +1503,6 @@ CT_DoLoadState(){ CT_DoLog INFO "Restoring state at step '${state_name}', as requested." CT_DoExtractTarballIfExists "${state_dir}/prefix_dir" "${CT_PREFIX_DIR}" - CT_DoExtractTarballIfExists "${state_dir}/config_dir" "${CT_CONFIG_DIR}" CT_DoExtractTarballIfExists "${state_dir}/buildtools_dir" "${CT_BUILDTOOLS_PREFIX_DIR}" # Restore the environment, discarding any error message diff --git a/steps.mk b/steps.mk index b7e3b02e..15b9a01b 100644 --- a/steps.mk +++ b/steps.mk @@ -16,9 +16,9 @@ help-env:: # The _for_build steps are noop for native and cross, # but are actual steps for canadian and cross-native. -# Please keep the last line with a '\' and keep the following empy line: +# Please keep the last line with a '\' and keep the following empty line: # it helps when diffing and merging. -CT_STEPS := libc_check_config \ +CT_STEPS := \ companion_libs_for_build \ binutils_for_build \ companion_libs_for_host \ -- cgit v1.2.3 From 0fdc1887a7426bf7974f0ca6bb24815dff4a2997 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sun, 3 Apr 2016 10:26:24 -0700 Subject: Change multilib functions to set the variable. Rather than echo-ing the new value, set the value into the variable with the name passed as an argument (similar to CT_SanitizeVarDir). This allows to use CT_DoLog in these functions. Signed-off-by: Alexey Neyman --- scripts/build/arch.sh | 11 ++++------- scripts/build/arch/powerpc.sh | 31 +++++++++++++++++-------------- scripts/build/arch/s390.sh | 16 ++++++++++------ scripts/build/arch/sparc.sh | 29 +++++++++++++++++++---------- scripts/build/arch/x86.sh | 38 +++++++++++++++++++++++--------------- scripts/build/libc/glibc.sh | 5 +++-- scripts/functions | 6 +++--- 7 files changed, 79 insertions(+), 57 deletions(-) (limited to 'scripts/functions') diff --git a/scripts/build/arch.sh b/scripts/build/arch.sh index 48da2d6d..2199a17f 100644 --- a/scripts/build/arch.sh +++ b/scripts/build/arch.sh @@ -6,18 +6,15 @@ CT_DoArchTupleValues() { } # Multilib: change the target triplet according to CFLAGS +# Usage: CT_DoArchGlibcAdjustTuple CT_DoArchMultilibTarget() { - local multi_flags="${1}" - local target="${2}" - - echo "${target}" + :; } # Multilib: Adjust target tuple for GLIBC +# Usage: CT_DoArchGlibcAdjustTuple CT_DoArchGlibcAdjustTuple() { - local target="${1}" - - echo "${target}" + :; } # Override from the actual arch implementation as needed. diff --git a/scripts/build/arch/powerpc.sh b/scripts/build/arch/powerpc.sh index 964dd25e..80157241 100644 --- a/scripts/build/arch/powerpc.sh +++ b/scripts/build/arch/powerpc.sh @@ -29,11 +29,12 @@ CT_DoArchTupleValues () { #------------------------------------------------------------------------------ # Get multilib architecture-specific target -# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +# Usage: CT_DoArchMultilibTarget "target variable" "multilib flags" CT_DoArchMultilibTarget () { - local target="${1}"; shift + local target_var="${1}"; shift local -a multi_flags=( "$@" ) + local target_ local m32=false local m64=false @@ -49,22 +50,24 @@ CT_DoArchMultilibTarget () esac done + eval target_=\"\${${target_var}}\" + # Fix up bitness - case "${target}" in - powerpc-*) $m64 && target=${target/#powerpc-/powerpc64-} ;; - powerpcle-*) $m64 && target=${target/#powerpcle-/powerpc64le-} ;; - powerpc64-*) $m32 && target=${target/#powerpc64-/powerpc-} ;; - powerpc64le-*) $m32 && target=${target/#powerpc64le-/powerpcle-} ;; + case "${target_}" in + powerpc-*) $m64 && target_=${target_/#powerpc-/powerpc64-} ;; + powerpcle-*) $m64 && target_=${target_/#powerpcle-/powerpc64le-} ;; + powerpc64-*) $m32 && target_=${target_/#powerpc64-/powerpc-} ;; + powerpc64le-*) $m32 && target_=${target_/#powerpc64le-/powerpcle-} ;; esac # Fix up endianness - case "${target}" in - powerpc-*) $mlittle && target=${target/#powerpc-/powerpcle-} ;; - powerpcle-*) $mbig && target=${target/#powerpcle-/powerpc-} ;; - powerpc64-*) $mlittle && target=${target/#powerpc64-/powerpc64le-} ;; - powerpc64le-*) $mbig && target=${target/#powerpc64le-/powerpc64-} ;; + case "${target_}" in + powerpc-*) $mlittle && target_=${target_/#powerpc-/powerpcle-} ;; + powerpcle-*) $mbig && target_=${target_/#powerpcle-/powerpc-} ;; + powerpc64-*) $mlittle && target_=${target_/#powerpc64-/powerpc64le-} ;; + powerpc64le-*) $mbig && target_=${target_/#powerpc64le-/powerpc64-} ;; esac - # return the target - echo "${target}" + # Set the target variable + eval ${target_var}=\"${target_}\" } diff --git a/scripts/build/arch/s390.sh b/scripts/build/arch/s390.sh index e303420a..dff86a0c 100644 --- a/scripts/build/arch/s390.sh +++ b/scripts/build/arch/s390.sh @@ -9,11 +9,12 @@ CT_DoArchTupleValues() { #------------------------------------------------------------------------------ # Get multilib architecture-specific target -# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +# Usage: CT_DoArchMultilibTarget "target variable" "multilib flags" CT_DoArchMultilibTarget () { - local target="${1}"; shift + local target_var="${1}"; shift local -a multi_flags=( "$@" ) + local target_ local m31=false local m64=false @@ -25,11 +26,14 @@ CT_DoArchMultilibTarget () esac done + eval target_=\"\${${target_var}}\" + # Fix bitness - case "${target}" in - s390-*) $m64 && target=${target/#s390-/s390x-} ;; - s390x-*) $m31 && target=${target/#s390x-/s390-} ;; + case "${target_}" in + s390-*) $m64 && target_=${target_/#s390-/s390x-} ;; + s390x-*) $m31 && target_=${target_/#s390x-/s390-} ;; esac - echo "${target}" + # Set the target variable + eval ${target_var}=\"${target_}\" } diff --git a/scripts/build/arch/sparc.sh b/scripts/build/arch/sparc.sh index 189cebe2..15213a6a 100644 --- a/scripts/build/arch/sparc.sh +++ b/scripts/build/arch/sparc.sh @@ -19,11 +19,12 @@ CT_DoArchTupleValues() { #------------------------------------------------------------------------------ # Get multilib architecture-specific target -# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +# Usage: CT_DoArchMultilibTarget "target variable" "multilib flags" CT_DoArchMultilibTarget () { - local target="${1}"; shift + local target_var="${1}"; shift local -a multi_flags=( "$@" ) + local target_ local m32=false local m64=false @@ -35,29 +36,37 @@ CT_DoArchMultilibTarget () esac done + eval target_=\"\${${target_var}}\" + # Fix up bitness - case "${target}" in - sparc-*) $m64 && target=${target/#sparc-/sparc64-} ;; - sparc64-*) $m32 && target=${target/#sparc64-/sparc-} ;; + case "${target_}" in + sparc-*) $m64 && target_=${target_/#sparc-/sparc64-} ;; + sparc64-*) $m32 && target_=${target_/#sparc64-/sparc-} ;; esac - echo "${target}" + # Set the target variable + eval ${target_var}=\"${target_}\" } # Special tuple adjustment for glibc. CT_DoArchGlibcAdjustTuple() { - local target="${1}" + local target_var="${1}" + local target_ + + eval target_=\"\${${target_var}}\" - case "${target}" in + case "${target_}" in # SPARC quirk: glibc 2.23 and newer dropped support for SPARCv8 and # earlier (corresponding pthread barrier code is missing). Until this # support is reintroduced, configure as sparcv9. sparc-*) if [ "${CT_LIBC_GLIBC_2_23_or_later}" = y ]; then - target=${target/#sparc-/sparcv9-} + CT_DoLog WARN "GLIBC 2.23 only supports SPARCv9" + target_=${target_/#sparc-/sparcv9-} fi ;; esac - echo "${target}" + # Set the target variable + eval ${target_var}=\"${target_}\" } diff --git a/scripts/build/arch/x86.sh b/scripts/build/arch/x86.sh index 0e41d67f..51476786 100644 --- a/scripts/build/arch/x86.sh +++ b/scripts/build/arch/x86.sh @@ -35,11 +35,12 @@ CT_DoArchTupleValues() { #------------------------------------------------------------------------------ # Get multilib architecture-specific target -# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +# Usage: CT_DoArchMultilibTarget "target variable" "multilib flags" CT_DoArchMultilibTarget () { - local target="${1}"; shift + local target_var="${1}"; shift local -a multi_flags=( "$@" ) + local target_ local bit32=false local bit64=false @@ -54,26 +55,32 @@ CT_DoArchMultilibTarget () esac done + eval target_=\"\${${target_var}}\" + # Fix up architecture. - case "${target}" in - x86_64-*) $bit32 && target=${target/#x86_64-/i386-} ;; - i[34567]86-*) $bit64 && target=${target/#i[34567]86-/x86_64-} ;; + case "${target_}" in + x86_64-*) $bit32 && target_=${target_/#x86_64-/i386-} ;; + i[34567]86-*) $bit64 && target_=${target_/#i[34567]86-/x86_64-} ;; esac # Fix up the ABI part. - case "${target}" in - *x32) $abi_dflt && target=${target/%x32} ;; - *) $abi_x32 && target=${target}x32 ;; + case "${target_}" in + *x32) $abi_dflt && target_=${target_/%x32} ;; + *) $abi_x32 && target_=${target_}x32 ;; esac - echo "${target}" + # Set the target variable + eval ${target_var}=\"${target_}\" } # Adjust target tuple for GLIBC CT_DoArchGlibcAdjustTuple() { - local target="${1}" + local target_var="${1}" + local target_ + + eval target_=\"\${${target_var}}\" - case "${target}" in + case "${target_}" in # x86 quirk: architecture name is i386, but glibc expects i[4567]86 - to # indicate the desired optimization. If it was a multilib variant of x86_64, # then it targets at least NetBurst a.k.a. i786, but we'll follow the model @@ -81,14 +88,15 @@ CT_DoArchGlibcAdjustTuple() { # conservative choice, i486. i386-*) if [ "${CT_TARGET_ARCH}" = "x86_64" ]; then - target=${target/#i386-/i686-} + target_=${target_/#i386-/i686-} elif [ "${CT_TARGET_ARCH}" != "i386" ]; then - target=${target/#i386-/${CT_TARGET_ARCH}-} + target_=${target_/#i386-/${CT_TARGET_ARCH}-} else - target=${target/#i386-/i486-} + target_=${target_/#i386-/i486-} fi ;; esac - echo "${target}" + # Set the target variable + eval ${target_var}=\"${target_}\" } diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index a08ed973..dc9443c0 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -120,8 +120,9 @@ do_libc_backend() { multi_root=$( "${CT_TARGET}-gcc" -print-sysroot ${multi_flags} ) # Adjust target tuple according to CFLAGS + any GLIBC quirks - target=$( CT_DoMultilibTarget "${CT_TARGET}" ${extra_flags} ) - target=$( CT_DoArchGlibcAdjustTuple "${target}" ) + target="${CT_TARGET}" + CT_DoMultilibTarget target ${extra_flags} + CT_DoArchGlibcAdjustTuple target CT_DoStep INFO "Building for multilib '${multi_flags}'" # Ensure sysroot (with suffix, if applicable) exists diff --git a/scripts/functions b/scripts/functions index 49b06869..ef75e09e 100644 --- a/scripts/functions +++ b/scripts/functions @@ -1371,18 +1371,18 @@ CT_DoBuildTargetTuple() { # GCC prints nothing and exits with status 0), falling back to calling # the architecture-specific functions. CT_DoMultilibTarget() { - local target="$1"; shift + local target_var="$1"; shift local -a multi_flags=( "$@" ) local gcc_multiarch gcc_multiarch=$( "${CT_TARGET}-gcc" -print-multiarch "${multi_flags[@]}" ) if [ -n "${gcc_multiarch}" ]; then - echo "${gcc_multiarch}" + eval "${target_var}=${gcc_multiarch}" return fi # Fall back to arch-specific guesswork - CT_DoArchMultilibTarget "${target}" "${multi_flags[@]}" + CT_DoArchMultilibTarget "${target_var}" "${multi_flags[@]}" } # This function does pause the build until the user strikes "Return" -- cgit v1.2.3 From 98e556d3868b638a658f497af0b64ce04fc5287d Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Mon, 11 Apr 2016 13:59:16 -0700 Subject: Support multilib in sh/uClibc. Signed-off-by: Alexey Neyman --- scripts/build/arch/sh.sh | 32 ++++++++- scripts/build/libc/glibc.sh | 122 +++++----------------------------- scripts/build/libc/uClibc.sh | 125 ++++++++++++----------------------- scripts/functions | 151 +++++++++++++++++++++++++++++++++++-------- 4 files changed, 213 insertions(+), 217 deletions(-) (limited to 'scripts/functions') diff --git a/scripts/build/arch/sh.sh b/scripts/build/arch/sh.sh index 101e4ce8..6761435d 100644 --- a/scripts/build/arch/sh.sh +++ b/scripts/build/arch/sh.sh @@ -44,9 +44,39 @@ CT_DoArchUClibcConfig() { CT_KconfigDisableOption "CONFIG_SH3" "${cfg}" CT_KconfigDisableOption "CONFIG_SH4" "${cfg}" CT_KconfigDisableOption "CONFIG_SH4A" "${cfg}" - case "${CT_ARCH_SH_VARIAN}" in + case "${CT_ARCH_SH_VARIANT}" in sh3) CT_KconfigEnableOption "CONFIG_SH3" "${cfg}";; sh4) CT_KconfigEnableOption "CONFIG_SH4" "${cfg}";; sh4a) CT_KconfigEnableOption "CONFIG_SH4A" "${cfg}";; esac } + +CT_DoArchUClibcCflags() { + local cfg="${1}" + local cflags="${2}" + local f + + for f in ${cflags}; do + case "${f}" in + -m3) + CT_KconfigEnableOption "CONFIG_SH3" "${cfg}" + ;; + -m4) + CT_KconfigEnableOption "CONFIG_SH4" "${cfg}" + CT_KconfigEnableOption "UCLIBC_HAS_FPU" "${cfg}" + ;; + -m4-nofpu) + CT_KconfigEnableOption "CONFIG_SH4" "${cfg}" + CT_KconfigDisableOption "UCLIBC_HAS_FPU" "${cfg}" + ;; + -m4a) + CT_KconfigEnableOption "CONFIG_SH4A" "${cfg}" + CT_KconfigEnableOption "UCLIBC_HAS_FPU" "${cfg}" + ;; + -m4a-nofpu) + CT_KconfigEnableOption "CONFIG_SH4A" "${cfg}" + CT_KconfigDisableOption "UCLIBC_HAS_FPU" "${cfg}" + ;; + esac + done +} diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index 8093e08b..8027b8f8 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -64,11 +64,6 @@ do_libc_post_cc() { # libc_mode : 'startfiles' or 'final' : string : (none) do_libc_backend() { local libc_mode - local -a multilibs - local multilib - local multi_dir multi_os_dir multi_root multi_flags multi_last - local root_suffix - local target local arg for arg in "$@"; do @@ -88,94 +83,7 @@ do_libc_backend() { esac CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-${libc_mode}" - - # If gcc is not configured for multilib, it still prints - # a single line for the default settings - multilibs=( $("${CT_TARGET}-gcc" -print-multi-lib 2>/dev/null) ) - for multilib in "${multilibs[@]}"; do - # 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/ - # The problem is that while GCC itself is aware of these subtleties, the - # binutils (notably, ld) it invokes under the hood are not. For example, - # if a shared library libfoo.so.1 requires libbar.so.1, ld will only search - # for libbar.so.1 in /m4a/usr/lib, but not in /m4a/usr/lib/m4a. - # In other words, 'gcc -lfoo -lbar' will work for both the default and -m4a - # cases, and 'gcc -lfoo' will work for the default, but not for -m4a. To - # address this, we first try to determine if the sysroot alone makes the - # configuration sufficiently unique. If there are no multilibs within the - # same suffixed sysroot, we can drop the multi_os_dir and both gcc and ld - # will work. If not, we'll supply both multi_root/multi_os_dir (which will - # likely break later, e.g. while building final GCC with C++ support). But, - # we've done all we can. - multi_flags=$( echo "${multilib#*;}" | ${sed} -r -e 's/@/ -/g;' ) - multi_dir="${multilib%%;*}" - multi_os_dir=$( "${CT_TARGET}-gcc" -print-multi-os-directory ${multi_flags} ) - multi_root=$( "${CT_TARGET}-gcc" -print-sysroot ${multi_flags} ) - root_suffix="${multi_root#${CT_SYSROOT_DIR}}" - CT_DoExecLog ALL mkdir -p "sysroot${root_suffix}" - if [ -e "sysroot${root_suffix}/seen" ]; then - CT_DoExecLog ALL rm -f "sysroot${root_suffix}/unique" - else - CT_DoExecLog ALL touch "sysroot${root_suffix}/seen" "sysroot${root_suffix}/unique" - fi - done - - last_multi= - for multilib in "${multilibs[@]}"; do - last_multi=$(( ${#multilibs[@]} - 1 )) - if [ "${multilib%%;*}" = "${multilibs[last_multi]%%;*}" ]; then - # This is the last multilib build or multilib is '.' - # (default target, not multilib) - multi_last=y - fi - - multi_flags=$( echo "${multilib#*;}" | ${sed} -r -e 's/@/ -/g;' ) - multi_dir="${multilib%%;*}" - multi_os_dir=$( "${CT_TARGET}-gcc" -print-multi-os-directory ${multi_flags} ) - multi_root=$( "${CT_TARGET}-gcc" -print-sysroot ${multi_flags} ) - root_suffix="${multi_root#${CT_SYSROOT_DIR}}" - - # Avoid multi_os_dir if it's the only directory in this sysroot. - if [ -e "sysroot${root_suffix}/unique" ]; then - multi_os_dir=. - fi - - # Adjust target tuple according to CFLAGS + any GLIBC quirks - target="${CT_TARGET}" - CT_DoMultilibTarget target ${extra_flags} - CT_DoArchGlibcAdjustTuple target - 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 "multilib_${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 - CT_EndStep - - done - + CT_IterateMultilibs do_libc_backend_once multilib libc_mode="${libc_mode}" CT_Popd CT_EndStep } @@ -184,26 +92,28 @@ do_libc_backend() { # Usage: do_libc_backend_once param=value [...] # 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 +# multi_* : as defined in CT_IterateMultilibs : (varies) : do_libc_backend_once() { - local multi_flags multi_dir multi_os_dir multi_root multi_last multi_root + local multi_flags multi_dir multi_os_dir multi_root multi_index multi_count local startfiles_dir local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}" local -a extra_config local -a extra_make_args local glibc_cflags - local libc_target="${CT_TARGET}" local arg opt for arg in "$@"; do eval "${arg// /\\ }" done + CT_DoStep INFO "Building for multilib ${multi_index}/${multi_count}: '${multi_flags}'" + + # Ensure sysroot (with suffix, if applicable) exists + CT_DoExecLog ALL mkdir -p "${multi_root}" + + # Adjust target tuple according GLIBC quirks + CT_DoArchGlibcAdjustTuple multi_target + # 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 @@ -335,7 +245,7 @@ do_libc_backend_once() { CT_DoLog DEBUG "Extra config args passed : '${extra_config[*]}'" CT_DoLog DEBUG "Extra CFLAGS passed : '${glibc_cflags}'" CT_DoLog DEBUG "Placing startfiles into : '${startfiles_dir}'" - CT_DoLog DEBUG "Configuring with --host : '${libc_target}'" + CT_DoLog DEBUG "Configuring with --host : '${multi_target}'" # CFLAGS are only applied when compiling .c files. .S files are compiled with ASFLAGS, # but they are not passed by configure. Thus, pass everything in CC instead. @@ -348,7 +258,7 @@ do_libc_backend_once() { "${src_dir}/configure" \ --prefix=/usr \ --build=${CT_BUILD} \ - --host=${libc_target} \ + --host=${multi_target} \ --cache-file="$(pwd)/config.cache" \ --without-cvs \ --disable-profile \ @@ -474,7 +384,7 @@ do_libc_backend_once() { install_root="${multi_root}" \ install - if [ "${CT_BUILD_MANUALS}" = "y" -a "${multi_last}" = "y" ]; then + if [ "${CT_BUILD_MANUALS}" = "y" -a "${multi_index}" = "${multi_count}" ]; then # We only need to build the manuals once. Only build them on the # last multilib target. If it's not multilib, it will happen on the # only target. @@ -488,10 +398,12 @@ do_libc_backend_once() { ${CT_PREFIX_DIR}/share/doc fi - if [ "${CT_LIBC_LOCALES}" = "y" -a "${multi_last}" = "y" ]; then + if [ "${CT_LIBC_LOCALES}" = "y" -a "${multi_index}" = "${multi_count}" ]; then do_libc_locales fi fi # libc_mode = final + + CT_EndStep } # Build up the addons list, separated with $1 diff --git a/scripts/build/libc/uClibc.sh b/scripts/build/libc/uClibc.sh index edde8159..046ba1d0 100644 --- a/scripts/build/libc/uClibc.sh +++ b/scripts/build/libc/uClibc.sh @@ -66,10 +66,7 @@ do_libc() { # Common backend for 1st and 2nd passes. do_libc_backend() { local libc_mode - local -a multilibs - local multilib - local multi_dir multi_os_dir multi_flags - local ldso ldso_f ldso_d multilib_dir + local arg for arg in "$@"; do eval "${arg// /\\ }" @@ -82,43 +79,7 @@ do_libc_backend() { esac CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-${libc_mode}" - - # See glibc.sh for the explanation of this magic. - multilibs=( $("${CT_TARGET}-gcc" -print-multi-lib 2>/dev/null) ) - for multilib in "${multilibs[@]}"; do - multi_flags=$( echo "${multilib#*;}" | ${sed} -r -e 's/@/ -/g;' ) - multi_dir="${multilib%%;*}" - multi_os_dir=$( "${CT_TARGET}-gcc" -print-multi-os-directory ${multi_flags} ) - multi_root=$( "${CT_TARGET}-gcc" -print-sysroot ${multi_flags} ) - root_suffix="${multi_root#${CT_SYSROOT_DIR}}" - CT_DoExecLog ALL mkdir -p "sysroot${root_suffix}" - if [ -e "sysroot${root_suffix}/seen" ]; then - CT_DoExecLog ALL rm -f "sysroot${root_suffix}/unique" - else - CT_DoExecLog ALL touch "sysroot${root_suffix}/seen" "sysroot${root_suffix}/unique" - fi - done - - for multilib in "${multilibs[@]}"; do - multi_flags=$( echo "${multilib#*;}" | ${sed} -r -e 's/@/ -/g;' ) - multi_dir="${multilib%%;*}" - multi_os_dir=$( "${CT_TARGET}-gcc" -print-multi-os-directory ${multi_flags} ) - multi_root=$( "${CT_TARGET}-gcc" -print-sysroot ${multi_flags} ) - root_suffix="${multi_root#${CT_SYSROOT_DIR}}" - - # Avoid multi_os_dir if it's the only directory in this sysroot. - if [ -e "sysroot${root_suffix}/unique" ]; then - multi_os_dir=. - fi - - CT_DoStep INFO "Building for multilib '${multi_flags}'" - do_libc_backend_once multi_dir="${multi_dir}" \ - multi_os_dir="${multi_os_dir}" \ - multi_flags="${multi_flags}" \ - multi_root="${multi_root}" \ - libc_mode="${libc_mode}" - CT_EndStep - done + CT_IterateMultilibs do_libc_backend_once multilib libc_mode="${libc_mode}" if [ "${libc_mode}" = "final" -a "${CT_SHARED_LIBS}" = "y" ]; then # uClibc and GCC disagree where the dynamic linker lives. uClibc always @@ -127,42 +88,7 @@ do_libc_backend() { # to the actual location, but only if that will not override the actual # file in /lib. Thus, need to do this after all the variants are built. echo "int main(void) { return 0; }" > test-ldso.c - for multilib in "${multilibs[@]}"; do - multi_flags=$( echo "${multilib#*;}" | ${sed} -r -e 's/@/ -/g;' ) - multi_os_dir=$( "${CT_TARGET}-gcc" -print-multi-os-directory ${multi_flags} ) - multi_root=$( "${CT_TARGET}-gcc" -print-sysroot ${multi_flags} ) - root_suffix="${multi_root#${CT_SYSROOT_DIR}}" - - # Avoid multi_os_dir if it's the only directory in this sysroot. - if [ -e "sysroot${root_suffix}/unique" ]; then - multi_os_dir=. - fi - - multilib_dir="/lib/${multi_os_dir}" - CT_SanitizeVarDir multilib_dir - - CT_DoExecLog ALL "${CT_TARGET}-gcc" -o test-ldso test-ldso.c ${multi_flags} - ldso=$( ${CT_TARGET}-readelf -Wl test-ldso | \ - grep 'Requesting program interpreter: ' | \ - sed -e 's,.*: ,,' -e 's,\].*,,' ) - ldso_d="${ldso%/ld*.so.*}" - ldso_f="${ldso##*/}" - if [ -z "${ldso}" -o "${ldso_d}" = "${multilib_dir}" ]; then - # GCC cannot produce shared executable, or the base directory - # for ld.so is the same as the multi_os_directory - continue - fi - - # If there is no such file in the expected ldso dir, create a symlink to - # multilib_dir ld.so - if [ ! -r "${multi_root}${ldso}" ]; then - # Convert ldso_d to "how many levels we need to go up" and remove - # leading slash. - ldso_d=$( echo "${ldso_d#/}" | sed 's,[^/]\+,..,g' ) - CT_DoExecLog ALL ln -sf "${ldso_d}${multilib_dir}/${ldso_f}" \ - "${multi_root}${ldso}" - fi - done + CT_IterateMultilibs do_libc_ldso_fixup ldso_fixup fi CT_Popd @@ -172,10 +98,10 @@ do_libc_backend() { # Common backend for 1st and 2nd passes, once per multilib. do_libc_backend_once() { local libc_mode - local multi_dir multi_os_dir multi_root multilib_dir startfiles_dir + local multi_dir multi_os_dir multi_root multi_flags multi_index multi_count + local multilib_dir startfiles_dir local jflag=${CT_LIBC_UCLIBC_PARALLEL:+${JOBSFLAGS}} local -a make_args - local build_dir local extra_cflags f cfg_cflags cf local hdr_install_subdir @@ -183,11 +109,11 @@ do_libc_backend_once() { eval "${arg// /\\ }" done + CT_DoStep INFO "Building for multilib ${multi_index}/${multi_count}: '${multi_flags}'" + # Simply copy files until uClibc has the ability to build out-of-tree CT_DoLog EXTRA "Copying sources to build dir" - build_dir="multilib_${multi_dir//\//_}" - CT_DoExecLog ALL cp -a "${CT_SRC_DIR}/${uclibc_name}-${CT_LIBC_VERSION}" "${build_dir}" - CT_Pushd "${build_dir}" + CT_DoExecLog ALL cp -aT "${CT_SRC_DIR}/${uclibc_name}-${CT_LIBC_VERSION}" . multilib_dir="lib/${multi_os_dir}" startfiles_dir="${multi_root}/usr/${multilib_dir}" @@ -326,7 +252,40 @@ do_libc_backend_once() { CT_DoExecLog ALL mv "${multi_root}/usr/include.new" "${multi_root}/usr/include/${hdr_install_subdir}" fi - CT_Popd + CT_EndStep +} + +do_libc_ldso_fixup() { + local multi_dir multi_os_dir multi_root multi_flags multi_index multi_count + local ldso ldso_f ldso_d multilib_dir + + for arg in "$@"; do + eval "${arg// /\\ }" + done + + CT_DoLog EXTRA "Checking dynamic linker for multilib '${multi_flags}'" + + multilib_dir="/lib/${multi_os_dir}" + CT_SanitizeVarDir multilib_dir + + CT_DoExecLog ALL "${CT_TARGET}-gcc" -o test-ldso ../test-ldso.c ${multi_flags} + ldso=$( ${CT_TARGET}-readelf -Wl test-ldso | \ + grep 'Requesting program interpreter: ' | \ + sed -e 's,.*: ,,' -e 's,\].*,,' ) + CT_DoLog DEBUG "Detected dynamic linker for multilib '${multi_flags}': '${ldso}'" + + ldso_d="${ldso%/ld*.so.*}" + ldso_f="${ldso##*/}" + # Create symlink if GCC produced an executable, dynamically linked, it was requesting + # a linker not in the current directory, and there is no such file in the expected + # ldso dir. + if [ -n "${ldso}" -a "${ldso_d}" != "${multilib_dir}" -a ! -r "${multi_root}${ldso}" ]; then + # Convert ldso_d to "how many levels we need to go up" and remove + # leading slash. + ldso_d=$( echo "${ldso_d#/}" | sed 's,[^/]\+,..,g' ) + CT_DoExecLog ALL ln -sf "${ldso_d}${multilib_dir}/${ldso_f}" \ + "${multi_root}${ldso}" + fi } # Initialises the .config file to sensible values diff --git a/scripts/functions b/scripts/functions index ef75e09e..f1dfd127 100644 --- a/scripts/functions +++ b/scripts/functions @@ -1366,25 +1366,6 @@ CT_DoBuildTargetTuple() { fi } -# This function determines the target tuple for a given set of compiler -# flags, using either GCC's multiarch feature (if supported; if not, -# GCC prints nothing and exits with status 0), falling back to calling -# the architecture-specific functions. -CT_DoMultilibTarget() { - local target_var="$1"; shift - local -a multi_flags=( "$@" ) - local gcc_multiarch - - gcc_multiarch=$( "${CT_TARGET}-gcc" -print-multiarch "${multi_flags[@]}" ) - if [ -n "${gcc_multiarch}" ]; then - eval "${target_var}=${gcc_multiarch}" - return - fi - - # Fall back to arch-specific guesswork - CT_DoArchMultilibTarget "${target_var}" "${multi_flags[@]}" -} - # This function does pause the build until the user strikes "Return" # Usage: CT_DoPause [optional_message] CT_DoPause() { @@ -1529,9 +1510,9 @@ CT_DoLoadState(){ # This function sets a kconfig option to a specific value in a .config file # Usage: CT_KconfigSetOption