scripts/build/kernel/linux.sh
author Daniel Price <daniel.price@gmail.com>
Tue Nov 20 16:59:17 2012 -0800 (2012-11-20)
changeset 3126 333d3e40cbd1
parent 3079 37831a33e07e
child 3204 2993e15fa6c5
permissions -rw-r--r--
scripts: refine static linking check to better guide the user

The current mechanism to check if static linking is possible, and the mesage
displayed on failure, can be puzzling to the unsuspecting user.

Also, the current implementation is not using the existing infrastructure,
and is thus difficult to enhance with new tests.

So, switch to using the standard CT_DoExecLog infra, and use four tests to
check for the host compiler:
- check we can run it
- check it can build a trivial program
- check it can statically link that program
- check if it statically link with libstdc++

That should cover most of the problems. Hopefully.

(At the same time, fix a typo in a comment)

Signed-off-by: Daniel Price <daniel.price@gmail.com>
[yann.morin.1998@free.fr: split original patch for self-contained changes]
[yann.morin.1998@free.fr: use steps to better see gcc's output]
[yann.morin.1998@free.fr: commit log]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Message-Id: <163f86b5216fc08c672a.1353459722@nipigon.dssd.com>
Patchwork-Id: 200536
     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         # Some no-mmu linux targets requires a -uclinux tuple (like m68k/cf),
    10         # while others must have a -linux tuple (like bfin).  Other targets
    11         # should be added here when someone starts to care about them.
    12         case "${CT_ARCH}" in
    13             blackfin)   CT_TARGET_KERNEL="linux" ;;
    14             m68k)       CT_TARGET_KERNEL="uclinux" ;;
    15             *)          CT_Abort "Unsupported no-mmu arch '${CT_ARCH}'"
    16         esac
    17     fi
    18 }
    19 
    20 # Download the kernel
    21 do_kernel_get() {
    22     local k_ver
    23     local custom_name
    24     local rel_dir
    25     local korg_base mirror_base
    26 
    27     if [ "${CT_KERNEL_LINUX_USE_CUSTOM_HEADERS}" = "y"  ]; then
    28         return 0
    29     fi
    30 
    31     if [ "${CT_KERNEL_LINUX_CUSTOM}" = "y" ]; then
    32         CT_GetCustom "linux" "${CT_KERNEL_VERSION}"     \
    33                      "${CT_KERNEL_LINUX_CUSTOM_LOCATION}"
    34     else # Not a custom tarball
    35         case "${CT_KERNEL_VERSION}" in
    36             2.6.*.*|3.*.*)
    37                 # 4-part versions (for 2.6 stables and long-terms), and
    38                 # 3-part versions (for 3.x.y stables and long-terms),
    39                 # we need to trash the last digit
    40                 k_ver="${CT_KERNEL_VERSION%.*}"
    41                 ;;
    42             2.6.*|3.*)
    43                 # 3-part version (for 2.6.x initial releases), and 2-part
    44                 # versions (for 3.x initial releases), use all of it
    45                 k_ver="${CT_KERNEL_VERSION}"
    46                 ;;
    47         esac
    48         case "${CT_KERNEL_VERSION}" in
    49             2.6.*)  rel_dir=v2.6;;
    50             3.*)    rel_dir=v3.x;;
    51         esac
    52         korg_base="http://ftp.kernel.org/pub/linux/kernel/${rel_dir}"
    53         CT_GetFile "linux-${CT_KERNEL_VERSION}"         \
    54                    "${korg_base}"                       \
    55                    "${korg_base}/longterm/v${k_ver}"    \
    56                    "${korg_base}/longterm"
    57     fi
    58 }
    59 
    60 # Extract kernel
    61 do_kernel_extract() {
    62     # If using a custom headers tree, nothing to do
    63     if [ "${CT_KERNEL_LINUX_USE_CUSTOM_HEADERS}" = "y" ]; then
    64         return 0
    65     fi
    66 
    67     # If using a custom directory location, nothing to do
    68     if [ "${CT_KERNEL_LINUX_CUSTOM}" = "y"    \
    69          -a -d "${CT_SRC_DIR}/linux-${CT_KERNEL_VERSION}" ]; then
    70         return 0
    71     fi
    72 
    73     # Otherwise, we're using either a mainstream tarball, or a custom
    74     # tarball; in either case, we need to extract
    75     CT_Extract "linux-${CT_KERNEL_VERSION}"
    76 
    77     # If using a custom tarball, no need to patch
    78     if [ "${CT_KERNEL_LINUX_CUSTOM}" = "y" ]; then
    79         return 0
    80     fi
    81     CT_Patch "linux" "${CT_KERNEL_VERSION}"
    82 }
    83 
    84 # Wrapper to the actual headers install method
    85 do_kernel_headers() {
    86     CT_DoStep INFO "Installing kernel headers"
    87 
    88     if [ "${CT_KERNEL_LINUX_USE_CUSTOM_HEADERS}" = "y" ]; then
    89         do_kernel_custom
    90     else
    91         do_kernel_install
    92     fi
    93 
    94     CT_EndStep
    95 }
    96 
    97 # Install kernel headers using headers_install from kernel sources.
    98 do_kernel_install() {
    99     local kernel_path
   100 
   101     CT_DoLog DEBUG "Using kernel's headers_install"
   102 
   103     mkdir -p "${CT_BUILD_DIR}/build-kernel-headers"
   104 
   105     kernel_path="${CT_SRC_DIR}/linux-${CT_KERNEL_VERSION}"
   106     if [ "${CT_KERNEL_LINUX_CUSTOM}" = "y" ]; then
   107         kernel_path="${CT_SRC_DIR}/linux-custom"
   108     fi
   109     V_OPT="V=${CT_KERNEL_LINUX_VERBOSE_LEVEL}"
   110 
   111     CT_DoLog EXTRA "Installing kernel headers"
   112     CT_DoExecLog ALL                                    \
   113     make -C "${kernel_path}"                            \
   114          O="${CT_BUILD_DIR}/build-kernel-headers"       \
   115          ARCH=${CT_ARCH}                                \
   116          INSTALL_HDR_PATH="${CT_SYSROOT_DIR}/usr"       \
   117          ${V_OPT}                                       \
   118          headers_install
   119 
   120     if [ "${CT_KERNEL_LINUX_INSTALL_CHECK}" = "y" ]; then
   121         CT_DoLog EXTRA "Checking installed headers"
   122         CT_DoExecLog ALL                                    \
   123         make -C "${kernel_path}"                            \
   124              O="${CT_BUILD_DIR}/build-kernel-headers"       \
   125              ARCH=${CT_ARCH}                                \
   126              INSTALL_HDR_PATH="${CT_SYSROOT_DIR}/usr"       \
   127              ${V_OPT}                                       \
   128              headers_check
   129     fi
   130 
   131     # Cleanup
   132     find "${CT_SYSROOT_DIR}" -type f                        \
   133                              \(    -name '.install'         \
   134                                 -o -name '..install.cmd'    \
   135                                 -o -name '.check'           \
   136                                 -o -name '..check.cmd'      \
   137                              \)                             \
   138                              -exec rm {} \;
   139 }
   140 
   141 # Use custom headers (most probably by using make headers_install in a
   142 # modified (read: customised) kernel tree, or using pre-2.6.18 headers, such
   143 # as 2.4). In this case, simply copy the headers in place
   144 do_kernel_custom() {
   145     local tar_opt
   146 
   147     CT_DoLog EXTRA "Installing custom kernel headers"
   148 
   149     mkdir -p "${CT_SYSROOT_DIR}/usr"
   150     cd "${CT_SYSROOT_DIR}/usr"
   151     if [ "${CT_KERNEL_LINUX_CUSTOM_IS_TARBALL}" = "y" ]; then
   152         case "${CT_KERNEL_LINUX_CUSTOM_PATH}" in
   153             *.tar)      ;;
   154             *.tgz)      tar_opt=--gzip;;
   155             *.tar.gz)   tar_opt=--gzip;;
   156             *.tar.bz2)  tar_opt=--bzip2;;
   157         esac
   158         CT_DoExecLog ALL tar x ${tar_opt} -vf ${CT_KERNEL_LINUX_CUSTOM_PATH}
   159     else
   160         CT_DoExecLog ALL cp -rv "${CT_KERNEL_LINUX_CUSTOM_PATH}/include" .
   161     fi
   162 }