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