scripts/build/internals.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Aug 17 23:50:03 2010 +0200 (2010-08-17)
changeset 2087 fefd9a3f8180
parent 2034 c3967b2c49b4
child 2089 eddb1bbc7b30
permissions -rw-r--r--
libc/mingw: fix space-damage

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