summaryrefslogtreecommitdiff
path: root/scripts/build/internals.sh
blob: 7d91d781606451a390c6d340bd099e8e8179e93b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# This file contains crosstool-NG internal steps

# This step is called once all components were built, to remove
# un-wanted files, to add tuple aliases, and to add the final
# crosstool-NG-provided files.
do_finish() {
    local _t
    local _type
    local strip_args
    local gcc_version
    local exe_suffix

    CT_DoStep INFO "Cleaning-up the toolchain's directory"

    if [ "${CT_STRIP_HOST_TOOLCHAIN_EXECUTABLES}" = "y" ]; then
        case "$CT_HOST" in
            *darwin*)
                strip_args=""
                ;;
            *freebsd*)
                strip_args="--strip-all"
                ;;
            *)
                strip_args="--strip-all -v"
                ;;
        esac
        case "$CT_TARGET" in
            *mingw*)
                exe_suffix=".exe"
                ;;
            *)
                exe_suffix=""
                ;;
        esac
        CT_DoLog INFO "Stripping all toolchain executables"
        CT_Pushd "${CT_PREFIX_DIR}"

        # Strip gdbserver
        if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
            CT_DoExecLog ALL "${CT_TARGET}-strip" ${strip_args}         \
                             "${CT_TARGET}/debug-root/usr/bin/gdbserver${exe_suffix}"
        fi
        if [ "${CT_CC_gcc}" = "y" ]; then
            # We can not use the version in CT_CC_GCC_VERSION because
            # of the Linaro stuff. So, harvest the version string
            # directly from the gcc sources...
            # All gcc 4.x seem to have the version in gcc/BASE-VER
            # while version prior to 4.x have the version in gcc/version.c
            # Of course, here is not the better place to do that...
            if [ -f "${CT_SRC_DIR}/gcc-${CT_CC_GCC_VERSION}/gcc/BASE-VER" ]; then
                gcc_version=$( cat "${CT_SRC_DIR}/gcc-${CT_CC_GCC_VERSION}/gcc/BASE-VER" )
            else
                gcc_version=$(sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \
                                   "${CT_SRC_DIR}/gcc-${CT_CC_GCC_VERSION}/gcc/version.c" \
                             )
            fi
            for _t in "bin/${CT_TARGET}-"*                                      \
                      "${CT_TARGET}/bin/"*                                      \
                      "libexec/gcc/${CT_TARGET}/${gcc_version}/"*               \
                      "libexec/gcc/${CT_TARGET}/${gcc_version}/install-tools/"* \
            ; do
                _type="$( file "${_t}" |cut -d ' ' -f 2- )"
                case "${_type}" in
                    *script*executable*)
                        ;;
                    *executable*)
                        CT_DoExecLog ALL ${CT_HOST}-strip ${strip_args} "${_t}"
                        ;;
                esac
            done
        fi
        CT_Popd
    fi

    if [ "${CT_BARE_METAL}" != "y" ]; then
        CT_DoLog EXTRA "Installing the populate helper"
        sed -r -e 's|@@CT_TARGET@@|'"${CT_TARGET}"'|g;' \
               -e 's|@@CT_install@@|'"install"'|g;'     \
               -e 's|@@CT_awk@@|'"awk"'|g;'             \
               -e 's|@@CT_bash@@|'"${bash}"'|g;'           \
               -e 's|@@CT_grep@@|'"grep"'|g;'           \
               -e 's|@@CT_make@@|'"make"'|g;'           \
               -e 's|@@CT_sed@@|'"sed"'|g;'             \
               "${CT_LIB_DIR}/scripts/populate.in"         \
               >"${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
        CT_DoExecLog ALL chmod 755 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
    fi

    if [ "${CT_LIBC_XLDD}" = "y" ]; then
        CT_DoLog EXTRA "Installing a cross-ldd helper"
        sed -r -e 's|@@CT_VERSION@@|'"${CT_VERSION}"'|g;' \
               -e 's|@@CT_TARGET@@|'"${CT_TARGET}"'|g;'      \
               -e 's|@@CT_BITS@@|'"${CT_ARCH_BITNESS}"'|g;'  \
               -e 's|@@CT_install@@|'"install"'|g;'       \
               -e 's|@@CT_bash@@|'"${bash}"'|g;'             \
               -e 's|@@CT_grep@@|'"grep"'|g;'             \
               -e 's|@@CT_make@@|'"make"'|g;'             \
               -e 's|@@CT_sed@@|'"sed"'|g;'               \
               "${CT_LIB_DIR}/scripts/xldd.in"               \
               >"${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
        CT_DoExecLog ALL chmod 755 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
    fi

    # Create the aliases to the target tools
    CT_DoLog EXTRA "Creating toolchain aliases"
    CT_SymlinkTools "${CT_PREFIX_DIR}/bin" "${CT_PREFIX_DIR}/bin" \
            "${CT_TARGET_ALIAS}" "${CT_TARGET_ALIAS_SED_EXPR}"

    # Remove the generated documentation files
    if [ "${CT_REMOVE_DOCS}" = "y" ]; then
        CT_DoLog EXTRA "Removing installed documentation"
        CT_DoForceRmdir "${CT_PREFIX_DIR}/"{,usr/}{,share/}{man,info}
        CT_DoForceRmdir "${CT_SYSROOT_DIR}/"{,usr/}{,share/}{man,info}
        CT_DoForceRmdir "${CT_DEBUGROOT_DIR}/"{,usr/}{,share/}{man,info}
    fi

    CT_EndStep
}