scripts/build/internals.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Jul 12 23:52:24 2011 +0200 (2011-07-12)
branch1.11
changeset 2558 b7317d2fe0e9
parent 2544 751c3f735ada
child 3044 c79d55b27724
permissions -rw-r--r--
scripts, cc/gcc: do not fail on existing symlinks or build.log

If the user builds a toolchain over an existing one, so, without removing
CT_PREFIX_DIR, the build fails as the symlinks already exist, as does the
build.log.

This can also happen (for build.log) if the user first ran in download-
or extract-only.

Patch (with no SoB) originally from:
Phil Wilshire <phil.wilshire@overturenetworks.com>

Modified by me as it did not apply cleanly.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
(transplanted from 1ebc2248cc60230cd53ff94ae8f8f1e3261461a3)
     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         # We can not use the version in CT_CC_VERSION because
    26         # of the Linaro stuff. So, harvest the version string
    27         # directly from the gcc sources...
    28         # All gcc 4.x seem to have the version in gcc/BASE-VER
    29         # while version prior to 4.x have the version in gcc/version.c
    30         # Of course, here is not the better place to do that...
    31         if [ -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
    32             gcc_version=$( cat "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" )
    33         else
    34             gcc_version=$( sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \
    35                                "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/version.c"   \
    36                          )
    37         fi
    38         for _t in "bin/${CT_TARGET}-"*                                      \
    39                   "${CT_TARGET}/bin/"*                                      \
    40                   "libexec/gcc/${CT_TARGET}/${gcc_version}/"*               \
    41                   "libexec/gcc/${CT_TARGET}/${gcc_version}/install-tools/"* \
    42         ; do
    43             _type="$( file "${_t}" |cut -d ' ' -f 2- )"
    44             case "${_type}" in
    45                 *script*executable*)
    46                     ;;
    47                 *executable*)
    48                     CT_DoExecLog ALL ${CT_HOST}-strip ${strip_args} "${_t}"
    49                     ;;
    50             esac
    51         done
    52         CT_Popd
    53     fi
    54 
    55     if [ "${CT_BARE_METAL}" != "y" ]; then
    56         CT_DoLog EXTRA "Installing the populate helper"
    57         sed -r -e 's|@@CT_TARGET@@|'"${CT_TARGET}"'|g;' \
    58                -e 's|@@CT_install@@|'"${install}"'|g;'  \
    59                -e 's|@@CT_bash@@|'"${bash}"'|g;'        \
    60                -e 's|@@CT_grep@@|'"${grep}"'|g;'        \
    61                -e 's|@@CT_make@@|'"${make}"'|g;'        \
    62                -e 's|@@CT_sed@@|'"${sed}"'|g;'          \
    63                "${CT_LIB_DIR}/scripts/populate.in"      \
    64                >"${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
    65         CT_DoExecLog ALL chmod 755 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
    66     fi
    67 
    68     if [ "${CT_LIBC_XLDD}" = "y" ]; then
    69         CT_DoLog EXTRA "Installing a cross-ldd helper"
    70         sed -r -e 's|@@CT_VERSION@@|'"${CT_VERSION}"'|g;'   \
    71                -e 's|@@CT_TARGET@@|'"${CT_TARGET}"'|g;'     \
    72                -e 's|@@CT_BITS@@|'"${CT_ARCH_BITNESS}"'|g;' \
    73                -e 's|@@CT_install@@|'"${install}"'|g;'      \
    74                -e 's|@@CT_bash@@|'"${bash}"'|g;'            \
    75                -e 's|@@CT_grep@@|'"${grep}"'|g;'            \
    76                -e 's|@@CT_make@@|'"${make}"'|g;'            \
    77                -e 's|@@CT_sed@@|'"${sed}"'|g;'              \
    78                "${CT_LIB_DIR}/scripts/xldd.in"              \
    79                >"${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
    80         CT_DoExecLog ALL chmod 755 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
    81     fi
    82 
    83     # Create the aliases to the target tools
    84     CT_DoLog EXTRA "Creating toolchain aliases"
    85     CT_Pushd "${CT_PREFIX_DIR}/bin"
    86     for t in "${CT_TARGET}-"*; do
    87         if [ -n "${CT_TARGET_ALIAS}" ]; then
    88             _t=$(echo "$t" |sed -r -e 's/^'"${CT_TARGET}"'-/'"${CT_TARGET_ALIAS}"'-/;')
    89             CT_DoExecLog ALL ln -sfv "${t}" "${_t}"
    90         fi
    91         if [ -n "${CT_TARGET_ALIAS_SED_EXPR}" ]; then
    92             _t=$(echo "$t" |sed -r -e "${CT_TARGET_ALIAS_SED_EXPR}")
    93             if [ "${_t}" = "${t}" ]; then
    94                 CT_DoLog WARN "The sed expression '${CT_TARGET_ALIAS_SED_EXPR}' has no effect on '${t}'"
    95             else
    96                 CT_DoExecLog ALL ln -sfv "${t}" "${_t}"
    97             fi
    98         fi
    99     done
   100     CT_Popd
   101 
   102     CT_DoLog EXTRA "Removing access to the build system tools"
   103     CT_DoExecLog DEBUG rm -rf "${CT_PREFIX_DIR}/buildtools"
   104 
   105     # Remove the generated documentation files
   106     if [ "${CT_REMOVE_DOCS}" = "y" ]; then
   107         CT_DoLog EXTRA "Removing installed documentation"
   108         CT_DoForceRmdir "${CT_PREFIX_DIR}/"{,usr/}{,share/}{man,info}
   109         CT_DoForceRmdir "${CT_SYSROOT_DIR}/"{,usr/}{,share/}{man,info}
   110         CT_DoForceRmdir "${CT_DEBUGROOT_DIR}/"{,usr/}{,share/}{man,info}
   111     fi
   112 
   113     # Remove the lib* symlinks, now:
   114     # The symlinks are needed only during the build process.
   115     # The final gcc will still search those dirs, but will also search
   116     # the standard lib/ dirs, so we can get rid of the symlinks
   117     CT_DoExecLog ALL rm -f "${CT_PREFIX_DIR}/lib32"
   118     CT_DoExecLog ALL rm -f "${CT_PREFIX_DIR}/lib64"
   119 
   120     CT_EndStep
   121 }