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