scripts/build/kernel_linux.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Feb 17 22:08:06 2008 +0000 (2008-02-17)
changeset 431 8bde4c6ea47a
parent 164 e78c0b2bc057
child 486 92f6149c4275
permissions -rw-r--r--
Robert P. J. DAY says:

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