scripts/build/internals.sh
author Titus von Boxberg <titus@v9g.de>
Sat Aug 21 16:45:50 2010 +0200 (2010-08-21)
changeset 2089 eddb1bbc7b30
parent 2060 51e4597b07fc
child 2117 24aacb93191d
permissions -rw-r--r--
internals: call strip in a portable way

strip on CT_HOST darwin does not want --strip-all or -v
     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_TARGET@@|'"${CT_TARGET}"'|g;' \
    51                -e 's|@@CT_install@@|'"${install}"'|g;'  \
    52                -e 's|@@CT_bash@@|'"${bash}"'|g;'        \
    53                -e 's|@@CT_grep@@|'"${grep}"'|g;'        \
    54                -e 's|@@CT_make@@|'"${make}"'|g;'        \
    55                -e 's|@@CT_sed@@|'"${sed}"'|g;'          \
    56                "${CT_LIB_DIR}/scripts/xldd.in"          \
    57                >"${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
    58         CT_DoExecLog ALL chmod 755 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
    59     fi
    60 
    61     # Create the aliases to the target tools
    62     CT_DoLog EXTRA "Creating toolchain aliases"
    63     CT_Pushd "${CT_PREFIX_DIR}/bin"
    64     for t in "${CT_TARGET}-"*; do
    65         if [ -n "${CT_TARGET_ALIAS}" ]; then
    66             _t=$(echo "$t" |sed -r -e 's/^'"${CT_TARGET}"'-/'"${CT_TARGET_ALIAS}"'-/;')
    67             CT_DoExecLog ALL ln -sv "${t}" "${_t}"
    68         fi
    69         if [ -n "${CT_TARGET_ALIAS_SED_EXPR}" ]; then
    70             _t=$(echo "$t" |sed -r -e "${CT_TARGET_ALIAS_SED_EXPR}")
    71             if [ "${_t}" = "${t}" ]; then
    72                 CT_DoLog WARN "The sed expression '${CT_TARGET_ALIAS_SED_EXPR}' has no effect on '${t}'"
    73             else
    74                 CT_DoExecLog ALL ln -sv "${t}" "${_t}"
    75             fi
    76         fi
    77     done
    78     CT_Popd
    79 
    80     # If using the companion libraries, we need a wrapper
    81     # that will set LD_LIBRARY_PATH approriately
    82     if [ "${CT_WRAPPER_NEEDED}" = "y" ]; then
    83         CT_DoLog EXTRA "Installing toolchain wrappers"
    84         CT_Pushd "${CT_PREFIX_DIR}/bin"
    85 
    86         case "$CT_SYS_OS" in
    87             Darwin|FreeBSD)
    88                 # wrapper does not work (when using readlink -m)
    89                 CT_DoLog WARN "Forcing usage of binary tool wrapper"
    90                 CT_TOOLS_WRAPPER="exec"
    91                 ;;
    92         esac
    93         # Install the wrapper
    94         case "${CT_TOOLS_WRAPPER}" in
    95             script)
    96                 CT_DoExecLog DEBUG install                              \
    97                                    -m 0755                              \
    98                                    "${CT_LIB_DIR}/scripts/wrapper.in"   \
    99                                    ".${CT_TARGET}-wrapper"
   100                 ;;
   101             exec)
   102                 CT_DoExecLog DEBUG "${CT_HOST}-gcc"                           \
   103                                    -Wall -Wextra -Werror                      \
   104                                    -Os                                        \
   105                                    "${CT_LIB_DIR}/scripts/wrapper.c"          \
   106                                    -o ".${CT_TARGET}-wrapper"
   107                 if [ "${CT_DEBUG_CT}" != "y" ]; then
   108                     # If not debugging crosstool-NG, strip the wrapper
   109                     CT_DoExecLog DEBUG "${CT_HOST}-strip" ".${CT_TARGET}-wrapper"
   110                 fi
   111                 ;;
   112         esac
   113 
   114         # Replace every tools with the wrapper
   115         # Do it unconditionally, even for those tools that happen to be shell
   116         # scripts, we don't know if they would in the end spawn a binary...
   117         # Just skip symlinks
   118         for _t in "${CT_TARGET}-"*; do
   119             if [ ! -L "${_t}" ]; then
   120                 CT_DoExecLog ALL mv "${_t}" ".${_t}"
   121                 CT_DoExecLog ALL ln ".${CT_TARGET}-wrapper" "${_t}"
   122             fi
   123         done
   124 
   125         # Get rid of the wrapper, we're using hardlinks
   126         CT_DoExecLog DEBUG rm -f ".${CT_TARGET}-wrapper"
   127         CT_Popd
   128     fi
   129 
   130     CT_DoLog EXTRA "Removing access to the build system tools"
   131     CT_DoExecLog DEBUG rm -rf "${CT_PREFIX_DIR}/buildtools"
   132 
   133     # Remove the generated documentation files
   134     if [ "${CT_REMOVE_DOCS}" = "y" ]; then
   135         CT_DoLog EXTRA "Removing installed documentation"
   136         CT_DoForceRmdir "${CT_PREFIX_DIR}/"{,usr/}{man,info}
   137         CT_DoForceRmdir "${CT_SYSROOT_DIR}/"{,usr/}{man,info}
   138         CT_DoForceRmdir "${CT_DEBUGROOT_DIR}/"{,usr/}{man,info}
   139     fi
   140 
   141     # Remove headers installed by native companion libraries
   142     CT_DoForceRmdir "${CT_PREFIX_DIR}/include"
   143 
   144     CT_EndStep
   145 }