From 4ee22d66a849123c06812736dd1472840aad5823 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Fri, 1 Apr 2016 23:28:43 -0700 Subject: [PATCH] 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 --- config/libc/uClibc.in | 4 +- scripts/build/libc/uClibc.sh | 253 ++++++++++++++--------------------- 2 files changed, 103 insertions(+), 154 deletions(-) diff --git a/config/libc/uClibc.in b/config/libc/uClibc.in index 989da7ba..a99ff736 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 41b651f2..edd82f6a 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 + # 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 +} - CT_DoStep INFO "Installing C library headers" +# 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 + + 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 -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 + "${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}" - CT_SanitizeVarDir startfiles_dir - CT_DoExecLog ALL mkdir -p "${startfiles_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} \ + ) + + # 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" - 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_DoYes | CT_DoExecLog ALL ${make} "${make_args[@]}" 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 + if [ "${libc_mode}" = "startfiles" ]; then + CT_DoLog EXTRA "Building headers" + CT_DoExecLog ALL ${make} "${make_args[@]}" 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 + # Ensure the directory for installing multilib-specific binaries exists. + CT_DoExecLog ALL mkdir -p "${startfiles_dir}" - # 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 + CT_DoLog EXTRA "Installing headers" + CT_DoExecLog ALL ${make} "${make_args[@]}" install_headers - # 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 + # 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 - CT_DoLog EXTRA "Installing start files" - CT_DoExecLog ALL ${install} -m 0644 lib/crt1.o lib/crti.o lib/crtn.o \ - "${startfiles_dir}" + # 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 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_DoLog EXTRA "Installing start files" + CT_DoExecLog ALL ${install} -m 0644 lib/crt1.o lib/crti.o lib/crtn.o \ + "${startfiles_dir}" - CT_EndStep -} + 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 -# This function build and install the full uClibc -do_libc() { - local multi_os_dir multi_root multilib_dir startfiles_dir + 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_DoStep INFO "Installing C library" + CT_DoLog EXTRA "Building C library" + CT_DoExecLog ALL ${make} "${make_args[@]}" pregen + CT_DoExecLog ALL ${make} ${jflag} "${make_args[@]}" all - # 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 - - 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. - # 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. - 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 + # 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 }