scripts/build/internals.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu Feb 17 21:54:07 2011 +0100 (2011-02-17)
changeset 2301 a3818c3b03e0
parent 2236 cb0f625b3f9f
child 2311 b49767e8651b
permissions -rw-r--r--
internals: fix stripping host binaries

The gcc used by linaro has a version number specific to Linaro, but
identifies itself with its upstream version numbering scheme.

This breaks the strip in the finish step, because the actual gcc version
is not the same as the configured one (eg. 4.5.2 vs. linaro-4.5-2011.02-0).

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
     1 # This file contains crosstool-NG internal steps
     2 
     3 # This step is called once all components were built, to remove
     4 # un-wanted files, to add tuple aliases, and to add the final
     5 # crosstool-NG-provided files.
     6 do_finish() {
     7     local _t
     8     local _type
     9     local strip_args
    10     local gcc_version
    11 
    12     CT_DoStep INFO "Cleaning-up the toolchain's directory"
    13 
    14     if [ "${CT_STRIP_ALL_TOOLCHAIN_EXECUTABLES}" = "y" ]; then
    15         case "$CT_HOST" in
    16             *darwin*)
    17                 strip_args=""
    18                 ;;
    19             *)
    20                 strip_args="--strip-all -v"
    21                 ;;
    22         esac
    23         CT_DoLog INFO "Stripping all toolchain executables"
    24         CT_Pushd "${CT_PREFIX_DIR}"
    25         gcc_version=$( "./bin/${CT_TARGET}-gcc" -dumpversion )
    26         for _t in "bin/${CT_TARGET}-"*                                      \
    27                   "${CT_TARGET}/bin/"*                                      \
    28                   "libexec/gcc/${CT_TARGET}/${gcc_version}/"*               \
    29                   "libexec/gcc/${CT_TARGET}/${gcc_version}/install-tools/"* \
    30         ; do
    31             _type="$( file "${_t}" |cut -d ' ' -f 2- )"
    32             case "${_type}" in
    33                 *"script text executable")
    34                     ;;
    35                 *executable*)
    36                     CT_DoExecLog ALL ${CT_HOST}-strip ${strip_args} "${_t}"
    37                     ;;
    38             esac
    39         done
    40         CT_Popd
    41     fi
    42 
    43     if [ "${CT_BARE_METAL}" != "y" ]; then
    44         CT_DoLog EXTRA "Installing the populate helper"
    45         sed -r -e 's|@@CT_TARGET@@|'"${CT_TARGET}"'|g;' \
    46                -e 's|@@CT_install@@|'"${install}"'|g;'  \
    47                -e 's|@@CT_bash@@|'"${bash}"'|g;'        \
    48                -e 's|@@CT_grep@@|'"${grep}"'|g;'        \
    49                -e 's|@@CT_make@@|'"${make}"'|g;'        \
    50                -e 's|@@CT_sed@@|'"${sed}"'|g;'          \
    51                "${CT_LIB_DIR}/scripts/populate.in"      \
    52                >"${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
    53         CT_DoExecLog ALL chmod 755 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
    54     fi
    55 
    56     if [ "${CT_LIBC_XLDD}" = "y" ]; then
    57         CT_DoLog EXTRA "Installing a cross-ldd helper"
    58         sed -r -e 's|@@CT_VERSION@@|'"${CT_VERSION}"'|g;'   \
    59                -e 's|@@CT_TARGET@@|'"${CT_TARGET}"'|g;'     \
    60                -e 's|@@CT_BITS@@|'"${CT_ARCH_BITNESS}"'|g;' \
    61                -e 's|@@CT_install@@|'"${install}"'|g;'      \
    62                -e 's|@@CT_bash@@|'"${bash}"'|g;'            \
    63                -e 's|@@CT_grep@@|'"${grep}"'|g;'            \
    64                -e 's|@@CT_make@@|'"${make}"'|g;'            \
    65                -e 's|@@CT_sed@@|'"${sed}"'|g;'              \
    66                "${CT_LIB_DIR}/scripts/xldd.in"              \
    67                >"${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
    68         CT_DoExecLog ALL chmod 755 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
    69     fi
    70 
    71     # Create the aliases to the target tools
    72     CT_DoLog EXTRA "Creating toolchain aliases"
    73     CT_Pushd "${CT_PREFIX_DIR}/bin"
    74     for t in "${CT_TARGET}-"*; do
    75         if [ -n "${CT_TARGET_ALIAS}" ]; then
    76             _t=$(echo "$t" |sed -r -e 's/^'"${CT_TARGET}"'-/'"${CT_TARGET_ALIAS}"'-/;')
    77             CT_DoExecLog ALL ln -sv "${t}" "${_t}"
    78         fi
    79         if [ -n "${CT_TARGET_ALIAS_SED_EXPR}" ]; then
    80             _t=$(echo "$t" |sed -r -e "${CT_TARGET_ALIAS_SED_EXPR}")
    81             if [ "${_t}" = "${t}" ]; then
    82                 CT_DoLog WARN "The sed expression '${CT_TARGET_ALIAS_SED_EXPR}' has no effect on '${t}'"
    83             else
    84                 CT_DoExecLog ALL ln -sv "${t}" "${_t}"
    85             fi
    86         fi
    87     done
    88     CT_Popd
    89 
    90     # If using the companion libraries, we need a wrapper
    91     # that will set LD_LIBRARY_PATH approriately
    92     if [ "${CT_WRAPPER_NEEDED}" = "y" ]; then
    93         CT_DoLog EXTRA "Installing toolchain wrappers"
    94         CT_Pushd "${CT_PREFIX_DIR}/bin"
    95 
    96         case "$CT_SYS_OS" in
    97             Darwin|FreeBSD)
    98                 # wrapper does not work (when using readlink -m)
    99                 CT_DoLog WARN "Forcing usage of binary tool wrapper"
   100                 CT_TOOLS_WRAPPER="exec"
   101                 ;;
   102         esac
   103         # Install the wrapper
   104         case "${CT_TOOLS_WRAPPER}" in
   105             script)
   106                 CT_DoExecLog DEBUG install                              \
   107                                    -m 0755                              \
   108                                    "${CT_LIB_DIR}/scripts/wrapper.in"   \
   109                                    ".${CT_TARGET}-wrapper"
   110                 ;;
   111             exec)
   112                 CT_DoExecLog DEBUG "${CT_HOST}-gcc"                           \
   113                                    -Wall -Wextra -Werror                      \
   114                                    -Os                                        \
   115                                    "${CT_LIB_DIR}/scripts/wrapper.c"          \
   116                                    -o ".${CT_TARGET}-wrapper"
   117                 if [ "${CT_DEBUG_CT}" != "y" ]; then
   118                     # If not debugging crosstool-NG, strip the wrapper
   119                     CT_DoExecLog DEBUG "${CT_HOST}-strip" ".${CT_TARGET}-wrapper"
   120                 fi
   121                 ;;
   122         esac
   123 
   124         # Replace every tools with the wrapper
   125         # Do it unconditionally, even for those tools that happen to be shell
   126         # scripts, we don't know if they would in the end spawn a binary...
   127         # Just skip symlinks
   128         for _t in "${CT_TARGET}-"*; do
   129             if [ ! -L "${_t}" ]; then
   130                 CT_DoExecLog ALL mv "${_t}" ".${_t}"
   131                 CT_DoExecLog ALL ln ".${CT_TARGET}-wrapper" "${_t}"
   132             fi
   133         done
   134 
   135         # Get rid of the wrapper, we're using hardlinks
   136         CT_DoExecLog DEBUG rm -f ".${CT_TARGET}-wrapper"
   137         CT_Popd
   138     fi
   139 
   140     CT_DoLog EXTRA "Removing access to the build system tools"
   141     CT_DoExecLog DEBUG rm -rf "${CT_PREFIX_DIR}/buildtools"
   142 
   143     # Remove the generated documentation files
   144     if [ "${CT_REMOVE_DOCS}" = "y" ]; then
   145         CT_DoLog EXTRA "Removing installed documentation"
   146         CT_DoForceRmdir "${CT_PREFIX_DIR}/"{,usr/}{,share/}{man,info}
   147         CT_DoForceRmdir "${CT_SYSROOT_DIR}/"{,usr/}{,share/}{man,info}
   148         CT_DoForceRmdir "${CT_DEBUGROOT_DIR}/"{,usr/}{,share/}{man,info}
   149     fi
   150 
   151     # Remove headers installed by native companion libraries
   152     CT_DoForceRmdir "${CT_PREFIX_DIR}/include"
   153 
   154     # Remove the lib* symlinks, now:
   155     # The symlinks are needed only during the build process.
   156     # The final gcc will still search those dirs, but will also search
   157     # the standard lib/ dirs, so we can get rid of the symlinks
   158     for d in                            \
   159         "${CT_PREFIX_DIR}"              \
   160         "${CT_SYSROOT_DIR}"             \
   161         "${CT_SYSROOT_DIR}/usr"         \
   162         "${CT_PREFIX_DIR}/${CT_TARGET}" \
   163     ; do
   164         CT_DoExecLog ALL rm -f "${d}/lib32"
   165         CT_DoExecLog ALL rm -f "${d}/lib64"
   166     done
   167 
   168     # Also remove the lib/ symlink out-side of sysroot
   169     if [ "${CT_USE_SYSROOT}" = "y" ]; then
   170         CT_DoExecLog ALL rm -f "${CT_PREFIX_DIR}/${CT_TARGET}/lib"
   171     fi
   172 
   173     CT_EndStep
   174 }