scripts/build/internals.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Dec 29 19:41:17 2010 +0100 (2010-12-29)
changeset 2236 cb0f625b3f9f
parent 2214 10d4f2bc227b
child 2301 a3818c3b03e0
permissions -rw-r--r--
internals: properly remove all docs

Part of the installed doc was not removed (if configured to).

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