scripts/build/libc/newlib.sh
author Johannes Stezenbach <js@sig21.net>
Tue Oct 30 00:22:25 2012 +0000 (2012-10-30)
changeset 3097 5c67476c7342
parent 3094 07a87075fa2d
child 3161 3ecd4bbfecc5
permissions -rw-r--r--
scripts/functions: fix endless loop in debug-shell with IO redirection

CT_DEBUG_INTERACTIVE is disabled when stdin, stdout or
stderr are redirected, but the check is only done at
the start of the build and doesn't catch when individual
build commands use redirection. When stdin is redirected
it will cause the debug shell to exit immediately, causing
and endless loop. Thus, save the stdin/our/err file handles
and restore them before invoking the debug shell.

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