scripts/build/libc/newlib.sh
author Daniel Price <daniel.price@gmail.com>
Tue Nov 20 16:59:17 2012 -0800 (2012-11-20)
changeset 3126 333d3e40cbd1
parent 3094 07a87075fa2d
child 3161 3ecd4bbfecc5
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
mgl@1371
     1
# This file adds functions to build the Newlib C library
mgl@1467
     2
# Copyright 2009 DoréDevelopment
mgl@1371
     3
# Licensed under the GPL v2. See COPYING in the root of this package
mgl@1371
     4
#
mgl@1467
     5
# Edited by Martin Lund <mgl@doredevelopment.dk>
mgl@1371
     6
#
mgl@1371
     7
mgl@1371
     8
do_libc_get() {
yann@1930
     9
    local libc_src
yann@1930
    10
    local avr32headers_src
yann@1930
    11
mgl@1371
    12
    libc_src="ftp://sources.redhat.com/pub/newlib"
mgl@1373
    13
    avr32headers_src="http://dev.doredevelopment.dk/avr32-toolchain/sources"
yann@1593
    14
david@3094
    15
    if [ "${CT_LIBC_NEWLIB_CUSTOM}" = "y" ]; then
david@3094
    16
        CT_GetCustom "newlib" "${CT_LIBC_VERSION}"      \
david@3094
    17
                     "${CT_LIBC_NEWLIB_CUSTOM_LOCATION}"
yann@3095
    18
    else # ! custom location
yann@1593
    19
        CT_GetFile "newlib-${CT_LIBC_VERSION}" ${libc_src}
yann@3095
    20
    fi # ! custom location
mgl@1371
    21
mgl@1373
    22
    if [ "${CT_ATMEL_AVR32_HEADERS}" = "y" ]; then
mgl@1373
    23
        CT_GetFile "avr32headers" ${avr32headers_src}
mgl@1373
    24
    fi
mgl@1371
    25
}
mgl@1371
    26
mgl@1371
    27
do_libc_extract() {
david@3094
    28
    # If using custom directory location, nothing to do
yann@3095
    29
    if [    "${CT_LIBC_NEWLIB_CUSTOM}" != "y"            \
yann@3095
    30
         -a -d "${CT_SRC_DIR}/newlib-${CT_LIBC_VERSION}" ]; then
david@3094
    31
        return 0
david@3094
    32
    fi
david@3094
    33
yann@3095
    34
    CT_Extract "newlib-${CT_LIBC_VERSION}"
yann@3095
    35
    CT_Patch "newlib" "${CT_LIBC_VERSION}"
mgl@1371
    36
mgl@1373
    37
    if [ "${CT_ATMEL_AVR32_HEADERS}" = "y" ]; then
mgl@1373
    38
        CT_Extract "avr32headers"
mgl@1373
    39
    fi
mgl@1371
    40
}
mgl@1371
    41
mgl@1371
    42
do_libc_check_config() {
mgl@1371
    43
    :
mgl@1371
    44
}
mgl@1371
    45
mgl@1371
    46
do_libc_start_files() {
yann@2895
    47
    :
yann@2895
    48
}
yann@2895
    49
yann@2895
    50
do_libc() {
yann@2165
    51
    local -a newlib_opts
yann@2165
    52
mgl@1371
    53
    CT_DoStep INFO "Installing C library"
mgl@1371
    54
mgl@1371
    55
    mkdir -p "${CT_BUILD_DIR}/build-libc"
mgl@1371
    56
    cd "${CT_BUILD_DIR}/build-libc"
mgl@1371
    57
mgl@1371
    58
    CT_DoLog EXTRA "Configuring C library"
mgl@1371
    59
yann@2167
    60
    if [ "${CT_LIBC_NEWLIB_IO_C99FMT}" = "y" ]; then
yann@2167
    61
        newlib_opts+=( "--enable-newlib-io-c99-formats" )
yann@2167
    62
    else
yann@2167
    63
        newlib_opts+=( "--disable-newlib-io-c99-formats" )
yann@2167
    64
    fi
yann@2166
    65
    if [ "${CT_LIBC_NEWLIB_IO_LL}" = "y" ]; then
yann@2166
    66
        newlib_opts+=( "--enable-newlib-io-long-long" )
yann@2166
    67
    else
yann@2166
    68
        newlib_opts+=( "--disable-newlib-io-long-long" )
yann@2166
    69
    fi
yann@2165
    70
    if [ "${CT_LIBC_NEWLIB_IO_FLOAT}" = "y" ]; then
yann@2165
    71
        newlib_opts+=( "--enable-newlib-io-float" )
yann@2165
    72
        if [ "${CT_LIBC_NEWLIB_IO_LDBL}" = "y" ]; then
yann@2165
    73
            newlib_opts+=( "--enable-newlib-io-long-double" )
yann@2165
    74
        else
yann@2165
    75
            newlib_opts+=( "--disable-newlib-io-long-double" )
yann@2165
    76
        fi
yann@2165
    77
    else
yann@2165
    78
        newlib_opts+=( "--disable-newlib-io-float" )
yann@2165
    79
        newlib_opts+=( "--disable-newlib-io-long-double" )
yann@2165
    80
    fi
kpet@2647
    81
    if [ "${CT_LIBC_NEWLIB_DISABLE_SUPPLIED_SYSCALLS}" = "y" ]; then
kpet@2647
    82
        newlib_opts+=( "--disable-newlib-supplied-syscalls" )
kpet@2647
    83
    else
kpet@2647
    84
        newlib_opts+=( "--enable-newlib-supplied-syscalls" )
kpet@2647
    85
    fi
yann@2165
    86
zhenqiang@2783
    87
    [ "${CT_LIBC_NEWLIB_ENABLE_TARGET_OPTSPACE}" = "y" ] && newlib_opts+=("--enable-target-optspace")
zhenqiang@2783
    88
yann@1588
    89
    # Note: newlib handles the build/host/target a little bit differently
yann@1588
    90
    # than one would expect:
yann@1588
    91
    #   build  : not used
yann@1588
    92
    #   host   : the machine building newlib
yann@1588
    93
    #   target : the machine newlib runs on
yann@2352
    94
    CT_DoExecLog CFG                                    \
yann@1593
    95
    CC_FOR_BUILD="${CT_BUILD}-gcc"                      \
zhenqiang@2787
    96
    CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"             \
yann@1593
    97
    AR=${CT_TARGET}-ar                                  \
yann@1593
    98
    RANLIB=${CT_TARGET}-ranlib                          \
yann@3095
    99
    "${CT_SRC_DIR}/newlib-${CT_LIBC_VERSION}/configure" \
yann@1593
   100
        --host=${CT_BUILD}                              \
yann@1593
   101
        --target=${CT_TARGET}                           \
yann@2165
   102
        --prefix=${CT_PREFIX_DIR}                       \
zhenqiang@2781
   103
        "${newlib_opts[@]}"                             \
zhenqiang@2781
   104
        "${CT_LIBC_NEWLIB_EXTRA_CONFIG_ARRAY[@]}"
yann@1982
   105
mgl@1371
   106
    CT_DoLog EXTRA "Building C library"
yann@2275
   107
    CT_DoExecLog ALL make ${JOBSFLAGS}
mgl@1371
   108
mgl@1371
   109
    CT_DoLog EXTRA "Installing C library"
mgl@1371
   110
    CT_DoExecLog ALL make install install_root="${CT_SYSROOT_DIR}"
mgl@1371
   111
zhenqiang@2808
   112
    if [ "${CT_BUILD_MANUALS}" = "y" ]; then
zhenqiang@2808
   113
        local -a doc_dir="${CT_BUILD_DIR}/build-libc/${CT_TARGET}"
zhenqiang@2808
   114
zhenqiang@2808
   115
        CT_DoLog EXTRA "Building and installing the C library manual"
zhenqiang@2808
   116
        CT_DoExecLog ALL make pdf html
zhenqiang@2808
   117
zhenqiang@2808
   118
        # NEWLIB install-{pdf.html} fail for some versions
zhenqiang@2808
   119
        CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/share/doc/newlib"
zhenqiang@2808
   120
        CT_DoExecLog ALL cp -av "${doc_dir}/newlib/libc/libc.pdf"   \
zhenqiang@2808
   121
                                "${doc_dir}/newlib/libm/libm.pdf"   \
zhenqiang@2808
   122
                                "${doc_dir}/newlib/libc/libc.html"  \
zhenqiang@2808
   123
                                "${doc_dir}/newlib/libm/libm.html"  \
zhenqiang@2808
   124
                                "${CT_PREFIX_DIR}/share/doc/newlib"
zhenqiang@2808
   125
    fi
zhenqiang@2808
   126
mgl@1371
   127
    CT_EndStep
mgl@1371
   128
}
mgl@1371
   129
mgl@1371
   130
do_libc_finish() {
yann@1589
   131
    CT_DoStep INFO "Finishing C library"
mgl@1373
   132
    
mgl@1373
   133
    if [ "${CT_ATMEL_AVR32_HEADERS}" = "y" ]; then
yann@1589
   134
        CT_DoLog EXTRA "Installing Atmel's AVR32 headers"
mgl@1373
   135
        CT_DoExecLog ALL cp -r ${CT_SRC_DIR}/avr32headers "${CT_PREFIX_DIR}/${CT_TARGET}/include/avr32"
mgl@1373
   136
    fi
mgl@1373
   137
mgl@1373
   138
    CT_EndStep
mgl@1371
   139
}