scripts/build/internals.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Mar 22 18:10:00 2011 +0100 (2011-03-22)
changeset 2357 21025504dbc9
parent 2336 ade5d48d98f2
child 2381 0ca0f85a4b2a
permissions -rw-r--r--
scripts/internals: fix stripping once more

Some scripts have 'very long lines', so the output of 'file'
will have that mentioned, such as:
POSIX shell script, ASCII text executable, with very long lines

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