scripts/build/kernel/linux.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Aug 02 18:26:53 2011 +0200 (2011-08-02)
changeset 2592 4908eb2b6f17
parent 2265 1e73ceb6ecb8
child 2603 461b9c476104
child 2685 86010f887870
permissions -rw-r--r--
scripts/functions: cvs retrieval first tries the mirror for tarballs

The cvs download helper looks for the local tarballs dir to see if it
can find a pre-downloaded tarball, and if it does not find it, does
the actual fetch to upstream via cvs.

In the process, it does not even try to get a tarball from the local
mirror, which can be useful if the mirror has been pre-populated
manually (or with a previously downloaded tree).

Fake a tarball get with the standard tarball-download helper, but
without specifying any upstream URL, which makes the helper directly
try the LAN mirror.

Of course, if no mirror is specified, no URL wil be available, and
the standard cvs retrieval will kick in.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
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@2264
    20
    local k_ver
yann@1990
    21
    if [    "${CT_KERNEL_LINUX_INSTALL}" = "y"  \
yann@1990
    22
         -a "${CT_KERNEL_LINUX_CUSTOM}" != "y"  \
yann@1990
    23
       ]; then
yann@2264
    24
        case "${CT_KERNEL_VERSION}" in
yann@2567
    25
            2.6.*.*|3.*.*)
yann@2567
    26
                # 4-part versions (for 2.6 stables and long-terms), and
yann@2567
    27
                # 3-part versions (for 3.x.y stables and long-terms),
yann@2567
    28
                # we need to trash the last digit
yann@2264
    29
                k_ver="${CT_KERNEL_VERSION%.*}"
yann@2264
    30
                ;;
yann@2567
    31
            2.6.*|3.*)
yann@2567
    32
                # 3-part version (for 2.6.x initial releases), and 2-part
yann@2567
    33
                # versions (for 3.x initial releases), use all of it
yann@2264
    34
                k_ver="${CT_KERNEL_VERSION}"
yann@2264
    35
                ;;
yann@2264
    36
        esac
yann@2567
    37
        CT_GetFile "linux-${CT_KERNEL_VERSION}"                                             \
yann@2567
    38
                   http://ftp.{de.,eu.,}kernel.org/pub/linux/kernel/v2.6                    \
yann@2567
    39
                   http://ftp.{de.,eu.,}kernel.org/pub/linux/kernel/v3.0                    \
yann@2567
    40
                   http://ftp.{de.,eu.,}kernel.org/pub/linux/kernel/v2.6/longterm/v${k_ver} \
yann@2567
    41
                   http://ftp.{de.,eu.,}kernel.org/pub/linux/kernel/v3.0/longterm/v${k_ver}
yann@1345
    42
    fi
yann@1345
    43
}
yann@1345
    44
yann@1345
    45
# Extract kernel
yann@1345
    46
do_kernel_extract() {
yann@1990
    47
    local tar_opt
yann@1989
    48
    if [ "${CT_KERNEL_LINUX_INSTALL}" = "y" ]; then
yann@1990
    49
        if [ "${CT_KERNEL_LINUX_CUSTOM}" = "y" ]; then
yann@1990
    50
            # We extract the custom linux tree into a directory with a
yann@1990
    51
            # well-known name, and strip the leading directory component
yann@1990
    52
            # of the extracted pathes. This is needed because we do not
yann@1990
    53
            # know the value for this first component, because it is a
yann@1990
    54
            # _custom_ tree.
yann@1990
    55
            # Also, we have to protect from partial extraction using the
yann@1990
    56
            # .extracting and .extracted locks (not using .patching and
yann@1990
    57
            # .patched as we are *not* patching that kernel).
yann@1990
    58
yann@1990
    59
            if [ -e "${CT_SRC_DIR}/.linux-custom.extracted" ]; then
yann@1990
    60
                CT_DoLog DEBUG "Custom linux kernel tree already extracted"
yann@1990
    61
                return 0
yann@1990
    62
            fi
yann@1990
    63
yann@1990
    64
            CT_TestAndAbort "Custom kernel tree partially extracted. Remove before resuming" -f "${CT_SRC_DIR}/.linux-custom.extracting"
yann@1990
    65
            CT_DoExecLog DEBUG touch "${CT_SRC_DIR}/.linux-custom.extracting"
yann@1990
    66
            CT_DoExecLog DEBUG mkdir "${CT_SRC_DIR}/linux-custom"
yann@1990
    67
yann@1990
    68
            case "${CT_KERNEL_LINUX_CUSTOM_TARBALL}" in
yann@1990
    69
                *.tar.bz2)      tar_opt=-j;;
yann@1990
    70
                *.tar.gz|*.tgz) tar_opt=-z;;
yann@1990
    71
                *.tar)          ;;
yann@1990
    72
                *)              CT_Abort "Don't know how to handle '${CT_KERNEL_LINUX_CUSTOM_TARBALL}': unknown extension";;
yann@1990
    73
            esac
yann@1990
    74
            CT_DoLog EXTRA "Extracting custom linux kernel"
yann@1990
    75
            CT_DoExecLog ALL tar x -C "${CT_SRC_DIR}/linux-custom"      \
yann@1990
    76
                                 --strip-components 1 -v ${tar_opt}     \
yann@1990
    77
                                 -f "${CT_KERNEL_LINUX_CUSTOM_TARBALL}"
yann@1990
    78
yann@1990
    79
            CT_DoExecLog ALL mv -v "${CT_SRC_DIR}/.linux-custom.extracting" "${CT_SRC_DIR}/.linux-custom.extracted"
yann@1990
    80
        else
yann@1990
    81
            CT_Extract "linux-${CT_KERNEL_VERSION}"
yann@1990
    82
            CT_Patch "linux" "${CT_KERNEL_VERSION}"
yann@1990
    83
        fi
yann@1345
    84
    fi
yann@1345
    85
}
yann@1345
    86
yann@1345
    87
# Wrapper to the actual headers install method
yann@1345
    88
do_kernel_headers() {
yann@1345
    89
    CT_DoStep INFO "Installing kernel headers"
yann@1345
    90
yann@1989
    91
    if [ "${CT_KERNEL_LINUX_INSTALL}" = "y" ]; then
yann@1989
    92
        do_kernel_install
yann@1989
    93
    else
yann@1345
    94
        do_kernel_custom
yann@1345
    95
    fi
yann@1345
    96
yann@1345
    97
    CT_EndStep
yann@1345
    98
}
yann@1345
    99
yann@1345
   100
# Install kernel headers using headers_install from kernel sources.
yann@1345
   101
do_kernel_install() {
yann@1990
   102
    local kernel_path
yann@1990
   103
yann@1345
   104
    CT_DoLog DEBUG "Using kernel's headers_install"
yann@1345
   105
yann@1345
   106
    mkdir -p "${CT_BUILD_DIR}/build-kernel-headers"
yann@1345
   107
yann@1990
   108
    kernel_path="${CT_SRC_DIR}/linux-${CT_KERNEL_VERSION}"
yann@1990
   109
    if [ "${CT_KERNEL_LINUX_CUSTOM}" = "y" ]; then
yann@1990
   110
        kernel_path="${CT_SRC_DIR}/linux-custom"
yann@1990
   111
    fi
yann@1345
   112
    V_OPT="V=${CT_KERNEL_LINUX_VERBOSE_LEVEL}"
yann@1345
   113
yann@1345
   114
    CT_DoLog EXTRA "Installing kernel headers"
yann@1345
   115
    CT_DoExecLog ALL                                    \
yann@1990
   116
    make -C "${kernel_path}"                            \
yann@1990
   117
         O="${CT_BUILD_DIR}/build-kernel-headers"       \
yann@1746
   118
         ARCH=${CT_ARCH}                                \
yann@1345
   119
         INSTALL_HDR_PATH="${CT_SYSROOT_DIR}/usr"       \
yann@1345
   120
         ${V_OPT}                                       \
yann@1345
   121
         headers_install
yann@1345
   122
yann@1345
   123
    if [ "${CT_KERNEL_LINUX_INSTALL_CHECK}" = "y" ]; then
yann@1345
   124
        CT_DoLog EXTRA "Checking installed headers"
yann@1345
   125
        CT_DoExecLog ALL                                    \
yann@1990
   126
        make -C "${kernel_path}"                            \
yann@1990
   127
             O="${CT_BUILD_DIR}/build-kernel-headers"       \
yann@1746
   128
             ARCH=${CT_ARCH}                                \
yann@1345
   129
             INSTALL_HDR_PATH="${CT_SYSROOT_DIR}/usr"       \
yann@1345
   130
             ${V_OPT}                                       \
yann@1345
   131
             headers_check
yann@1345
   132
    fi
bryanhundven@2228
   133
bryanhundven@2228
   134
    # Cleanup
bryanhundven@2228
   135
    find "${CT_SYSROOT_DIR}" -type f                        \
bryanhundven@2228
   136
                             \(    -name '.install'         \
bryanhundven@2228
   137
                                -o -name '..install.cmd'    \
bryanhundven@2228
   138
                                -o -name '.check'           \
bryanhundven@2228
   139
                                -o -name '..check.cmd'      \
bryanhundven@2228
   140
                             \)                             \
bryanhundven@2228
   141
                             -exec rm {} \;
yann@1345
   142
}
yann@1345
   143
yann@1345
   144
# Use custom headers (most probably by using make headers_install in a
yann@1345
   145
# modified (read: customised) kernel tree, or using pre-2.6.18 headers, such
yann@1345
   146
# as 2.4). In this case, simply copy the headers in place
yann@1345
   147
do_kernel_custom() {
yann@1345
   148
    local tar_opt
yann@1345
   149
yann@1345
   150
    CT_DoLog EXTRA "Installing custom kernel headers"
yann@1345
   151
yann@1345
   152
    mkdir -p "${CT_SYSROOT_DIR}/usr"
yann@1345
   153
    cd "${CT_SYSROOT_DIR}/usr"
yann@1345
   154
    if [ "${CT_KERNEL_LINUX_CUSTOM_IS_TARBALL}" = "y" ]; then
yann@1345
   155
        case "${CT_KERNEL_LINUX_CUSTOM_PATH}" in
yann@1345
   156
            *.tar)      ;;
yann@1345
   157
            *.tgz)      tar_opt=--gzip;;
yann@1345
   158
            *.tar.gz)   tar_opt=--gzip;;
yann@1345
   159
            *.tar.bz2)  tar_opt=--bzip2;;
yann@1345
   160
            *.tar.lzma) tar_opt=--lzma;;
yann@1345
   161
        esac
yann@1345
   162
        CT_DoExecLog ALL tar x ${tar_opt} -vf ${CT_KERNEL_LINUX_CUSTOM_PATH}
yann@1345
   163
    else
yann@1345
   164
        CT_DoExecLog ALL cp -rv "${CT_KERNEL_LINUX_CUSTOM_PATH}/include" .
yann@1345
   165
    fi
yann@1345
   166
}