scripts/build/kernel/linux.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Jan 14 18:32:38 2011 +0100 (2011-01-14)
changeset 2264 1452840382bb
parent 2228 aa02b51ce928
child 2265 1e73ceb6ecb8
permissions -rw-r--r--
kernel/linux: longterm kernel location changed

The location of the longterm Linux kernels on FTP has changed.
Here is a simple (but not very versatile) fix.

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