scripts/build/internals.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Nov 16 17:49:15 2010 +0100 (2010-11-16)
changeset 2204 ea1c9143e1e3
parent 2185 46330accf748
child 2213 6aa057745dbd
permissions -rw-r--r--
scripts: call curl and wget in sequence

It can happen, in some circumpstances, than one can succeed where
the other would fail. Those cases involves convoluted enterprise
networks with proxies playing tricks.

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