From b06f5ab6895d1342d76ed85fde804fafb2ea573c Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Fri, 10 Jun 2016 22:10:20 +0200 Subject: Update elf2flt git repository location The elf2flt git repository has been moved to GitHub. Updated the script accordingly. Signed-off-by: Martin Lund diff --git a/scripts/build/binutils/binutils.sh b/scripts/build/binutils/binutils.sh index edaf818..65a2dcc 100644 --- a/scripts/build/binutils/binutils.sh +++ b/scripts/build/binutils/binutils.sh @@ -25,7 +25,7 @@ do_binutils_get() { CT_GetCustom "elf2flt" "${CT_ELF2FLT_CUSTOM_VERSION}" \ "${CT_ELF2FLT_CUSTOM_LOCATION}" else - CT_GetGit elf2flt "${CT_ELF2FLT_GIT_CSET}" http://cgit.openadk.org/cgi/cgit/elf2flt.git + CT_GetGit elf2flt "${CT_ELF2FLT_GIT_CSET}" https://github.com/uclinux-dev/elf2flt.git fi fi } -- cgit v0.10.2-6-g49f6 From e4a21f634dc2ff526369c8835e87da32017e2087 Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Tue, 14 Jun 2016 07:53:21 +0200 Subject: Update elf2flt default cset diff --git a/config/binutils/binutils.in.2 b/config/binutils/binutils.in.2 index 3dafb0f..336098b 100644 --- a/config/binutils/binutils.in.2 +++ b/config/binutils/binutils.in.2 @@ -29,7 +29,7 @@ if ELF2FLT_GIT config ELF2FLT_GIT_CSET string prompt "git cset" - default "454b6b415a31959661406bdfbd9dad22229367bf" + default "9dbc458c6122c495bbdec8dc975a15c9d39e5ff2" help Enter the git changeset to use. -- cgit v0.10.2-6-g49f6 From 4090f17e6b1b0ea0fd8372c5016fdf4fd4b2e3d0 Mon Sep 17 00:00:00 2001 From: Vaibhav Jain Date: Tue, 19 Jul 2016 15:03:05 +0530 Subject: samples: Add powerpc64 little-endian toolchain sample This change adds a powerpc64le-unknown-linux-gnu sample that can be used to quickly create a little-endian tool-chain for powerpc64 architecture. This sample is based on the earlier work done by "Yann E. MORIN" to add support for powerpc64 tool chain and implementing the power64-unknown-linux-gnu sample. The existing sample however generates a big-endian tool chain by default. Signed-off-by: Vaibhav Jain diff --git a/samples/powerpc64le-unknown-linux-gnu/crosstool.config b/samples/powerpc64le-unknown-linux-gnu/crosstool.config new file mode 100644 index 0000000..6c7771d --- /dev/null +++ b/samples/powerpc64le-unknown-linux-gnu/crosstool.config @@ -0,0 +1,13 @@ +CT_LOCAL_TARBALLS_DIR="${HOME}/src" +CT_SAVE_TARBALLS=y +CT_LOG_EXTRA=y +CT_ARCH_64=y +CT_ARCH_powerpc=y +CT_KERNEL_linux=y +CT_BINUTILS_PLUGINS=y +CT_CC_LANG_CXX=y +CT_DEBUG_gdb=y +# CT_GDB_CROSS_PYTHON is not set +CT_GDB_NATIVE=y +CT_ARCH_ENDIAN="little" +CT_ARCH_LE=y diff --git a/samples/powerpc64le-unknown-linux-gnu/reported.by b/samples/powerpc64le-unknown-linux-gnu/reported.by new file mode 100644 index 0000000..0bcecbb --- /dev/null +++ b/samples/powerpc64le-unknown-linux-gnu/reported.by @@ -0,0 +1,3 @@ +reporter_name="Vaibhav Jain" +reporter_url="https://github.com/vaibhav92/crosstool-ng" +reporter_comment="Based on power64-unknown-linux-gnu sample implemented by Yann E. MORIN" -- cgit v0.10.2-6-g49f6 From 269eb6387594c4e680684198a33b26ca0c4acf7f Mon Sep 17 00:00:00 2001 From: "Kirill K. Smirnov" Date: Tue, 26 Jul 2016 00:26:17 +0300 Subject: Add sparc-leon-linux-uclibc sample Signed-off-by: Kirill K. Smirnov diff --git a/samples/sparc-leon-linux-uclibc/crosstool.config b/samples/sparc-leon-linux-uclibc/crosstool.config new file mode 100644 index 0000000..4afde66 --- /dev/null +++ b/samples/sparc-leon-linux-uclibc/crosstool.config @@ -0,0 +1,17 @@ +CT_LOCAL_TARBALLS_DIR="${HOME}/src" +CT_SAVE_TARBALLS=y +CT_LOG_EXTRA=y +CT_ARCH_CPU="leon" +CT_ARCH_TUNE="leon" +CT_ARCH_FLOAT_SW=y +CT_ARCH_sparc=y +CT_TARGET_VENDOR="leon" +CT_KERNEL_linux=y +CT_KERNEL_V_3_10=y +CT_LIBC_uClibc=y +CT_LIBC_UCLIBC_CONFIG_FILE="${CT_LIB_DIR}/samples/${CT_TARGET}/${CT_LIBC}-${CT_LIBC_VERSION}.config" +CT_LIBC_UCLIBC_IPV6=y +CT_LIBC_UCLIBC_WCHAR=y +CT_CC_GCC_V_4_9_3=y +CT_CC_GCC_EXTRA_CONFIG_ARRAY="--disable-libitm" +CT_CC_LANG_CXX=y diff --git a/samples/sparc-leon-linux-uclibc/reported.by b/samples/sparc-leon-linux-uclibc/reported.by new file mode 100644 index 0000000..edba82e --- /dev/null +++ b/samples/sparc-leon-linux-uclibc/reported.by @@ -0,0 +1,3 @@ +reporter_name="Kirill K. Smirnov" +reporter_url="" +reporter_comment="For sparc/leon without FPU" diff --git a/samples/sparc-leon-linux-uclibc/uClibc-1.0.12.config b/samples/sparc-leon-linux-uclibc/uClibc-1.0.12.config new file mode 100644 index 0000000..abcfe40 --- /dev/null +++ b/samples/sparc-leon-linux-uclibc/uClibc-1.0.12.config @@ -0,0 +1,20 @@ +TARGET_sparc=y +# UCLIBC_HAS_FPU is not set +DO_C99_MATH=y +UCLIBC_HAS_THREADS_NATIVE=y +UCLIBC_SUSV3_LEGACY=y +UCLIBC_SUSV4_LEGACY=y +# UNIX98PTY_ONLY is not set +UCLIBC_HAS_LIBUTIL=y +UCLIBC_HAS_SHA256_CRYPT_IMPL=y +UCLIBC_HAS_SHA512_CRYPT_IMPL=y +UCLIBC_HAS_IPV6=y +UCLIBC_HAS_RPC=y +UCLIBC_HAS_FULL_RPC=y +UCLIBC_HAS_REENTRANT_RPC=y +UCLIBC_USE_NETLINK=y +UCLIBC_HAS_RESOLVER_SUPPORT=y +UCLIBC_HAS_LIBRESOLV_STUB=y +UCLIBC_HAS_WCHAR=y +UCLIBC_HAS_GLIBC_CUSTOM_PRINTF=y +UCLIBC_HAS_PRINTF_M_SPEC=y -- cgit v0.10.2-6-g49f6 From a2d6572b4586baa57a7e9c3c8426109e6e2c0048 Mon Sep 17 00:00:00 2001 From: Jean-Marie Lemetayer Date: Tue, 26 Jul 2016 16:07:58 +0200 Subject: populate: Fix undefined awk Fix minor issue introduced by 6f8e89cb5ca061e899bf3feaaf3fecf30d366c3e diff --git a/scripts/build/internals.sh b/scripts/build/internals.sh index a2351ac..ce36f52 100644 --- a/scripts/build/internals.sh +++ b/scripts/build/internals.sh @@ -64,6 +64,7 @@ do_finish() { CT_DoLog EXTRA "Installing the populate helper" ${sed} -r -e 's|@@CT_TARGET@@|'"${CT_TARGET}"'|g;' \ -e 's|@@CT_install@@|'"${install}"'|g;' \ + -e 's|@@CT_awk@@|'"${awk}"'|g;' \ -e 's|@@CT_bash@@|'"${bash}"'|g;' \ -e 's|@@CT_grep@@|'"${grep}"'|g;' \ -e 's|@@CT_make@@|'"${make}"'|g;' \ -- cgit v0.10.2-6-g49f6 From 29df8cccf445aaacd7bd1163ab0c4860ee3e1890 Mon Sep 17 00:00:00 2001 From: Carlos Santos Date: Tue, 16 Aug 2016 23:56:23 -0300 Subject: scripts/functions: fix log level in call to CT_DoLog It must be "DEBUG", not "Debug" Signed-off-by: Carlos Santos diff --git a/scripts/functions b/scripts/functions index 62d264e..ca7713a 100644 --- a/scripts/functions +++ b/scripts/functions @@ -928,7 +928,7 @@ CT_GetGit() { else # Woops... CT_DoExecLog ALL rm -rf "${dir}" - CT_DoLog Debug "Could not clone '${basename}'" + CT_DoLog DEBUG "Could not clone '${basename}'" return 1 fi } -- cgit v0.10.2-6-g49f6 From 098bd01f81b6eea922cb1c4edcd8aff398616641 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sat, 21 May 2016 16:55:56 -0700 Subject: glibc.sh: Use --print-multi-os-directory 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. Use this to build libc into the correct locations, the same applies to the dummy libc.so Changed by Alexey Neyman: restore missing CT_EndStep. Signed-off-by: Ray Donnelly Signed-off-by: Alexey Neyman diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index 472acad..2efcf8d 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -72,6 +72,7 @@ do_libc_backend() { local multilib local multi_dir local multi_flags + local target local extra_dir local target local libc_headers libc_startfiles libc_full @@ -166,32 +167,13 @@ do_libc_backend() { libc_headers="${libc_headers}" \ libc_startfiles="${libc_startfiles}" \ libc_full="${libc_full}" \ - target="${target}" + libc_target="${target}" CT_Popd - if [ "${multi_dir}" != "." ]; then - if [ "${libc_mode}" = "final" ]; then - CT_DoLog EXTRA "Fixing up multilib location" - - # rewrite the library multiplexers - for d in "lib/${multi_dir}" "usr/lib/${multi_dir}"; do - for l in libc libpthread libgcc_s; do - if [ -f "${CT_SYSROOT_DIR}/${d}/${l}.so" \ - -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so ] - then - CT_DoExecLog DEBUG ${sed} -r -i \ - -e "s:/lib/:/lib/${multi_dir}/:g;" \ - "${CT_SYSROOT_DIR}/${d}/${l}.so" - fi - done - done - # Remove the multi_dir now it is no longer useful - CT_DoExecLog DEBUG rm -rf "${CT_SYSROOT_DIR}/${multi_dir}" - fi # libc_mode == final - CT_EndStep fi + done CT_EndStep @@ -202,16 +184,19 @@ do_libc_backend() { # 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) -# target : Build libc using this target (for multilib) : string : ${CT_TARGET} 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 src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}" local extra_cc_args local -a extra_config @@ -219,17 +204,13 @@ do_libc_backend_once() { local glibc_cflags local float_extra local endian_extra - local target + local libc_target="${CT_TARGET}" local arg for arg in "$@"; do eval "${arg// /\\ }" done - if [ "${target}" = "" ]; then - target="${CT_TARGET}" - fi - CT_DoLog EXTRA "Configuring C library" case "${CT_LIBC}" in @@ -347,6 +328,24 @@ 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 @@ -357,11 +356,14 @@ 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 "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 "Configuring with --host : '${libc_target}'" + CT_DoLog DEBUG "Configuring with --libdir: '${lib_dir}'" CT_DoExecLog CFG \ BUILD_CC="${CT_BUILD}-gcc" \ @@ -373,12 +375,13 @@ do_libc_backend_once() { "${src_dir}/configure" \ --prefix=/usr \ --build=${CT_BUILD} \ - --host=${target} \ + --host=${libc_target} \ --cache-file="$(pwd)/config.cache" \ --without-cvs \ --disable-profile \ --without-gd \ --with-headers="${CT_HEADERS_DIR}" \ + --libdir=${lib_dir} \ "${extra_config[@]}" \ "${CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY[@]}" @@ -415,7 +418,7 @@ do_libc_backend_once() { # use the 'install-headers' makefile target to install the # headers CT_DoExecLog ALL ${make} ${JOBSFLAGS} \ - install_root=${CT_SYSROOT_DIR}${extra_dir} \ + install_root=${install_root} \ install-bootstrap-headers=yes \ "${extra_make_args[@]}" \ install-headers @@ -464,12 +467,12 @@ do_libc_backend_once() { # there are a few object files needed to link shared libraries, # which we build and install by hand - CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}${extra_dir}/usr/lib" + CT_DoExecLog ALL mkdir -p "${extraos_dir}" CT_DoExecLog ALL ${make} ${JOBSFLAGS} \ - "${extra_make_args[@]}" \ + "${extra_make_args[@]}" \ csu/subdir_lib CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \ - "${CT_SYSROOT_DIR}${extra_dir}/usr/lib" + "${extraos_dir}" # Finally, 'libgcc_s.so' requires a 'libc.so' to link against. # However, since we will never actually execute its code, @@ -480,7 +483,7 @@ do_libc_backend_once() { -nostartfiles \ -shared \ -x c /dev/null \ - -o "${CT_SYSROOT_DIR}${extra_dir}/usr/lib/libc.so" + -o "${extraos_dir}/libc.so" fi # threads == nptl fi # libc_headers == y @@ -491,9 +494,9 @@ do_libc_backend_once() { all CT_DoLog EXTRA "Installing C library" - CT_DoExecLog ALL ${make} ${JOBSFLAGS} \ - "${extra_make_args[@]}" \ - install_root="${CT_SYSROOT_DIR}${extra_dir}" \ + CT_DoExecLog ALL ${make} ${JOBSFLAGS} \ + "${extra_make_args[@]}" \ + install_root="${install_root}" \ install if [ "${CT_BUILD_MANUALS}" = "y" ]; then -- cgit v0.10.2-6-g49f6 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 diff --git a/scripts/build/cc/100-gcc.sh b/scripts/build/cc/100-gcc.sh index 7bb3610..57e46f9 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 } diff --git a/scripts/build/internals.sh b/scripts/build/internals.sh index a2351ac..047becd 100644 --- a/scripts/build/internals.sh +++ b/scripts/build/internals.sh @@ -118,12 +118,5 @@ do_finish() { CT_DoForceRmdir "${CT_DEBUGROOT_DIR}/"{,usr/}{,share/}{man,info} fi - # Remove the lib* symlinks, now: - # The symlinks are needed only during the build process. - # The final gcc will still search those dirs, but will also search - # the standard lib/ dirs, so we can get rid of the symlinks - CT_DoExecLog ALL rm -f "${CT_PREFIX_DIR}/lib32" - CT_DoExecLog ALL rm -f "${CT_PREFIX_DIR}/lib64" - CT_EndStep } diff --git a/scripts/crosstool-NG.sh.in b/scripts/crosstool-NG.sh.in index 3c193c3..6ae9d5d 100644 --- a/scripts/crosstool-NG.sh.in +++ b/scripts/crosstool-NG.sh.in @@ -325,40 +325,14 @@ if [ -z "${CT_RESTART}" ]; then fi CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}" CT_DoExecLog ALL mkdir -p "${CT_DEBUGROOT_DIR}" + CT_DoExecLog ALL mkdir -p "${CT_HEADERS_DIR}" - # Prepare the 'lib' directories in sysroot, else the ../lib64 hack used by - # 32 -> 64 bit crosscompilers won't work, and build of final gcc will fail - # with: "ld: cannot open crti.o: No such file or directory" - # Also prepare the lib directory in the install dir, else some 64 bit archs - # won't build + # Need the non-multilib directories: GCC's multi-os-directory is based off them, so + # even if the /lib is not used for any of the multilibs, it must be present so that + # the paths like 'lib/../lib64' still work. CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/lib" CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/lib" CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib" - CT_DoExecLog ALL mkdir -p "${CT_HEADERS_DIR}" - - if [ "${CT_USE_SYSROOT}" = "y" ]; then - # Prevent gcc from installing its libraries outside of the sysroot - CT_Pushd "${CT_PREFIX_DIR}/${CT_TARGET}" - CT_DoExecLog ALL ln -sf "${CT_SYSROOT_REL_DIR}/lib" "lib" - CT_Popd - fi - - # Since we're *not* multilib on the target side, we want all the - # libraries to end up in "lib". We create "lib64" (for 64-bit - # build or host architectures) and "lib32" (for 32-bit emulation - # on 64-bit) as symlinks to "lib". - # - # Not all of these symlinks are necessary, but better safe than - # sorry. They are summarily removed by build/internals.sh:do_finish. - for d in \ - "${CT_PREFIX_DIR}" \ - "${CT_SYSROOT_DIR}" \ - "${CT_SYSROOT_DIR}/usr" \ - "${CT_PREFIX_DIR}/${CT_TARGET}" \ - ; do - CT_DoExecLog ALL ln -sf "lib" "${d}/lib32" - CT_DoExecLog ALL ln -sf "lib" "${d}/lib64" - done # Determine build system if not set by the user if [ -z "${CT_BUILD}" ]; then -- cgit v0.10.2-6-g49f6 From cc86d80da26aa27c382dee5ef44d21f450b3ae60 Mon Sep 17 00:00:00 2001 From: Ray Donnelly Date: Sat, 12 Apr 2014 13:19:06 +0100 Subject: glibc: Build manuals and locales last Rather then building the manuals and locales for each multilib target, only build the manuals on the last multilib target. If you are not building a multilib toolchain, then the first libc build will be the last. Signed-off-by: Bryan Hundven diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index 2efcf8d..cff6d95 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -72,6 +72,7 @@ do_libc_backend() { local multilib local multi_dir local multi_flags + local multi_last local target local extra_dir local target @@ -102,7 +103,14 @@ do_libc_backend() { # 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) ) + 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_dir="${multilib%%;*}" if [ "${multi_dir}" != "." ]; then CT_DoStep INFO "Building for multilib subdir='${multi_dir}'" @@ -167,7 +175,8 @@ do_libc_backend() { libc_headers="${libc_headers}" \ libc_startfiles="${libc_startfiles}" \ libc_full="${libc_full}" \ - libc_target="${target}" + libc_target="${target}" \ + multi_last="${multi_last}" CT_Popd if [ "${multi_dir}" != "." ]; then @@ -188,6 +197,7 @@ do_libc_backend() { # 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) +# multi_last : The last multilib target : bool : n do_libc_backend_once() { local libc_headers local libc_startfiles @@ -205,6 +215,7 @@ do_libc_backend_once() { local float_extra local endian_extra local libc_target="${CT_TARGET}" + local multi_last local arg for arg in "$@"; do @@ -499,7 +510,10 @@ do_libc_backend_once() { install_root="${install_root}" \ install - if [ "${CT_BUILD_MANUALS}" = "y" ]; then + if [ "${CT_BUILD_MANUALS}" = "y" -a "${multi_last}" = "y" ]; 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. CT_DoLog EXTRA "Building and installing the C library manual" # Omit JOBSFLAGS as GLIBC has problems building the # manuals in parallel @@ -510,7 +524,7 @@ do_libc_backend_once() { ${CT_PREFIX_DIR}/share/doc fi - if [ "${CT_LIBC_LOCALES}" = "y" ]; then + if [ "${CT_LIBC_LOCALES}" = "y" -a "${multi_last}" = "y" ]; then do_libc_locales fi fi # libc_full == y -- cgit v0.10.2-6-g49f6 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 diff --git a/config/target.in b/config/target.in index 8cbaabc..e8f0fe7 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 57e46f9..72e9dd0 100644 --- a/scripts/build/cc/100-gcc.sh +++ b/scripts/build/cc/100-gcc.sh @@ -85,6 +85,167 @@ cc_gcc_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() { local -a core_opts @@ -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 cff6d95..c419603 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 6ae9d5d..9a4091a 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 62d264e..557c028 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 v0.10.2-6-g49f6 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 diff --git a/scripts/build/cc/100-gcc.sh b/scripts/build/cc/100-gcc.sh index 72e9dd0..db14728 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 c419603..c3926bf 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 2699d79..e0e9c63 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 422412c..7903a76 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 9a4091a..b49c68e 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 557c028..2331557 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 v0.10.2-6-g49f6 From d58e740be8ea07e5f4f24378f903773eae247828 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Thu, 31 Mar 2016 08:44:50 -0700 Subject: glibc.sh: cleanups - Dump CT_LIBC_EXTRA_CC_ARGS: instead, treat CT_LIBC_EXTRA_CFLAGS as arguments to CC (or they are not applied to .S, for example). Combine them with multi_flags and CT_TARGET_CFLAGS in proper order. - Analyze thus combined flags to determine --with-fp/--without-fp. Don't need to check CT_ARCH_FLOAT - it is reflected in CT_TARGET_CFLAGS anyway. Check more soft/hard float options defined on different architectures. - Drop checking for endianness flags: they are not reflected in configure arguments in any way, and they're already present in CFLAGS (either via multi_flags or via CT_TARGET_CFLAGS). Besides, CT_ARCH_ENDIAN_OPT was actually called CT_ARCH_ENDIAN_CFLAG, so this was a no-op anyway. Signed-off-by: Alexey Neyman diff --git a/config/libc/glibc.in.2 b/config/libc/glibc.in.2 index 346f9b7..104552a 100644 --- a/config/libc/glibc.in.2 +++ b/config/libc/glibc.in.2 @@ -55,16 +55,6 @@ config LIBC_GLIBC_EXTRA_CFLAGS help Extra target CFLAGS to use when building. -config LIBC_EXTRA_CC_ARGS - string - prompt "gcc extra flags" - default "" - help - Extra flags to pass gcc when building. - - Seldom used, except for sparc64 which seems to need the flag -64 - to be passed onto gcc. - config LIBC_ENABLE_FORTIFIED_BUILD bool prompt "Enable fortified build (EXPERIMENTAL)" diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index c3926bf..dcd9e15 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -182,14 +182,11 @@ do_libc_backend_once() { 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 local -a extra_make_args local glibc_cflags - local float_extra - local endian_extra local libc_target="${CT_TARGET}" - local arg + local arg opt for arg in "$@"; do eval "${arg// /\\ }" @@ -217,14 +214,8 @@ do_libc_backend_once() { CT_DoLog EXTRA "Configuring C library" - case "${CT_LIBC}" in - glibc) - # glibc can't be built without -O2 (reference needed!) - OPTIMIZE=-O2 - # Also, if those two are missing, iconv build breaks - extra_config+=( --disable-debug --disable-sanity-checks ) - ;; - esac + # Also, if those two are missing, iconv build breaks + extra_config+=( --disable-debug --disable-sanity-checks ) # always include rpc, the user can still override it with TI-RPC extra_config+=( --enable-obsolete-rpc ) @@ -252,21 +243,6 @@ do_libc_backend_once() { *) extra_config+=("--disable-shared");; esac - float_extra="$( echo "${multi_flags}" \ - |${sed} -r -e '/^(.*[[:space:]])?-m(hard|soft)-float([[:space:]].*)?$/!d;' \ - -e 's//\2/;' \ - )" - case "${float_extra}" in - hard) extra_config+=("--with-fp");; - soft) extra_config+=("--without-fp");; - "") - case "${CT_ARCH_FLOAT}" in - hard|softfp) extra_config+=("--with-fp");; - soft) extra_config+=("--without-fp");; - esac - ;; - esac - if [ "${CT_LIBC_DISABLE_VERSIONING}" = "y" ]; then extra_config+=("--disable-versioning") fi @@ -283,24 +259,6 @@ do_libc_backend_once() { extra_config+=("--with-pkgversion=${CT_PKGVERSION}") [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}") - # 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 "${multi_flags}" \ - |${sed} -r -e '/^(.*[[:space:]])?-(E[BL]|m((big|little)(-endian)?|e?[bl]))([[:space:]].*)?$/!d;' \ - -e 's//\2/;' \ - )" - # 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) - ;; - EL|mlittle-endian|mlittle|mel|ml) - ;; - "") extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}" - ;; - esac - touch config.cache if [ "${CT_LIBC_GLIBC_FORCE_UNWIND}" = "y" ]; then echo "libc_cv_forced_unwind=yes" >>config.cache @@ -310,13 +268,30 @@ do_libc_backend_once() { # Pre-seed the configparms file with values from the config option printf "%s\n" "${CT_LIBC_GLIBC_CONFIGPARMS}" > configparms - extra_cc_args+=" ${multi_flags}" + # glibc can't be built without -O2 (reference needed!) + glibc_cflags+=" -O2" case "${CT_LIBC_ENABLE_FORTIFIED_BUILD}" in y) ;; *) glibc_cflags+=" -U_FORTIFY_SOURCE";; esac - glibc_cflags+=" ${CT_TARGET_CFLAGS} ${OPTIMIZE} ${CT_LIBC_GLIBC_EXTRA_CFLAGS}" + + # In the order of increasing precedence. Flags common to compiler and linker. + glibc_cflags+=" ${CT_TARGET_CFLAGS}" + glibc_cflags+=" ${CT_LIBC_GLIBC_EXTRA_CFLAGS}" + glibc_cflags+=" ${multi_flags}" + + # Analyze the resulting options for any extra configure switches to throw in. + for opt in ${glibc_cflags}; do + case ${opt} in + -mhard-float|-mfloat-abi=hard|-mfloat-abi=softfp|-mno-soft-float|-mfpu) + extra_config+=("--with-fp") + ;; + -msoft-float|-mfloat-abi=soft|-mno-float|-mno-fpu) + extra_config+=("--without-fp") + ;; + esac + done # ./configure is mislead by our tools override wrapper for bash # so just tell it where the real bash is _on_the_target_! @@ -333,9 +308,12 @@ do_libc_backend_once() { # 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 - # Compare these options with the ones used when installing the glibc headers above - they're different. - # Adding "--without-gd" option to avoid error "memusagestat.c:36:16: gd.h: No such file or directory" + # to read up on what they all mean, and customize a bit, possibly + # by setting GLIBC_EXTRA_CONFIG_ARRAY. + # Compare these options with the ones used when installing + # the glibc headers above - they're different. + # Adding "--without-gd" option to avoid error "memusagestat.c:36:16: + # gd.h: No such file or directory" # See also http://sources.redhat.com/ml/libc-alpha/2000-07/msg00024.html. # Set BUILD_CC, or we won't be able to build datafiles # Run explicitly through CONFIG_SHELL, or the build breaks badly (loop-of-death) @@ -343,15 +321,15 @@ do_libc_backend_once() { 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) : '${multi_flags}'" + CT_DoLog DEBUG "Extra CFLAGS passed : '${glibc_cflags}'" CT_DoLog DEBUG "Placing startfiles into : '${startfiles_dir}'" CT_DoLog DEBUG "Configuring with --host : '${libc_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. CT_DoExecLog CFG \ - BUILD_CC="${CT_BUILD}-gcc" \ - CFLAGS="${glibc_cflags}" \ - CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \ + BUILD_CC=${CT_BUILD}-gcc \ + CC="${CT_TARGET}-gcc ${glibc_cflags}" \ AR=${CT_TARGET}-ar \ RANLIB=${CT_TARGET}-ranlib \ "${CONFIG_SHELL}" \ -- cgit v0.10.2-6-g49f6 From f204cc8ec4b70eee4de79ac5e7df831cfe0cb751 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Fri, 1 Apr 2016 15:43:56 -0700 Subject: Spelling fixes. Signed-off-by: Alexey Neyman diff --git a/config/cc/gcc.in b/config/cc/gcc.in index 2df2058..1fcdb72 100644 --- a/config/cc/gcc.in +++ b/config/cc/gcc.in @@ -226,7 +226,7 @@ config CC_GCC_HAS_LNK_HASH_STYLE bool # Only enable gcc's support for plugins if binutils has it as well -# They are usefull only when doing LTO, but it does no harm enabling +# They are useful only when doing LTO, but it does no harm enabling # them even without LTO. config CC_GCC_ENABLE_PLUGINS bool diff --git a/config/debug/gdb.in.cross b/config/debug/gdb.in.cross index 07b85b8..fb993c9 100644 --- a/config/debug/gdb.in.cross +++ b/config/debug/gdb.in.cross @@ -21,7 +21,7 @@ config GDB_CROSS_STATIC depends on CONFIGURE_has_static_link select WANTS_STATIC_LINK help - A static cross gdb can be usefull if you debug on a machine that is + A static cross gdb can be useful if you debug on a machine that is not the one that is used to compile the toolchain. That way, you can share the cross-gdb without installing a toolchain diff --git a/config/libc/none.in b/config/libc/none.in index d587faf..b8860b0 100644 --- a/config/libc/none.in +++ b/config/libc/none.in @@ -4,10 +4,10 @@ ## ## help Do not use a C library. ## help -## help This is usefull if your project is self-contained, does not rely on +## help This is useful if your project is self-contained, does not rely on ## help an external C library, and provides all the necessary bits. ## help -## help Most probably usefull to bootloaders, as they generally don't depend +## help Most probably useful to bootloaders, as they generally don't depend ## help on the C library. ## help ## help If unsure: do *not* choose that, and use another option in the choice. -- cgit v0.10.2-6-g49f6 From 28c24f5034768c7f01ef2987d3e72dfdf7c438db Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Fri, 1 Apr 2016 18:24:27 -0700 Subject: uClibc.sh: typo, local -> locale. Signed-off-by: Alexey Neyman diff --git a/scripts/build/libc/uClibc.sh b/scripts/build/libc/uClibc.sh index 7903a76..41b651f 100644 --- a/scripts/build/libc/uClibc.sh +++ b/scripts/build/libc/uClibc.sh @@ -5,7 +5,7 @@ # This is a constant because it does not change very often. # We're in 2010, and are still using data from 7 years ago. uclibc_locales_version=030818 -uclibc_local_tarball="uClibc-locale-${uclibc_locales_version}" +uclibc_locale_tarball="uClibc-locale-${uclibc_locales_version}" if [ "${CT_LIBC_UCLIBC_NG}" = "y" ]; then uclibc_name="uClibc-ng" @@ -26,7 +26,7 @@ do_libc_get() { fi # uClibc locales if [ "${CT_LIBC_UCLIBC_LOCALES_PREGEN_DATA}" = "y" ]; then - CT_GetFile "${uclibc_local_tarball}" ${libc_src} + CT_GetFile "${uclibc_locale_tarball}" ${libc_src} fi return 0 @@ -41,11 +41,11 @@ do_libc_extract() { # Extracting pregen locales ourselves is kinda # broken, so just link it in place... if [ "${CT_LIBC_UCLIBC_LOCALES_PREGEN_DATA}" = "y" \ - -a ! -f "${CT_SRC_DIR}/.${uclibc_local_tarball}.extracted" ]; then + -a ! -f "${CT_SRC_DIR}/.${uclibc_locale_tarball}.extracted" ]; then CT_Pushd "${CT_SRC_DIR}/${uclibc_name}-${CT_LIBC_VERSION}/extra/locale" - CT_DoExecLog ALL ln -s "${CT_TARBALLS_DIR}/${uclibc_local_tarball}.tgz" . + CT_DoExecLog ALL ln -s "${CT_TARBALLS_DIR}/${uclibc_locale_tarball}.tgz" . CT_Popd - touch "${CT_SRC_DIR}/.${uclibc_local_tarball}.extracted" + touch "${CT_SRC_DIR}/.${uclibc_locale_tarball}.extracted" fi return 0 @@ -99,7 +99,7 @@ do_libc_start_files() { ${make} CROSS_COMPILE="${CT_TARGET}-" \ UCLIBC_EXTRA_CFLAGS="-pipe" \ PREFIX="${multi_root}/" \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ + LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ oldconfig CT_DoLog EXTRA "Building headers" @@ -108,7 +108,7 @@ do_libc_start_files() { CROSS_COMPILE="${CT_TARGET}-" \ UCLIBC_EXTRA_CFLAGS="-pipe" \ PREFIX="${multi_root}/" \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ + LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ headers CT_DoLog EXTRA "Installing headers" @@ -117,7 +117,7 @@ do_libc_start_files() { CROSS_COMPILE="${CT_TARGET}-" \ UCLIBC_EXTRA_CFLAGS="-pipe" \ PREFIX="${multi_root}/" \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ + LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ install_headers # The check might look bogus, but it is the same condition as is used @@ -131,7 +131,7 @@ do_libc_start_files() { PREFIX="${multi_root}/" \ STRIPTOOL=true \ ${CT_LIBC_UCLIBC_VERBOSITY} \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ + LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ lib/crt1.o lib/crti.o lib/crtn.o # From: http://git.openembedded.org/cgit.cgi/openembedded/commit/?id=ad5668a7ac7e0436db92e55caaf3fdf782b6ba3b @@ -197,7 +197,7 @@ do_libc() { ${make} CROSS_COMPILE=${CT_TARGET}- \ UCLIBC_EXTRA_CFLAGS="-pipe" \ PREFIX="${multi_root}/" \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ + LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ oldconfig # We do _not_ want to strip anything for now, in case we specifically @@ -211,7 +211,7 @@ do_libc() { PREFIX="${multi_root}/" \ STRIPTOOL=true \ ${CT_LIBC_UCLIBC_VERBOSITY} \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ + LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ pregen CT_DoExecLog ALL \ ${make} ${CT_LIBC_UCLIBC_PARALLEL:+${JOBSFLAGS}} \ @@ -220,7 +220,7 @@ do_libc() { PREFIX="${multi_root}/" \ STRIPTOOL=true \ ${CT_LIBC_UCLIBC_VERBOSITY} \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ + LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ all # YEM-FIXME: @@ -244,7 +244,7 @@ do_libc() { PREFIX="${multi_root}/" \ STRIPTOOL=true \ ${CT_LIBC_UCLIBC_VERBOSITY} \ - LOCALE_DATA_FILENAME="${uclibc_local_tarball}.tgz" \ + LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ MULTILIB_DIR="${multilib_dir}" \ install -- cgit v0.10.2-6-g49f6 From 4ee22d66a849123c06812736dd1472840aad5823 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Fri, 1 Apr 2016 23:28:43 -0700 Subject: uclibc: merge startfiles/final into single backend. In preparation for multilib support, use the same "backend" model that is already employed by glibc and musl. Also, the verbosity setting descriptions were swapped. V=2 is actually less verbose than V=1: V=1 prints full commands, while V=2 prints 'CC '. Signed-off-by: Alexey Neyman diff --git a/config/libc/uClibc.in b/config/libc/uClibc.in index 989da7b..a99ff73 100644 --- a/config/libc/uClibc.in +++ b/config/libc/uClibc.in @@ -129,13 +129,13 @@ config LIBC_UCLIBC_VERBOSITY_0 config LIBC_UCLIBC_VERBOSITY_1 bool - prompt "Brief build (show defines, ld flags)" + prompt "Very verbose build" help Print simplified command lines. config LIBC_UCLIBC_VERBOSITY_2 bool - prompt "Very verbose build" + prompt "Brief build (show defines, ld flags)" help Print full command lines. diff --git a/scripts/build/libc/uClibc.sh b/scripts/build/libc/uClibc.sh index 41b651f..edd82f6 100644 --- a/scripts/build/libc/uClibc.sh +++ b/scripts/build/libc/uClibc.sh @@ -73,180 +73,129 @@ do_libc_check_config() { # Build and install headers and start files do_libc_start_files() { - 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 -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 - - 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="${CT_TARGET}-" \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${multi_root}/" \ - LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ - oldconfig - - CT_DoLog EXTRA "Building headers" - CT_DoExecLog ALL \ - ${make} ${CT_LIBC_UCLIBC_VERBOSITY} \ - CROSS_COMPILE="${CT_TARGET}-" \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${multi_root}/" \ - LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ - headers - - CT_DoLog EXTRA "Installing headers" - CT_DoExecLog ALL \ - ${make} ${CT_LIBC_UCLIBC_VERBOSITY} \ - CROSS_COMPILE="${CT_TARGET}-" \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${multi_root}/" \ - LOCALE_DATA_FILENAME="${uclibc_locale_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="${CT_TARGET}-" \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${multi_root}/" \ - STRIPTOOL=true \ - ${CT_LIBC_UCLIBC_VERBOSITY} \ - LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ - lib/crt1.o lib/crti.o lib/crtn.o - - # From: http://git.openembedded.org/cgit.cgi/openembedded/commit/?id=ad5668a7ac7e0436db92e55caaf3fdf782b6ba3b - # 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 "${CT_TARGET}-gcc" -nostdlib \ - -nostartfiles \ - -shared \ - -x c /dev/null \ - -o libdummy.so - - CT_DoLog EXTRA "Installing start files" - CT_DoExecLog ALL ${install} -m 0644 lib/crt1.o lib/crti.o lib/crtn.o \ - "${startfiles_dir}" - - CT_DoLog EXTRA "Installing dummy shared libs" - 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 + # Start files and Headers should be configured the same way as the + # final libc, but built and installed differently. + do_libc_backend libc_mode=startfiles } -# This function build and install the full uClibc +# This function builds and install the full C library do_libc() { + do_libc_backend libc_mode=final +} + +# Common backend for 1st and 2nd passes +do_libc_backend() { + local libc_mode local multi_os_dir multi_root multilib_dir startfiles_dir + local jflag=${CT_LIBC_UCLIBC_PARALLEL:+${JOBSFLAGS}} + local -a make_args - CT_DoStep INFO "Installing C library" + for arg in "$@"; do + eval "${arg// /\\ }" + done + + case "${libc_mode}" in + startfiles) CT_DoStep INFO "Installing C library headers & start files";; + final) CT_DoStep INFO "Installing C library";; + *) CT_Abort "Unsupported (or unset) libc_mode='${libc_mode}'";; + esac # 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_BUILD_DIR}/build-libc" - cd "${CT_BUILD_DIR}/build-libc" - - # Retrieve the config file - CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config + CT_DoExecLog ALL cp -a "${CT_SRC_DIR}/${uclibc_name}-${CT_LIBC_VERSION}" \ + "${CT_BUILD_DIR}/build-libc-${libc_mode}" + cd "${CT_BUILD_DIR}/build-libc-${libc_mode}" 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}" + multilib_dir="lib/${multi_os_dir}" + startfiles_dir="${multi_root}/usr/${multilib_dir}" + CT_SanitizeVarDir multilib_dir startfiles_dir + + # Construct make arguments: + # - uClibc uses the CROSS environment variable as a prefix to the compiler + # tools to use. Since it requires core pass-1, thusly named compiler is + # already available. + # - Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak, + # depending on the configuration of the library. That is, they are tailored + # to best fit the target. So it is useless and seems to be a bad thing to + # use LIBC_EXTRA_CFLAGS here. + # - We do _not_ want to strip anything for now, in case we specifically + # asked for a debug toolchain, thus the STRIPTOOL= assignment. + make_args=( CROSS_COMPILE="${CT_TARGET}-" \ + UCLIBC_EXTRA_CFLAGS="-pipe" \ + PREFIX="${multi_root}/" \ + MULTILIB_DIR="${multilib_dir}" \ + LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ + STRIPTOOL=true \ + ${CT_LIBC_UCLIBC_VERBOSITY} \ + ) - 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" + # Retrieve the config file + CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/uClibc.config" .config - 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. - # Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak, - # depending on the configuration of the library. That is, they are tailored - # to best fit the target. So it is useless and seems to be a bad thing to - # use LIBC_EXTRA_CFLAGS here. + # 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 CFG \ - ${make} CROSS_COMPILE=${CT_TARGET}- \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${multi_root}/" \ - LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ - oldconfig - - # We do _not_ want to strip anything for now, in case we specifically - # asked for a debug toolchain, thus the STRIPTOOL= assignment - # /Old/ versions can not build in // - CT_DoLog EXTRA "Building C library" - CT_DoExecLog ALL \ - ${make} -j1 \ - CROSS_COMPILE=${CT_TARGET}- \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${multi_root}/" \ - STRIPTOOL=true \ - ${CT_LIBC_UCLIBC_VERBOSITY} \ - LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ - pregen - CT_DoExecLog ALL \ - ${make} ${CT_LIBC_UCLIBC_PARALLEL:+${JOBSFLAGS}} \ - CROSS_COMPILE=${CT_TARGET}- \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${multi_root}/" \ - STRIPTOOL=true \ - ${CT_LIBC_UCLIBC_VERBOSITY} \ - LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ - all - - # YEM-FIXME: - # - we want to install 'runtime' files, eg. lib*.{a,so*}, crti.o and - # such files, except the headers as they already are installed - # - "make install_dev" installs the headers, the crti.o... and the - # static libs, but not the dynamic libs - # - "make install_runtime" installs the dynamic libs only - # - "make install" calls install_runtime and install_dev - # - so we're left with re-installing the headers... Sigh... - # - # 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 useful for installation. - # - CT_DoLog EXTRA "Installing C library" - CT_DoExecLog ALL \ - ${make} CROSS_COMPILE=${CT_TARGET}- \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ - PREFIX="${multi_root}/" \ - STRIPTOOL=true \ - ${CT_LIBC_UCLIBC_VERBOSITY} \ - LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ - MULTILIB_DIR="${multilib_dir}" \ - install + CT_DoYes | CT_DoExecLog ALL ${make} "${make_args[@]}" oldconfig + + if [ "${libc_mode}" = "startfiles" ]; then + CT_DoLog EXTRA "Building headers" + CT_DoExecLog ALL ${make} "${make_args[@]}" headers + + # Ensure the directory for installing multilib-specific binaries exists. + CT_DoExecLog ALL mkdir -p "${startfiles_dir}" + + CT_DoLog EXTRA "Installing headers" + CT_DoExecLog ALL ${make} "${make_args[@]}" 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} ${jflag} "${make_args[@]}" \ + lib/crt1.o lib/crti.o lib/crtn.o + + # From: http://git.openembedded.org/cgit.cgi/openembedded/commit/?id=ad5668a7ac7e0436db92e55caaf3fdf782b6ba3b + # 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 "${CT_TARGET}-gcc" -nostdlib -nostartfiles \ + -shared -x c /dev/null -o libdummy.so + + CT_DoLog EXTRA "Installing start files" + CT_DoExecLog ALL ${install} -m 0644 lib/crt1.o lib/crti.o lib/crtn.o \ + "${startfiles_dir}" + + CT_DoLog EXTRA "Installing dummy shared libs" + 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 + fi # libc_mode == startfiles + + if [ "${libc_mode}" = "final" ]; then + 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" + + CT_DoLog EXTRA "Building C library" + CT_DoExecLog ALL ${make} "${make_args[@]}" pregen + CT_DoExecLog ALL ${make} ${jflag} "${make_args[@]}" all + + # YEM-FIXME: + # - we want to install 'runtime' files, eg. lib*.{a,so*}, crti.o and + # such files, except the headers as they already are installed + # - "make install_dev" installs the headers, the crti.o... and the + # static libs, but not the dynamic libs + # - "make install_runtime" installs the dynamic libs only + # - "make install" calls install_runtime and install_dev + # - so we're left with re-installing the headers... Sigh... + CT_DoLog EXTRA "Installing C library" + CT_DoExecLog ALL ${make} "${make_args[@]}" install + fi # libc_mode == final CT_EndStep } -- cgit v0.10.2-6-g49f6 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 diff --git a/scripts/build/arch.sh b/scripts/build/arch.sh new file mode 100644 index 0000000..48da2d6 --- /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 ffceae3..cf6d40d 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 338392c..5f6ce2f 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 a6eb010..052e4a7 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 93ecc9a..456a6e3 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 68ad4fa..4d732be 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 8c7d445..24c556b 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 77bbc8a..964dd25 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 e7f4f1a..7780e40 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 2d3baa3..189cebe 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 ca0f08b..0e41d67 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 b73f990..3dc91a4 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 dcd9e15..a08ed97 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 964a11d..44ca008 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 e0e9c63..e31d110 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 e70b669..d9bda06 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 d4bf7dc..8537a8e 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 edd82f6..c59d5fa 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 b49c68e..01fe07c 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 2331557..49b0686 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 b7e3b02..15b9a01 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 v0.10.2-6-g49f6 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 diff --git a/scripts/build/arch.sh b/scripts/build/arch.sh index 48da2d6..2199a17 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 964dd25..8015724 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 e303420..dff86a0 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 189cebe..15213a6 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 0e41d67..5147678 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 a08ed97..dc9443c 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 49b0686..ef75e09 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 v0.10.2-6-g49f6 From bf3eceb5d9b27fc65c819abe0b7f3cec704917e7 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Mon, 4 Apr 2016 08:25:07 -0700 Subject: uClibc: Split configuration tweaker into per-arch functions. Signed-off-by: Alexey Neyman diff --git a/scripts/build/arch.sh b/scripts/build/arch.sh index 2199a17..6414b54 100644 --- a/scripts/build/arch.sh +++ b/scripts/build/arch.sh @@ -17,5 +17,23 @@ CT_DoArchGlibcAdjustTuple() { :; } +# Helper for uClibc configurators: select the architecture +# Usage: CT_DoArchUClibcSelectArch +CT_DoArchUClibcSelectArch() { + local cfg="${1}" + local arch="${2}" + + ${sed} -i -r -e '/^TARGET_.*/d' "${cfg}" + CT_KconfigEnableOption "TARGET_${arch}" "${cfg}" + CT_KconfigSetOption "TARGET_ARCH" "${arch}" "${cfg}" +} + +# uClibc: Adjust configuration file according to the CT-NG configuration +# Usage CT_DoArchUClibcConfig +CT_DoArchUClibcConfig() { + CT_DoLog WARN "Support for '${CT_ARCH}' is not implemented in uClibc config tweaker." + CT_DoLog WARN "Exact configuration file must be provided." +} + # Override from the actual arch implementation as needed. . "${CT_LIB_DIR}/scripts/build/arch/${CT_ARCH}.sh" diff --git a/scripts/build/arch/arm.sh b/scripts/build/arch/arm.sh index 5f6ce2f..8af0072 100644 --- a/scripts/build/arch/arm.sh +++ b/scripts/build/arch/arm.sh @@ -39,3 +39,22 @@ CT_DoArchTupleValues() { CT_TARGET_SYS="${CT_TARGET_SYS}hf" fi } + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "arm" + + # FIXME: CONFIG_ARM_OABI does not exist in neither uClibc/uClibc-ng + # FIXME: CONFIG_ARM_EABI does not seem to affect anything in either of them, too + # (both check the compiler's built-in define, __ARM_EABI__ instead) except for + # a check for match between toolchain configuration and uClibc-ng in + # uClibc_arch_features.h + if [ "${CT_ARCH_ARM_EABI}" = "y" ]; then + CT_KconfigDisableOption "CONFIG_ARM_OABI" "${cfg}" + CT_KconfigEnableOption "CONFIG_ARM_EABI" "${cfg}" + else + CT_KconfigDisableOption "CONFIG_ARM_EABI" "${cfg}" + CT_KconfigEnableOption "CONFIG_ARM_OABI" "${cfg}" + fi +} diff --git a/scripts/build/arch/m68k.sh b/scripts/build/arch/m68k.sh index 052e4a7..3cba76c 100644 --- a/scripts/build/arch/m68k.sh +++ b/scripts/build/arch/m68k.sh @@ -1 +1,7 @@ # Compute M68k-specific values + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "m68k" +} diff --git a/scripts/build/arch/microblaze.sh b/scripts/build/arch/microblaze.sh index 456a6e3..e9d9811 100644 --- a/scripts/build/arch/microblaze.sh +++ b/scripts/build/arch/microblaze.sh @@ -19,3 +19,9 @@ CT_DoArchTupleValues () { esac } + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "microblaze" +} diff --git a/scripts/build/arch/mips.sh b/scripts/build/arch/mips.sh index 4d732be..030e77b 100644 --- a/scripts/build/arch/mips.sh +++ b/scripts/build/arch/mips.sh @@ -14,3 +14,36 @@ CT_DoArchTupleValues() { CT_ARCH_ABI_CFLAG="-mabi=${CT_ARCH_mips_ABI}" CT_ARCH_WITH_ABI="--with-abi=${CT_ARCH_mips_ABI}" } + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "${CT_ARCH}" + + CT_KconfigDisableOption "CONFIG_MIPS_O32_ABI" "${cfg}" + CT_KconfigDisableOption "CONFIG_MIPS_N32_ABI" "${cfg}" + CT_KconfigDisableOption "CONFIG_MIPS_N64_ABI" "${cfg}" + case "${CT_ARCH_mips_ABI}" in + 32) + CT_KconfigEnableOption "CONFIG_MIPS_O32_ABI" "${cfg}" + ;; + n32) + CT_KconfigEnableOption "CONFIG_MIPS_N32_ABI" "${cfg}" + ;; + 64) + CT_KconfigEnableOption "CONFIG_MIPS_N64_ABI" "${cfg}" + ;; + esac + + # FIXME: uClibc (!ng) allows to select ISA in the config; should + # match from the selected ARCH_ARCH level... For now, delete and + # fall back to default. + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_1" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_2" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_3" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_4" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS32" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS32R2" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS64" "${cfg}" + CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS64R2" "${cfg}" +} diff --git a/scripts/build/arch/powerpc.sh b/scripts/build/arch/powerpc.sh index 8015724..52f3f8b 100644 --- a/scripts/build/arch/powerpc.sh +++ b/scripts/build/arch/powerpc.sh @@ -71,3 +71,20 @@ CT_DoArchMultilibTarget () # Set the target variable eval ${target_var}=\"${target_}\" } + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "powerpc" + + CT_KconfigDisableOption "CONFIG_E500" "${cfg}" + CT_KconfigDisableOption "CONFIG_CLASSIC" "${cfg}" + CT_KconfigDeleteOption "TARGET_SUBARCH" "${cfg}" + if [ "${CT_ARCH_powerpc_ABI}" = "spe" ]; then + CT_KconfigEnableOption "CONFIG_E500" "${cfg}" + CT_KconfigSetOption "TARGET_SUBARCH" "e500" "${cfg}" + else + CT_KconfigEnableOption "CONFIG_CLASSIC" "${cfg}" + CT_KconfigSetOption "TARGET_SUBARCH" "classic" "${cfg}" + fi +} diff --git a/scripts/build/arch/sh.sh b/scripts/build/arch/sh.sh index 7780e40..101e4ce 100644 --- a/scripts/build/arch/sh.sh +++ b/scripts/build/arch/sh.sh @@ -35,3 +35,18 @@ CT_DoArchTupleValues () { esac CT_ARCH_FLOAT_CFLAG= } + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + # FIXME: uclibc (!ng) seems to support sh64 (sh5), too + CT_DoArchUClibcSelectArch "${cfg}" "sh" + CT_KconfigDisableOption "CONFIG_SH3" "${cfg}" + CT_KconfigDisableOption "CONFIG_SH4" "${cfg}" + CT_KconfigDisableOption "CONFIG_SH4A" "${cfg}" + case "${CT_ARCH_SH_VARIAN}" in + sh3) CT_KconfigEnableOption "CONFIG_SH3" "${cfg}";; + sh4) CT_KconfigEnableOption "CONFIG_SH4" "${cfg}";; + sh4a) CT_KconfigEnableOption "CONFIG_SH4A" "${cfg}";; + esac +} diff --git a/scripts/build/arch/sparc.sh b/scripts/build/arch/sparc.sh index 15213a6..74f6f78 100644 --- a/scripts/build/arch/sparc.sh +++ b/scripts/build/arch/sparc.sh @@ -70,3 +70,10 @@ CT_DoArchGlibcAdjustTuple() { # Set the target variable eval ${target_var}=\"${target_}\" } + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "${CT_ARCH}" + # FIXME: select CONFIG_SPARC_V7/V8/V9/V9B according to the CPU selector +} diff --git a/scripts/build/arch/x86.sh b/scripts/build/arch/x86.sh index 5147678..4193278 100644 --- a/scripts/build/arch/x86.sh +++ b/scripts/build/arch/x86.sh @@ -100,3 +100,33 @@ CT_DoArchGlibcAdjustTuple() { # Set the target variable eval ${target_var}=\"${target_}\" } + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + if [ "${CT_ARCH_BITNESS}" = 64 ]; then + CT_DoArchUClibcSelectArch "${cfg}" "x86_64" + else + CT_DoArchUClibcSelectArch "${cfg}" "i386" + fi + + # FIXME This doesn't cover all cases of x86_32 on uClibc (!ng) + CT_KconfigDisableOption "CONFIG_386" "${cfg}" + CT_KconfigDisableOption "CONFIG_486" "${cfg}" + CT_KconfigDisableOption "CONFIG_586" "${cfg}" + CT_KconfigDisableOption "CONFIG_686" "${cfg}" + case ${CT_TARGET_ARCH} in + i386) + CT_KconfigEnableOption "CONFIG_386" "${cfg}" + ;; + i486) + CT_KconfigEnableOption "CONFIG_486" "${cfg}" + ;; + i586) + CT_KconfigEnableOption "CONFIG_586" "${cfg}" + ;; + i686) + CT_KconfigEnableOption "CONFIG_686" "${cfg}" + ;; + esac +} diff --git a/scripts/build/arch/xtensa.sh b/scripts/build/arch/xtensa.sh index c7bd432..a3010c6 100644 --- a/scripts/build/arch/xtensa.sh +++ b/scripts/build/arch/xtensa.sh @@ -70,3 +70,9 @@ CT_ConfigureXtensa() { CT_Popd } + +CT_DoArchUClibcConfig() { + local cfg="${1}" + + CT_DoArchUClibcSelectArch "${cfg}" "xtensa" +} diff --git a/scripts/build/libc/uClibc.sh b/scripts/build/libc/uClibc.sh index c59d5fa..1e2a290 100644 --- a/scripts/build/libc/uClibc.sh +++ b/scripts/build/libc/uClibc.sh @@ -193,96 +193,8 @@ manage_uClibc_config() { dst="$2" # Start with fresh files - CT_DoExecLog ALL rm -f "${dst}" - CT_DoExecLog ALL mkdir -p "$(dirname ${dst})" CT_DoExecLog ALL cp "${src}" "${dst}" - # Hack our target in the config file. - case "${CT_ARCH}:${CT_ARCH_BITNESS}" in - x86:32) arch=i386;; - x86:64) arch=x86_64;; - sh:32) arch="sh";; - *) arch="${CT_ARCH}";; - esac - # Also remove stripping: its the responsibility of the - # firmware builder to strip or not. - ${sed} -i -r -e '/^TARGET_.*/d' "${dst}" - CT_KconfigEnableOption "TARGET_${arch}" "${dst}" - CT_KconfigSetOption "TARGET_ARCH" "${arch}" "${dst}" - CT_KconfigDisableOption "DOSTRIP" "${dst}" - - # Ah. We may one day need architecture-specific handler here... - case "${arch}" in - arm*) - if [ "${CT_ARCH_ARM_EABI}" = "y" ]; then - CT_KconfigDisableOption "CONFIG_ARM_OABI" "${dst}" - CT_KconfigEnableOption "CONFIG_ARM_EABI" "${dst}" - else - CT_KconfigDisableOption "CONFIG_ARM_EABI" "${dst}" - CT_KconfigEnableOption "CONFIG_ARM_OABI" "${dst}" - fi - ;; - i386) - # FIXME This doesn't cover all cases of x86_32... - case ${CT_TARGET_ARCH} in - i386) - CT_KconfigEnableOption "CONFIG_386" "${dst}" - ;; - i486) - CT_KconfigEnableOption "CONFIG_486" "${dst}" - ;; - i586) - CT_KconfigEnableOption "CONFIG_586" "${dst}" - ;; - i686) - CT_KconfigEnableOption "CONFIG_686" "${dst}" - ;; - esac - ;; - mips*) - CT_KconfigDisableOption "CONFIG_MIPS_O32_ABI" "${dst}" - CT_KconfigDisableOption "CONFIG_MIPS_N32_ABI" "${dst}" - CT_KconfigDisableOption "CONFIG_MIPS_N64_ABI" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_1" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_2" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_3" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_4" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS32" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS32R2" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS64" "${dst}" - CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS64R2" "${dst}" - case "${CT_ARCH_mips_ABI}" in - 32) - CT_KconfigEnableOption "CONFIG_MIPS_O32_ABI" "${dst}" - ;; - n32) - CT_KconfigEnableOption "CONFIG_MIPS_N32_ABI" "${dst}" - ;; - 64) - CT_KconfigEnableOption "CONFIG_MIPS_N64_ABI" "${dst}" - ;; - esac - ;; - powerpc*) - CT_KconfigDisableOption "CONFIG_E500" "${dst}" - CT_KconfigDisableOption "CONFIG_CLASSIC" "${dst}" - CT_KconfigDeleteOption "TARGET_SUBARCH" "${dst}" - if [ "${CT_ARCH_powerpc_ABI}" = "spe" ]; then - CT_KconfigEnableOption "CONFIG_E500" "${dst}" - CT_KconfigSetOption "TARGET_SUBARCH" "e500" "${dst}" - else - CT_KconfigEnableOption "CONFIG_CLASSIC" "${dst}" - CT_KconfigSetOption "TARGET_SUBARCH" "classic" "${dst}" - fi - ;; - sh) - # all we really support right now is sh4:32 - CT_KconfigEnableOption "CONFIG_SH4" "${dst}" - ;; - esac - - # Accomodate for old and new uClibc versions, where the - # way to select between big/little endian has changed case "${CT_ARCH_ENDIAN}" in big) CT_KconfigDisableOption "ARCH_LITTLE_ENDIAN" "${dst}" @@ -298,8 +210,6 @@ manage_uClibc_config() { ;; esac - # Accomodate for old and new uClibc versions, where the - # MMU settings has different config knobs if [ "${CT_ARCH_USE_MMU}" = "y" ]; then CT_KconfigEnableOption "ARCH_USE_MMU" "${dst}" else @@ -392,29 +302,23 @@ manage_uClibc_config() { fi # Push the threading model + CT_KconfigDisableOption "UCLIBC_HAS_THREADS" "${dst}" + CT_KconfigDisableOption "LINUXTHREADS_OLD" "${dst}" + CT_KconfigDisableOption "LINUXTHREADS_NEW" "${dst}" + CT_KconfigDisableOption "UCLIBC_HAS_THREADS_NATIVE" "${dst}" case "${CT_THREADS}:${CT_LIBC_UCLIBC_LNXTHRD}" in none:) - CT_KconfigDisableOption "UCLIBC_HAS_THREADS" "${dst}" - CT_KconfigDisableOption "LINUXTHREADS_OLD" "${dst}" - CT_KconfigDisableOption "LINUXTHREADS_NEW" "${dst}" - CT_KconfigDisableOption "UCLIBC_HAS_THREADS_NATIVE" "${dst}" ;; linuxthreads:old) CT_KconfigEnableOption "UCLIBC_HAS_THREADS" "${dst}" CT_KconfigEnableOption "LINUXTHREADS_OLD" "${dst}" - CT_KconfigDisableOption "LINUXTHREADS_NEW" "${dst}" - CT_KconfigDisableOption "UCLIBC_HAS_THREADS_NATIVE" "${dst}" ;; linuxthreads:new) CT_KconfigEnableOption "UCLIBC_HAS_THREADS" "${dst}" - CT_KconfigDisableOption "LINUXTHREADS_OLD" "${dst}" CT_KconfigEnableOption "LINUXTHREADS_NEW" "${dst}" - CT_KconfigDisableOption "UCLIBC_HAS_THREADS_NATIVE" "${dst}" ;; nptl:) CT_KconfigEnableOption "UCLIBC_HAS_THREADS" "${dst}" - CT_KconfigDisableOption "LINUXTHREADS_OLD" "${dst}" - CT_KconfigDisableOption "LINUXTHREADS_NEW" "${dst}" CT_KconfigEnableOption "UCLIBC_HAS_THREADS_NATIVE" "${dst}" ;; *) @@ -426,29 +330,22 @@ manage_uClibc_config() { CT_KconfigEnableOption "PTHREADS_DEBUG_SUPPORT" "${dst}" # Force on debug options if asked for + CT_KconfigDisableOption "DODEBUG" "${dst}" + CT_KconfigDisableOption "DODEBUG_PT" "${dst}" + CT_KconfigDisableOption "DOASSERTS" "${dst}" + CT_KconfigDisableOption "SUPPORT_LD_DEBUG" "${dst}" + CT_KconfigDisableOption "SUPPORT_LD_DEBUG_EARLY" "${dst}" + CT_KconfigDisableOption "UCLIBC_MALLOC_DEBUGGING" "${dst}" case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in 0) - CT_KconfigDisableOption "DODEBUG" "${dst}" - CT_KconfigDisableOption "DODEBUG_PT" "${dst}" - CT_KconfigDisableOption "DOASSERTS" "${dst}" - CT_KconfigDisableOption "SUPPORT_LD_DEBUG" "${dst}" - CT_KconfigDisableOption "SUPPORT_LD_DEBUG_EARLY" "${dst}" - CT_KconfigDisableOption "UCLIBC_MALLOC_DEBUGGING" "${dst}" ;; 1) CT_KconfigEnableOption "DODEBUG" "${dst}" - CT_KconfigDisableOption "DODEBUG_PT" "${dst}" - CT_KconfigDisableOption "DOASSERTS" "${dst}" - CT_KconfigDisableOption "SUPPORT_LD_DEBUG" "${dst}" - CT_KconfigDisableOption "SUPPORT_LD_DEBUG_EARLY" "${dst}" - CT_KconfigDisableOption "UCLIBC_MALLOC_DEBUGGING" "${dst}" ;; 2) CT_KconfigEnableOption "DODEBUG" "${dst}" - CT_KconfigDisableOption "DODEBUG_PT" "${dst}" CT_KconfigEnableOption "DOASSERTS" "${dst}" CT_KconfigEnableOption "SUPPORT_LD_DEBUG" "${dst}" - CT_KconfigDisableOption "SUPPORT_LD_DEBUG_EARLY" "${dst}" CT_KconfigEnableOption "UCLIBC_MALLOC_DEBUGGING" "${dst}" ;; 3) @@ -460,6 +357,13 @@ manage_uClibc_config() { CT_KconfigEnableOption "UCLIBC_MALLOC_DEBUGGING" "${dst}" ;; esac + + # Remove stripping: its the responsibility of the + # firmware builder to strip or not. + CT_KconfigDisableOption "DOSTRIP" "${dst}" + + # Now allow architecture to tweak as it wants + CT_DoArchUClibcConfig "${dst}" } do_libc_post_cc() { -- cgit v0.10.2-6-g49f6 From f2ffdf798ddcd5b471a5055c18215ca2988ddf29 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Tue, 5 Apr 2016 14:47:20 -0700 Subject: First stab at multilib/uClibc. Create a separate 'libc_backend_once', install headers into a subdirectory (different sets of headers are installed for 32- and 64-bit architectures), and create a symlink for the dynamic linker location expected by GCC. Signed-off-by: Alexey Neyman diff --git a/scripts/build/arch.sh b/scripts/build/arch.sh index 6414b54..b75c1be 100644 --- a/scripts/build/arch.sh +++ b/scripts/build/arch.sh @@ -29,11 +29,33 @@ CT_DoArchUClibcSelectArch() { } # uClibc: Adjust configuration file according to the CT-NG configuration -# Usage CT_DoArchUClibcConfig +# Usage: CT_DoArchUClibcConfig CT_DoArchUClibcConfig() { CT_DoLog WARN "Support for '${CT_ARCH}' is not implemented in uClibc config tweaker." CT_DoLog WARN "Exact configuration file must be provided." } +# Multilib/uClibc: Adjust configuration file for given CFLAGS +# Usage: CT_DoArchUClibcCflags +CT_DoArchUClibcCflags() { + local cfg="${1}" + local cflags="${2}" + + # Likely, any non-default cflags need to be reflected into the config. + # It may work if we just pass them into EXTRA_CFLAGS, but we have no + # idea as they might interact with the CFLAGS inferred by uClibc from + # the configuration file. + if [ "${cflags}" != "" ]; then + CT_DoLog WARN "Multilib configuration not supported for uClibc/${CT_ARCH}" + fi +} + +# Multilib/uClibc: Adjust header installation path for given CFLAGS +# Usage: CT_DoArchUClibcHeaderDir +CT_DoArchUClibcHeaderDir() { + # Only needed if a given architecture may select different uClibc architectures. + :; +} + # Override from the actual arch implementation as needed. . "${CT_LIB_DIR}/scripts/build/arch/${CT_ARCH}.sh" diff --git a/scripts/build/arch/arm.sh b/scripts/build/arch/arm.sh index 8af0072..b728311 100644 --- a/scripts/build/arch/arm.sh +++ b/scripts/build/arch/arm.sh @@ -27,7 +27,6 @@ CT_DoArchTupleValues() { thumb) CT_ARCH_CC_CORE_EXTRA_CONFIG="--with-mode=thumb" CT_ARCH_CC_EXTRA_CONFIG="--with-mode=thumb" -# CT_ARCH_TARGET_CFLAGS="-mthumb" ;; esac @@ -38,6 +37,23 @@ CT_DoArchTupleValues() { if [ "${CT_ARCH_ARM_TUPLE_USE_EABIHF}" = "y" ]; then CT_TARGET_SYS="${CT_TARGET_SYS}hf" fi + + # If building multilib, zero out any WITH_*/*_CFLAG - GCC on ARM does not allow + # any of them with multilib. + if [ "${CT_MULTILIB}" = "y" ]; then + CT_ARCH_WITH_ARCH= + CT_ARCH_WITH_ABI= + CT_ARCH_WITH_CPU= + CT_ARCH_WITH_TUNE= + CT_ARCH_WITH_FPU= + CT_ARCH_WITH_FLOAT= + CT_ARCH_ARCH_CFLAG= + CT_ARCH_ABI_CFLAG= + CT_ARCH_CPU_CFLAG= + CT_ARCH_TUNE_CFLAG= + CT_ARCH_FPU_CFLAG= + CT_ARCH_FLOAT_CFLAG= + fi } CT_DoArchUClibcConfig() { @@ -45,6 +61,15 @@ CT_DoArchUClibcConfig() { CT_DoArchUClibcSelectArch "${cfg}" "arm" + case "${CT_ARCH_ARM_MODE}" in + arm) + CT_KconfigDisableOption "COMPILE_IN_THUMB_MODE" "${cfg}" + ;; + thumb) + CT_KconfigEnableOption "COMPILE_IN_THUMB_MODE" "${cfg}" + ;; + esac + # FIXME: CONFIG_ARM_OABI does not exist in neither uClibc/uClibc-ng # FIXME: CONFIG_ARM_EABI does not seem to affect anything in either of them, too # (both check the compiler's built-in define, __ARM_EABI__ instead) except for @@ -58,3 +83,38 @@ CT_DoArchUClibcConfig() { CT_KconfigEnableOption "CONFIG_ARM_OABI" "${cfg}" fi } + +CT_DoArchUClibcCflags() { + local cfg="${1}" + local cflags="${2}" + local f + + for f in ${cflags}; do + case "${f}" in + -mthumb) + CT_KconfigEnableOption "COMPILE_IN_THUMB_MODE" "${cfg}" + ;; + -marm) + CT_KconfigDisableOption "COMPILE_IN_THUMB_MODE" "${cfg}" + ;; + -mlittle-endian) + CT_KconfigDisableOption "ARCH_BIG_ENDIAN" "${cfg}" + CT_KconfigDisableOption "ARCH_WANTS_BIG_ENDIAN" "${cfg}" + CT_KconfigEnableOption "ARCH_LITTLE_ENDIAN" "${cfg}" + CT_KconfigEnableOption "ARCH_WANTS_LITTLE_ENDIAN" "${cfg}" + ;; + -mbig-endian) + CT_KconfigEnableOption "ARCH_BIG_ENDIAN" "${cfg}" + CT_KconfigEnableOption "ARCH_WANTS_BIG_ENDIAN" "${cfg}" + CT_KconfigDisableOption "ARCH_LITTLE_ENDIAN" "${cfg}" + CT_KconfigDisableOption "ARCH_WANTS_LITTLE_ENDIAN" "${cfg}" + ;; + -mhard-float|-mfloat-abi=hard|-mfloat-abi=softfp) + CT_KconfigEnableOption "UCLIBC_HAS_FPU" "${cfg}" + ;; + -msoft-float|-mfloat-abi=soft) + CT_KconfigDisableOption "UCLIBC_HAS_FPU" "${cfg}" + ;; + esac + done +} diff --git a/scripts/build/arch/mips.sh b/scripts/build/arch/mips.sh index 030e77b..6097c89 100644 --- a/scripts/build/arch/mips.sh +++ b/scripts/build/arch/mips.sh @@ -47,3 +47,25 @@ CT_DoArchUClibcConfig() { CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS64" "${cfg}" CT_KconfigDeleteOption "CONFIG_MIPS_ISA_MIPS64R2" "${cfg}" } + +CT_DoArchUClibcCflags() { + local cfg="${1}" + local cflags="${2}" + local f + + for f in ${cflags}; do + case "${f}" in + -mabi=*) + CT_KconfigDisableOption "CONFIG_MIPS_O32_ABI" "${cfg}" + CT_KconfigDisableOption "CONFIG_MIPS_N32_ABI" "${cfg}" + CT_KconfigDisableOption "CONFIG_MIPS_N64_ABI" "${cfg}" + case "${f#-mabi=}" in + 32) CT_KconfigEnableOption "CONFIG_MIPS_O32_ABI" "${cfg}";; + n32) CT_KconfigEnableOption "CONFIG_MIPS_N32_ABI" "${cfg}";; + 64) CT_KconfigEnableOption "CONFIG_MIPS_N64_ABI" "${cfg}";; + *) CT_Abort "Unsupported ABI: ${f#-mabi=}";; + esac + ;; + esac + done +} diff --git a/scripts/build/arch/x86.sh b/scripts/build/arch/x86.sh index 4193278..9cd14a0 100644 --- a/scripts/build/arch/x86.sh +++ b/scripts/build/arch/x86.sh @@ -130,3 +130,40 @@ CT_DoArchUClibcConfig() { ;; esac } + +CT_DoArchUClibcCflags() { + local cfg="${1}" + local cflags="${2}" + local f + + for f in ${cflags}; do + case "${f}" in + -m64) + CT_DoArchUClibcSelectArch "${cfg}" "x86_64" + ;; + -m32) + # Since it's a part of multilib with 64-bit flavor, default + # to new architecture (i686). + CT_DoArchUClibcSelectArch "${cfg}" "i386" + CT_KconfigDisableOption "CONFIG_386" "${cfg}" + CT_KconfigDisableOption "CONFIG_486" "${cfg}" + CT_KconfigDisableOption "CONFIG_586" "${cfg}" + CT_KconfigEnableOption "CONFIG_686" "${cfg}" + ;; + -mx32) + CT_Abort "uClibc does not support x32 ABI" + ;; + esac + done +} + +CT_DoArchUClibcHeaderDir() { + local dir_var="${1}" + local cflags="${2}" + + # If it is non-default multilib, add a suffix with architecture (reported by gcc) + # to the headers installation path. + if [ -n "${cflags}" ]; then + eval "${dir_var}="$( ${CT_TARGET}-gcc -print-multiarch ${cflags} ) + fi +} diff --git a/scripts/build/libc/uClibc.sh b/scripts/build/libc/uClibc.sh index 1e2a290..822d381 100644 --- a/scripts/build/libc/uClibc.sh +++ b/scripts/build/libc/uClibc.sh @@ -63,12 +63,13 @@ do_libc() { do_libc_backend libc_mode=final } -# Common backend for 1st and 2nd passes +# Common backend for 1st and 2nd passes. do_libc_backend() { local libc_mode - local multi_os_dir multi_root multilib_dir startfiles_dir - local jflag=${CT_LIBC_UCLIBC_PARALLEL:+${JOBSFLAGS}} - local -a make_args + local -a multilibs + local multilib + local multi_dir multi_os_dir multi_flags + local ldso ldso_f ldso_d multilib_dir for arg in "$@"; do eval "${arg// /\\ }" @@ -80,14 +81,86 @@ do_libc_backend() { *) CT_Abort "Unsupported (or unset) libc_mode='${libc_mode}'";; esac + # 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} ) + + 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 + + if [ "${libc_mode}" = "final" -a "${CT_SHARED_LIBS}" = "y" ]; then + # uClibc and GCC disagree where the dynamic linker lives. uClibc always + # places it in the MULTILIB_DIR, while gcc does that for *some* variants + # and expects it in /lib for the other. So, create a symlink from lib + # 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. + CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-test-ldso" + echo "int main(void) { return 0; }" > dummy.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} ) + multilib_dir="/lib/${multi_os_dir}" + CT_SanitizeVarDir multilib_dir + + CT_DoExecLog ALL "${CT_TARGET}-gcc" -o dummy dummy.c ${multi_flags} + ldso=$( ${CT_TARGET}-readelf -Wl dummy | \ + 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_Popd + fi + + CT_EndStep +} + +# 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 jflag=${CT_LIBC_UCLIBC_PARALLEL:+${JOBSFLAGS}} + local -a make_args + local build_dir + local extra_cflags f cfg_cflags cf + local hdr_install_subdir + + for arg in "$@"; do + eval "${arg// /\\ }" + done + # 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 -a "${CT_SRC_DIR}/${uclibc_name}-${CT_LIBC_VERSION}" \ - "${CT_BUILD_DIR}/build-libc-${libc_mode}" - cd "${CT_BUILD_DIR}/build-libc-${libc_mode}" + build_dir="${CT_BUILD_DIR}/build-libc-${libc_mode}${multi_dir//\//_}" + CT_DoExecLog ALL cp -a "${CT_SRC_DIR}/${uclibc_name}-${CT_LIBC_VERSION}" "${build_dir}" + cd "${build_dir}" - multi_os_dir=$( "${CT_TARGET}-gcc" -print-multi-os-directory ) - multi_root=$( "${CT_TARGET}-gcc" -print-sysroot ) multilib_dir="lib/${multi_os_dir}" startfiles_dir="${multi_root}/usr/${multilib_dir}" CT_SanitizeVarDir multilib_dir startfiles_dir @@ -103,7 +176,6 @@ do_libc_backend() { # - We do _not_ want to strip anything for now, in case we specifically # asked for a debug toolchain, thus the STRIPTOOL= assignment. make_args=( CROSS_COMPILE="${CT_TARGET}-" \ - UCLIBC_EXTRA_CFLAGS="-pipe" \ PREFIX="${multi_root}/" \ MULTILIB_DIR="${multilib_dir}" \ LOCALE_DATA_FILENAME="${uclibc_locale_tarball}.tgz" \ @@ -120,10 +192,45 @@ do_libc_backend() { CT_LIBC_UCLIBC_CONFIG_FILE="${CT_LIB_DIR}/contrib/uClibc-defconfigs/${uclibc_name}.config" fi - manage_uClibc_config "${CT_LIBC_UCLIBC_CONFIG_FILE}" .config - + manage_uClibc_config "${CT_LIBC_UCLIBC_CONFIG_FILE}" .config "${multi_flags}" CT_DoYes | CT_DoExecLog ALL ${make} "${make_args[@]}" oldconfig + # Now filter the multilib flags. manage_uClibc_config did the opposite of + # what Rules.mak in uClibc would do: by the multilib's CFLAGS, it determined + # the applicable configuration options. We don't want to pass the same options + # in the UCLIBC_EXTRA_CFLAGS again (on some targets, the options do not correctly + # override each other). On the other hand, we do not want to lose the options + # that are not reflected in the .config. + extra_cflags="-pipe" + { echo "include Rules.mak"; echo "show-cpu-flags:"; printf '\t@echo $(CPU_CFLAGS)\n'; } \ + > .show-cpu-cflags.mk + cfg_cflags=$( ${make} "${make_args[@]}" \ + --no-print-directory -f .show-cpu-cflags.mk show-cpu-flags ) + CT_DoExecLog ALL rm -f .show-cpu-cflags.mk + CT_DoLog DEBUG "CPU_CFLAGS detected by uClibc: ${cfg_cflags[@]}" + for f in ${multi_flags}; do + for cf in ${cfg_cflags}; do + if [ "${f}" = "${cf}" ]; then + f= + break + fi + done + if [ -n "${f}" ]; then + extra_cflags+=" ${f}" + fi + done + CT_DoLog DEBUG "Filtered multilib CFLAGS: ${extra_cflags}" + make_args+=( UCLIBC_EXTRA_CFLAGS="${extra_cflags}" ) + + # uClibc does not have a way to select the installation subdirectory for headers, + # it is always $(DEVEL_PREFIX)/include. Also, we're reinstalling the headers + # at the final stage (see the note below), we may already have the subdirectory + # in /usr/include. + CT_DoArchUClibcHeaderDir hdr_install_subdir "${multi_flags}" + if [ -n "$hdr_install_subdir" ]; then + CT_DoExecLog ALL cp -a "${multi_root}/usr/include" "${multi_root}/usr/include.saved" + fi + if [ "${libc_mode}" = "startfiles" ]; then CT_DoLog EXTRA "Building headers" CT_DoExecLog ALL ${make} "${make_args[@]}" headers @@ -146,7 +253,7 @@ do_libc_backend() { # No problem to create it for other archs. CT_DoLog EXTRA "Building dummy shared libs" CT_DoExecLog ALL "${CT_TARGET}-gcc" -nostdlib -nostartfiles \ - -shared -x c /dev/null -o libdummy.so + -shared ${multi_flags} -x c /dev/null -o libdummy.so CT_DoLog EXTRA "Installing start files" CT_DoExecLog ALL ${install} -m 0644 lib/crt1.o lib/crti.o lib/crtn.o \ @@ -182,7 +289,14 @@ do_libc_backend() { CT_DoExecLog ALL ${make} "${make_args[@]}" install fi # libc_mode == final - CT_EndStep + # Now, if installing headers into a subdirectory, put everything in its place. + # Remove the header subdirectory if it existed already. + if [ -n "$hdr_install_subdir" ]; then + CT_DoExecLog ALL mv "${multi_root}/usr/include" "${multi_root}/usr/include.new" + CT_DoExecLog ALL mv "${multi_root}/usr/include.saved" "${multi_root}/usr/include" + CT_DoExecLog ALL rm -rf "${multi_root}/usr/include/${hdr_install_subdir}" + CT_DoExecLog ALL mv "${multi_root}/usr/include.new" "${multi_root}/usr/include/${hdr_install_subdir}" + fi } # Initialises the .config file to sensible values @@ -191,6 +305,7 @@ do_libc_backend() { manage_uClibc_config() { src="$1" dst="$2" + flags="$3" # Start with fresh files CT_DoExecLog ALL cp "${src}" "${dst}" @@ -364,6 +479,7 @@ manage_uClibc_config() { # Now allow architecture to tweak as it wants CT_DoArchUClibcConfig "${dst}" + CT_DoArchUClibcCflags "${dst}" "${flags}" } do_libc_post_cc() { -- cgit v0.10.2-6-g49f6 From 99dd2f6f60ff244f509d917dc00d080667a90f69 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sat, 9 Apr 2016 00:27:21 -0700 Subject: mips: allow o32 ABI as default for multilib ... since n32 and n64 are going to get built as well. Signed-off-by: Alexey Neyman diff --git a/config/arch/mips.in.2 b/config/arch/mips.in.2 index ee0424d..35c60e0 100644 --- a/config/arch/mips.in.2 +++ b/config/arch/mips.in.2 @@ -7,7 +7,7 @@ choice config ARCH_mips_o32 bool prompt "o32" - depends on ARCH_32 + depends on (ARCH_32 || MULTILIB) help This is the -mabi=32 gcc option. -- cgit v0.10.2-6-g49f6 From 258394c19f7b3fd3700814d7b4de9336bb16e554 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Mon, 11 Apr 2016 23:11:22 -0700 Subject: Treat multiroots differently. 'ld' does not search for dependency libraries in multi_os_directory, so if there's both multi_os_directory and multi_root, and there is only one configuration in each multi_root, forgo the multi_os_directory suffix. Needed for sh4-multilib-linux-uclibc. Signed-off-by: Alexey Neyman diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index dc9443c..8093e08 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -66,7 +66,8 @@ do_libc_backend() { local libc_mode local -a multilibs local multilib - local multi_dir multi_os_dir multi_flags multi_last + local multi_dir multi_os_dir multi_root multi_flags multi_last + local root_suffix local target local arg @@ -86,18 +87,12 @@ 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) ) - 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 - # GCC makes the distinction between: # multilib (-print-multi-lib or -print-multi-directory) and # multilib-os (--print-multi-os-directory) @@ -114,10 +109,50 @@ do_libc_backend() { # /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}" @@ -127,7 +162,7 @@ do_libc_backend() { # 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//\//_}" + CT_mkdir_pushd "multilib_${multi_dir//\//_}" do_libc_backend_once multi_dir="${multi_dir}" \ multi_os_dir="${multi_os_dir}" \ multi_flags="${multi_flags}" \ @@ -141,6 +176,7 @@ do_libc_backend() { done + CT_Popd CT_EndStep } diff --git a/scripts/build/libc/uClibc.sh b/scripts/build/libc/uClibc.sh index 822d381..edde815 100644 --- a/scripts/build/libc/uClibc.sh +++ b/scripts/build/libc/uClibc.sh @@ -81,6 +81,8 @@ do_libc_backend() { *) CT_Abort "Unsupported (or unset) libc_mode='${libc_mode}'";; 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 @@ -88,6 +90,26 @@ do_libc_backend() { 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}" \ @@ -104,17 +126,23 @@ do_libc_backend() { # and expects it in /lib for the other. So, create a symlink from lib # 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. - CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-test-ldso" - echo "int main(void) { return 0; }" > dummy.c + 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 dummy dummy.c ${multi_flags} - ldso=$( ${CT_TARGET}-readelf -Wl dummy | \ + 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.*}" @@ -135,9 +163,9 @@ do_libc_backend() { "${multi_root}${ldso}" fi done - CT_Popd fi + CT_Popd CT_EndStep } @@ -157,9 +185,9 @@ do_libc_backend_once() { # Simply copy files until uClibc has the ability to build out-of-tree CT_DoLog EXTRA "Copying sources to build dir" - build_dir="${CT_BUILD_DIR}/build-libc-${libc_mode}${multi_dir//\//_}" + build_dir="multilib_${multi_dir//\//_}" CT_DoExecLog ALL cp -a "${CT_SRC_DIR}/${uclibc_name}-${CT_LIBC_VERSION}" "${build_dir}" - cd "${build_dir}" + CT_Pushd "${build_dir}" multilib_dir="lib/${multi_os_dir}" startfiles_dir="${multi_root}/usr/${multilib_dir}" @@ -297,6 +325,8 @@ do_libc_backend_once() { CT_DoExecLog ALL rm -rf "${multi_root}/usr/include/${hdr_install_subdir}" CT_DoExecLog ALL mv "${multi_root}/usr/include.new" "${multi_root}/usr/include/${hdr_install_subdir}" fi + + CT_Popd } # Initialises the .config file to sensible values -- cgit v0.10.2-6-g49f6 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 diff --git a/scripts/build/arch/sh.sh b/scripts/build/arch/sh.sh index 101e4ce..6761435 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 8093e08..8027b8f 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 edde815..046ba1d 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 ef75e09..f1dfd12 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