scripts/build/internals.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu Jul 22 23:26:08 2010 +0200 (2010-07-22)
changeset 2034 c3967b2c49b4
parent 2004 5d6d3c28a658
child 2060 51e4597b07fc
permissions -rw-r--r--
scripts: add a cross-ldd-like

Add a cross-ldd that mimicks a native ldd.
     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 
     9     CT_DoStep INFO "Cleaning-up the toolchain's directory"
    10 
    11     if [ "${CT_BARE_METAL}" != "y" ]; then
    12         CT_DoLog EXTRA "Installing the populate helper"
    13         sed -r -e 's|@@CT_TARGET@@|'"${CT_TARGET}"'|g;' \
    14                -e 's|@@CT_install@@|'"${install}"'|g;'  \
    15                -e 's|@@CT_bash@@|'"${bash}"'|g;'        \
    16                -e 's|@@CT_grep@@|'"${grep}"'|g;'        \
    17                -e 's|@@CT_make@@|'"${make}"'|g;'        \
    18                -e 's|@@CT_sed@@|'"${sed}"'|g;'          \
    19                "${CT_LIB_DIR}/scripts/populate.in"      \
    20                >"${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
    21         CT_DoExecLog ALL chmod 755 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
    22     fi
    23 
    24     if [ "${CT_LIBC_XLDD}" = "y" ]; then
    25         CT_DoLog EXTRA "Installing a cross-ldd helper"
    26         sed -r -e 's|@@CT_TARGET@@|'"${CT_TARGET}"'|g;' \
    27                -e 's|@@CT_install@@|'"${install}"'|g;'  \
    28                -e 's|@@CT_bash@@|'"${bash}"'|g;'        \
    29                -e 's|@@CT_grep@@|'"${grep}"'|g;'        \
    30                -e 's|@@CT_make@@|'"${make}"'|g;'        \
    31                -e 's|@@CT_sed@@|'"${sed}"'|g;'          \
    32                "${CT_LIB_DIR}/scripts/xldd.in"          \
    33                >"${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
    34         CT_DoExecLog ALL chmod 755 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
    35     fi
    36 
    37     # Create the aliases to the target tools
    38     CT_DoLog EXTRA "Creating toolchain aliases"
    39     CT_Pushd "${CT_PREFIX_DIR}/bin"
    40     for t in "${CT_TARGET}-"*; do
    41         if [ -n "${CT_TARGET_ALIAS}" ]; then
    42             _t=$(echo "$t" |sed -r -e 's/^'"${CT_TARGET}"'-/'"${CT_TARGET_ALIAS}"'-/;')
    43             CT_DoExecLog ALL ln -sv "${t}" "${_t}"
    44         fi
    45         if [ -n "${CT_TARGET_ALIAS_SED_EXPR}" ]; then
    46             _t=$(echo "$t" |sed -r -e "${CT_TARGET_ALIAS_SED_EXPR}")
    47             if [ "${_t}" = "${t}" ]; then
    48                 CT_DoLog WARN "The sed expression '${CT_TARGET_ALIAS_SED_EXPR}' has no effect on '${t}'"
    49             else
    50                 CT_DoExecLog ALL ln -sv "${t}" "${_t}"
    51             fi
    52         fi
    53     done
    54     CT_Popd
    55 
    56     # If using the companion libraries, we need a wrapper
    57     # that will set LD_LIBRARY_PATH approriately
    58     if [ "${CT_WRAPPER_NEEDED}" = "y" ]; then
    59         CT_DoLog EXTRA "Installing toolchain wrappers"
    60         CT_Pushd "${CT_PREFIX_DIR}/bin"
    61 
    62         case "$CT_SYS_OS" in
    63             Darwin|FreeBSD)
    64                 # wrapper does not work (when using readlink -m)
    65                 CT_DoLog WARN "Forcing usage of binary tool wrapper"
    66                 CT_TOOLS_WRAPPER="exec"
    67                 ;;
    68         esac
    69         # Install the wrapper
    70         case "${CT_TOOLS_WRAPPER}" in
    71             script)
    72                 CT_DoExecLog DEBUG install                              \
    73                                    -m 0755                              \
    74                                    "${CT_LIB_DIR}/scripts/wrapper.in"   \
    75                                    ".${CT_TARGET}-wrapper"
    76                 ;;
    77             exec)
    78                 CT_DoExecLog DEBUG "${CT_HOST}-gcc"                           \
    79                                    -Wall -Wextra -Werror                      \
    80                                    -Os                                        \
    81                                    "${CT_LIB_DIR}/scripts/wrapper.c"          \
    82                                    -o ".${CT_TARGET}-wrapper"
    83                 if [ "${CT_DEBUG_CT}" != "y" ]; then
    84                     # If not debugging crosstool-NG, strip the wrapper
    85                     CT_DoExecLog DEBUG "${CT_HOST}-strip" ".${CT_TARGET}-wrapper"
    86                 fi
    87                 ;;
    88         esac
    89 
    90         # Replace every tools with the wrapper
    91         # Do it unconditionally, even for those tools that happen to be shell
    92         # scripts, we don't know if they would in the end spawn a binary...
    93         # Just skip symlinks
    94         for _t in "${CT_TARGET}-"*; do
    95             if [ ! -L "${_t}" ]; then
    96                 CT_DoExecLog ALL mv "${_t}" ".${_t}"
    97                 CT_DoExecLog ALL ln ".${CT_TARGET}-wrapper" "${_t}"
    98             fi
    99         done
   100 
   101         # Get rid of the wrapper, we're using hardlinks
   102         CT_DoExecLog DEBUG rm -f ".${CT_TARGET}-wrapper"
   103         CT_Popd
   104     fi
   105 
   106     CT_DoLog EXTRA "Removing access to the build system tools"
   107     CT_DoExecLog DEBUG rm -rf "${CT_PREFIX_DIR}/buildtools"
   108 
   109     # Remove the generated documentation files
   110     if [ "${CT_REMOVE_DOCS}" = "y" ]; then
   111         CT_DoLog EXTRA "Removing installed documentation"
   112         CT_DoForceRmdir "${CT_PREFIX_DIR}/"{,usr/}{man,info}
   113         CT_DoForceRmdir "${CT_SYSROOT_DIR}/"{,usr/}{man,info}
   114         CT_DoForceRmdir "${CT_DEBUGROOT_DIR}/"{,usr/}{man,info}
   115     fi
   116 
   117     # Remove headers installed by native companion libraries
   118     CT_DoForceRmdir "${CT_PREFIX_DIR}/include"
   119 
   120     CT_EndStep
   121 }