scripts/build/kernel_linux.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jul 27 14:28:36 2008 +0000 (2008-07-27)
branch1.2
changeset 739 8ebf5ea601d8
parent 523 010f6f4e4dd6
permissions -rw-r--r--
Backport #876 from trunk:
Re-enable the restart functionality by removing some variables from the saved environment.

/branches/1.2/scripts/functions | 16 10 6 0 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
     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 do_print_filename() {
     6     [ "${CT_KERNEL}" = "linux" ] || return 0
     7     case "${CT_KERNEL_LINUX_HEADERS_SANITISED}" in
     8         y)  echo "linux-libc-headers-${CT_KERNEL_VERSION}";;
     9         *)  echo "linux-${CT_KERNEL_VERSION}";;
    10     esac
    11 }
    12 
    13 # Download the kernel
    14 do_kernel_get() {
    15     if [ "${CT_KERNEL_LINUX_HEADERS_USE_CUSTOM_DIR}" != "y" ]; then
    16         CT_GetFile "${CT_KERNEL_FILE}"                                                  \
    17                    {ftp,http}://ftp.kernel.org/pub/linux/kernel/v2.{6{,/testing},4,2}   \
    18                    http://ep09.pld-linux.org/~mmazur/linux-libc-headers
    19     fi
    20     return 0
    21 }
    22 
    23 # Extract kernel
    24 do_kernel_extract() {
    25     if [ "${CT_KERNEL_LINUX_HEADERS_USE_CUSTOM_DIR}" != "y" ]; then
    26         CT_ExtractAndPatch "${CT_KERNEL_FILE}"
    27     fi
    28     return 0
    29 }
    30 
    31 # Check kernel configuration
    32 do_kernel_check_config() {
    33     # Only the copied or sanitised headers need a config file.
    34     # Pre-existing headers as well as headers_install don't.
    35     if [ "${CT_KERNEL_LINUX_NEEDS_CONFIG}" = "y"        \
    36          -a \( -z "${CT_KERNEL_LINUX_CONFIG_FILE}"      \
    37                -o ! -r "${CT_KERNEL_LINUX_CONFIG_FILE}" \
    38             \)                                          \
    39        ]; then
    40         CT_DoLog WARN "You did not provide a kernel configuration file!"
    41         CT_DoLog WARN "I will try to generate one for you, but beware!"
    42 
    43         CT_DoStep INFO "Building a default configuration file for linux kernel"
    44 
    45         mkdir -p "${CT_BUILD_DIR}/build-kernel-defconfig"
    46         cd "${CT_BUILD_DIR}/build-kernel-defconfig"
    47         make -C "${CT_SRC_DIR}/${CT_KERNEL_FILE}" O=$(pwd)  \
    48              ARCH=${CT_KERNEL_ARCH} defconfig               2>&1 |CT_DoLog ALL
    49 
    50         CT_KERNEL_LINUX_CONFIG_FILE="$(pwd)/.config"
    51 
    52         CT_EndStep
    53     fi
    54 }
    55 
    56 # Wrapper to the actual headers install method
    57 do_kernel_headers() {
    58     CT_DoStep INFO "Installing kernel headers"
    59 
    60     # Special case when using pre-installed headers
    61     if [ "${CT_KERNEL_LINUX_HEADERS_USE_CUSTOM_DIR}" = "y" ]; then
    62         do_kernel_preinstalled
    63     else
    64         # We need to enter this directory to find the kernel version strings
    65         cd "${CT_SRC_DIR}/${CT_KERNEL_FILE}"
    66         if [ "${CT_KERNEL_LINUX_HEADERS_SANITISED}" != "y" ]; then
    67             k_version=$(awk '/^VERSION =/ { print $3 }' Makefile)
    68             k_patchlevel=$(awk '/^PATCHLEVEL =/ { print $3 }' Makefile)
    69             k_sublevel=$(awk '/^SUBLEVEL =/ { print $3 }' Makefile)
    70             k_extraversion=$(awk '/^EXTRAVERSION =/ { print $3 }' Makefile)
    71         else
    72             k_version=$(echo "${CT_KERNEL_VERSION}." |cut -d . -f 1)
    73             k_patchlevel=$(echo "${CT_KERNEL_VERSION}." |cut -d . -f 2)
    74             k_sublevel=$(echo "${CT_KERNEL_VERSION}." |cut -d . -f 3)
    75             k_extraversion=$(echo "${CT_KERNEL_VERSION}." |cut -d . -f 4)
    76         fi
    77 
    78         case "${k_version}.${k_patchlevel}" in
    79             2.2|2.4|2.6) ;;
    80             *)  CT_Abort "Unsupported kernel version 'linux-${k_version}.${k_patchlevel}'.";;
    81         esac
    82 
    83         # Kernel version that support verbosity will use this, others will ignore it:
    84         V_OPT="V=${CT_KERNEL_LINUX_VERBOSE_LEVEL}"
    85 
    86         if [ "${CT_KERNEL_LINUX_HEADERS_INSTALL}" = "y" ]; then
    87             do_kernel_install
    88         elif [ "${CT_KERNEL_LINUX_HEADERS_SANITISED}" = "y" ]; then
    89             do_kernel_sanitised
    90         else [ "${CT_KERNEL_LINUX_HEADERS_COPY}" = "y" ];
    91             do_kernel_copy
    92         fi
    93     fi
    94 
    95     CT_EndStep
    96 }
    97 
    98 # Install kernel headers using headers_install from kernel sources.
    99 do_kernel_install() {
   100     CT_DoLog DEBUG "Using kernel's headers_install"
   101 
   102     mkdir -p "${CT_BUILD_DIR}/build-kernel-headers"
   103     cd "${CT_BUILD_DIR}/build-kernel-headers"
   104 
   105     case "${k_version}.${k_patchlevel}" in
   106         2.6) [ ${k_sublevel} -ge 18 ] || CT_Abort "Kernel version >= 2.6.18 is needed to install kernel headers.";;
   107         *)   CT_Abort "Kernel version >= 2.6.18 is needed to install kernel headers.";;
   108     esac
   109 
   110     CT_DoLog EXTRA "Installing kernel headers"
   111     CT_DoExecLog ALL                                \
   112     make -C "${CT_SRC_DIR}/${CT_KERNEL_FILE}"       \
   113          O=$(pwd)                                   \
   114          ARCH=${CT_KERNEL_ARCH}                     \
   115          INSTALL_HDR_PATH="${CT_SYSROOT_DIR}/usr"   \
   116          ${V_OPT}                                   \
   117          headers_install
   118 
   119     if [ "${CT_KERNEL_LINUX_HEADERS_INSTALL_CHECK}" = "y" ]; then
   120         CT_DoLog EXTRA "Checking installed headers"
   121         CT_DoExecLog ALL                                \
   122         make -C "${CT_SRC_DIR}/${CT_KERNEL_FILE}"       \
   123              O=$(pwd)                                   \
   124              ARCH=${CT_KERNEL_ARCH}                     \
   125              INSTALL_HDR_PATH="${CT_SYSROOT_DIR}/usr"   \
   126              ${V_OPT}                                   \
   127              headers_check
   128         find "${CT_SYSROOT_DIR}" -type f -name '.check*' -exec rm {} \;
   129     fi
   130 }
   131 
   132 # Install kernel headers from oldish Mazur's sanitised headers.
   133 do_kernel_sanitised() {
   134     CT_DoLog EXTRA "Copying sanitised headers"
   135     cd "${CT_SRC_DIR}/${CT_KERNEL_FILE}"
   136     cp -rv include/linux "${CT_HEADERS_DIR}" 2>&1 |CT_DoLog ALL
   137     cp -rv "include/asm-${CT_KERNEL_ARCH}" "${CT_HEADERS_DIR}/asm" 2>&1 |CT_DoLog ALL
   138 }
   139 
   140 # Install kernel headers by plain copy.
   141 do_kernel_copy() {
   142     CT_DoLog DEBUG "Copying plain kernel headers"
   143     CT_DoLog WARN "You are using plain kernel headers. You really shouldn't do that."
   144     CT_DoLog WARN "You'd be better off by using installed headers (or sanitised headers)."
   145 
   146     # 2.2 and 2.4 don't support building out-of-tree. 2.6 does.
   147     CT_DoLog EXTRA "Preparing kernel headers"
   148     case "${k_version}.${k_patchlevel}" in
   149         2.2|2.4) cd "${CT_SRC_DIR}/${CT_KERNEL_FILE}"
   150                  cp "${CT_KERNEL_LINUX_CONFIG_FILE}" .config
   151                  CT_DoYes "" |make ARCH=${CT_KERNEL_ARCH} oldconfig
   152                  # 2.4 doesn't follow V=# for verbosity... :-(
   153                  make ARCH=${CT_KERNEL_ARCH} symlinks include/linux/version.h
   154                  ;;
   155         2.6)     mkdir -p "${CT_BUILD_DIR}/build-kernel-headers"
   156                  cd "${CT_BUILD_DIR}/build-kernel-headers"
   157                  cp "${CT_KERNEL_LINUX_CONFIG_FILE}" .config
   158                  CT_DoYes "" |make -C "${CT_SRC_DIR}/${CT_KERNEL_FILE}"         \
   159                                    O=$(pwd) ${V_OPT} ARCH=${CT_KERNEL_ARCH}     \
   160                                    oldconfig
   161                  case "${CT_KERNEL_ARCH}" in
   162                      sh*)        # sh does secret stuff in 'make prepare' that can't be
   163                                  # triggered separately, but happily, it doesn't use
   164                                  # target gcc, so we can use it.
   165                                  # Update: this fails on 2.6.11, as it installs
   166                                  # elfconfig.h, which requires target compiler :-(
   167                                  make ${PARALLELMFLAGS}                 \
   168                                       ARCH=${CT_KERNEL_ARCH} ${V_OPT}   \
   169                                       prepare include/linux/version.h
   170                                  ;;
   171                      arm*|cris*) make ${PARALLELMFLAGS}                     \
   172                                       ARCH=${CT_KERNEL_ARCH} ${V_OPT}       \
   173                                       include/asm include/linux/version.h   \
   174                                       include/asm-${CT_KERNEL_ARCH}/.arch
   175                                  ;;
   176                      mips*)      # for linux-2.6, 'make prepare' for mips doesn't 
   177                                  # actually create any symlinks.  Hope generic is ok.
   178                                  # Note that glibc ignores all -I flags passed in CFLAGS,
   179                                  # so you have to use -isystem.
   180                                  make ${PARALLELMFLAGS}                 \
   181                                       ARCH=${CT_KERNEL_ARCH} ${V_OPT}   \
   182                                       include/asm include/linux/version.h
   183                                  TARGET_CFLAGS="${TARGET_CFLAGS} -isystem ${LINUX_HEADER_DIR}/include/asm-mips/mach-generic"
   184                                  ;;
   185                      *)          make ${PARALLELMFLAGS}                 \
   186                                       ARCH=${CT_KERNEL_ARCH} ${V_OPT}   \
   187                                       include/asm include/linux/version.h
   188                                  ;;
   189                  esac
   190                  ;;
   191     esac 2>&1 |CT_DoLog ALL
   192 
   193     CT_DoLog EXTRA "Copying kernel headers"
   194     cp -rv include/asm-generic "${CT_HEADERS_DIR}/asm-generic" 2>&1 |CT_DoLog ALL
   195     cp -rv include/linux "${CT_HEADERS_DIR}" 2>&1 |CT_DoLog ALL
   196     cp -rv include/asm-${CT_KERNEL_ARCH} "${CT_HEADERS_DIR}/asm" 2>&1 |CT_DoLog ALL
   197 }
   198 
   199 # Use preinstalled headers (most probably by using make headers_install in a
   200 # modified (read: customised) kernel tree). In this case, simply copy
   201 # the headers in place
   202 do_kernel_preinstalled() {
   203     CT_DoLog EXTRA "Copying preinstalled kernel headers"
   204 
   205     mkdir -p "${CT_SYSROOT_DIR}/usr"
   206     cd "${CT_KERNEL_LINUX_HEADERS_CUSTOM_DIR}"
   207     cp -rv include "${CT_SYSROOT_DIR}/usr" 2>&1 |CT_DoLog ALL
   208 }