scripts/build/kernel/linux.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Jan 22 23:20:18 2011 +0100 (2011-01-22)
changeset 2305 2ed26c646568
parent 2264 1452840382bb
child 2567 92e02b41d2d1
permissions -rw-r--r--
scripts: create the makeinfo wrapper before we set PATH

If we set PATH to the tools wrappers before we create the
makeinfo wrapper, then we may well wrap an existing wrapper
from a previous run.

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