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