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