scripts/build/internals.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Nov 23 21:35:15 2010 +0100 (2010-11-23)
changeset 2187 9cdb153ff9df
parent 2185 46330accf748
child 2213 6aa057745dbd
permissions -rw-r--r--
scripts/xldd: report appropriate load address for 32- or 64-bit

For 32-bit target systems, report 4-byte (8-xdigit) wide adresses,
and for 64-bit, report 8-byte (16-xdigit) wide adresses.

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