scripts/build/internals.sh
author Remy Bohmer <linux@bohmer.net>
Thu May 27 23:18:19 2010 +0200 (2010-05-27)
changeset 2060 51e4597b07fc
parent 2034 c3967b2c49b4
child 2089 eddb1bbc7b30
permissions -rw-r--r--
scripts: add option to strip all toolchain executables

To reduce filesizes of the toolchain and even improve build times
of projects to be build with this toolchain it is usefull to strip
the delivered toolchain executables. Since it is not likely that we
will debug the toolchain executables itself we do not need the
debug information inside the executables itself.

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