scripts/build/kernel/linux.sh
author Remy Bohmer <linux@bohmer.net>
Thu May 27 23:18:19 2010 +0200 (2010-05-27)
changeset 2060 51e4597b07fc
parent 1989 f357bc3abfa6
child 2228 aa02b51ce928
permissions -rw-r--r--
scripts: add option to strip all toolchain executables

To reduce filesizes of the toolchain and even improve build times
of projects to be build with this toolchain it is usefull to strip
the delivered toolchain executables. Since it is not likely that we
will debug the toolchain executables itself we do not need the
debug information inside the executables itself.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
     1 # This file declares functions to install the kernel headers for linux
     2 # Copyright 2007 Yann E. MORIN
     3 # Licensed under the GPL v2. See COPYING in the root of this package
     4 
     5 CT_DoKernelTupleValues() {
     6     if [ "${CT_ARCH_USE_MMU}" = "y" ]; then
     7         CT_TARGET_KERNEL="linux"
     8     else
     9     # Sometime, noMMU linux targets have a -uclinux tuple, while
    10     # sometime it's -linux. We currently have only one noMMU linux
    11     # target, and it uses -linux, so let's just use that. Time
    12     # to fix that later...
    13     #    CT_TARGET_KERNEL="uclinux"
    14         CT_TARGET_KERNEL="linux"
    15     fi
    16 }
    17 
    18 # Download the kernel
    19 do_kernel_get() {
    20     if [    "${CT_KERNEL_LINUX_INSTALL}" = "y"  \
    21          -a "${CT_KERNEL_LINUX_CUSTOM}" != "y"  \
    22        ]; then
    23         CT_GetFile "linux-${CT_KERNEL_VERSION}" \
    24                    {ftp,http}://ftp.{de.,eu.,}kernel.org/pub/linux/kernel/v2.{6{,/testing},4,2}
    25     fi
    26 }
    27 
    28 # Extract kernel
    29 do_kernel_extract() {
    30     local tar_opt
    31     if [ "${CT_KERNEL_LINUX_INSTALL}" = "y" ]; then
    32         if [ "${CT_KERNEL_LINUX_CUSTOM}" = "y" ]; then
    33             # We extract the custom linux tree into a directory with a
    34             # well-known name, and strip the leading directory component
    35             # of the extracted pathes. This is needed because we do not
    36             # know the value for this first component, because it is a
    37             # _custom_ tree.
    38             # Also, we have to protect from partial extraction using the
    39             # .extracting and .extracted locks (not using .patching and
    40             # .patched as we are *not* patching that kernel).
    41 
    42             if [ -e "${CT_SRC_DIR}/.linux-custom.extracted" ]; then
    43                 CT_DoLog DEBUG "Custom linux kernel tree already extracted"
    44                 return 0
    45             fi
    46 
    47             CT_TestAndAbort "Custom kernel tree partially extracted. Remove before resuming" -f "${CT_SRC_DIR}/.linux-custom.extracting"
    48             CT_DoExecLog DEBUG touch "${CT_SRC_DIR}/.linux-custom.extracting"
    49             CT_DoExecLog DEBUG mkdir "${CT_SRC_DIR}/linux-custom"
    50 
    51             case "${CT_KERNEL_LINUX_CUSTOM_TARBALL}" in
    52                 *.tar.bz2)      tar_opt=-j;;
    53                 *.tar.gz|*.tgz) tar_opt=-z;;
    54                 *.tar)          ;;
    55                 *)              CT_Abort "Don't know how to handle '${CT_KERNEL_LINUX_CUSTOM_TARBALL}': unknown extension";;
    56             esac
    57             CT_DoLog EXTRA "Extracting custom linux kernel"
    58             CT_DoExecLog ALL tar x -C "${CT_SRC_DIR}/linux-custom"      \
    59                                  --strip-components 1 -v ${tar_opt}     \
    60                                  -f "${CT_KERNEL_LINUX_CUSTOM_TARBALL}"
    61 
    62             CT_DoExecLog ALL mv -v "${CT_SRC_DIR}/.linux-custom.extracting" "${CT_SRC_DIR}/.linux-custom.extracted"
    63         else
    64             CT_Extract "linux-${CT_KERNEL_VERSION}"
    65             CT_Patch "linux" "${CT_KERNEL_VERSION}"
    66         fi
    67     fi
    68 }
    69 
    70 # Wrapper to the actual headers install method
    71 do_kernel_headers() {
    72     CT_DoStep INFO "Installing kernel headers"
    73 
    74     if [ "${CT_KERNEL_LINUX_INSTALL}" = "y" ]; then
    75         do_kernel_install
    76     else
    77         do_kernel_custom
    78     fi
    79 
    80     CT_EndStep
    81 }
    82 
    83 # Install kernel headers using headers_install from kernel sources.
    84 do_kernel_install() {
    85     local kernel_path
    86 
    87     CT_DoLog DEBUG "Using kernel's headers_install"
    88 
    89     mkdir -p "${CT_BUILD_DIR}/build-kernel-headers"
    90 
    91     kernel_path="${CT_SRC_DIR}/linux-${CT_KERNEL_VERSION}"
    92     if [ "${CT_KERNEL_LINUX_CUSTOM}" = "y" ]; then
    93         kernel_path="${CT_SRC_DIR}/linux-custom"
    94     fi
    95     V_OPT="V=${CT_KERNEL_LINUX_VERBOSE_LEVEL}"
    96 
    97     CT_DoLog EXTRA "Installing kernel headers"
    98     CT_DoExecLog ALL                                    \
    99     make -C "${kernel_path}"                            \
   100          O="${CT_BUILD_DIR}/build-kernel-headers"       \
   101          ARCH=${CT_ARCH}                                \
   102          INSTALL_HDR_PATH="${CT_SYSROOT_DIR}/usr"       \
   103          ${V_OPT}                                       \
   104          headers_install
   105 
   106     if [ "${CT_KERNEL_LINUX_INSTALL_CHECK}" = "y" ]; then
   107         CT_DoLog EXTRA "Checking installed headers"
   108         CT_DoExecLog ALL                                    \
   109         make -C "${kernel_path}"                            \
   110              O="${CT_BUILD_DIR}/build-kernel-headers"       \
   111              ARCH=${CT_ARCH}                                \
   112              INSTALL_HDR_PATH="${CT_SYSROOT_DIR}/usr"       \
   113              ${V_OPT}                                       \
   114              headers_check
   115         find "${CT_SYSROOT_DIR}" -type f -name '.check*' -exec rm {} \;
   116     fi
   117 }
   118 
   119 # Use custom headers (most probably by using make headers_install in a
   120 # modified (read: customised) kernel tree, or using pre-2.6.18 headers, such
   121 # as 2.4). In this case, simply copy the headers in place
   122 do_kernel_custom() {
   123     local tar_opt
   124 
   125     CT_DoLog EXTRA "Installing custom kernel headers"
   126 
   127     mkdir -p "${CT_SYSROOT_DIR}/usr"
   128     cd "${CT_SYSROOT_DIR}/usr"
   129     if [ "${CT_KERNEL_LINUX_CUSTOM_IS_TARBALL}" = "y" ]; then
   130         case "${CT_KERNEL_LINUX_CUSTOM_PATH}" in
   131             *.tar)      ;;
   132             *.tgz)      tar_opt=--gzip;;
   133             *.tar.gz)   tar_opt=--gzip;;
   134             *.tar.bz2)  tar_opt=--bzip2;;
   135             *.tar.lzma) tar_opt=--lzma;;
   136         esac
   137         CT_DoExecLog ALL tar x ${tar_opt} -vf ${CT_KERNEL_LINUX_CUSTOM_PATH}
   138     else
   139         CT_DoExecLog ALL cp -rv "${CT_KERNEL_LINUX_CUSTOM_PATH}/include" .
   140     fi
   141 }