scripts/build/libc/newlib.sh
author Martin Guy <martinwguy@gmail.com>
Sun Mar 31 04:07:38 2013 +0000 (2013-03-31)
changeset 3203 74fd467be5aa
parent 3186 fb0aa58be2c5
child 3229 b9bd01c4dc61
permissions -rw-r--r--
arch/avr32: Fix download of header files

This patch fixes the download of the avr32 headers in crosstool-ng by
fetching them directly from Atmel's web site instead of the now-broken URL
given by the original author of the avr32-header-fetching modification,
who fetched them from a copy on his own, now-defunct server.

It also adds the necessary logic to extract from a zip file, as that is
how the headers are packaged.

To configure it for avr32 after launching ct-ng menuconfig in an empty
directory:

Paths and misc options ->
Shell to use as CONFIG_SHELL = sh
Target options ->
Target Architecture = avr32
Toolchain options ->
Tuple's alias = avr32
Binary utilities ->
binutils version = 2.18a
C compiler
gcc version = 4.2.2
C-library
newlib version = 1.17.0
Enable IOs on long long = yes
Enable IOs on floats and doubles = yes
Disable the syscalls supplied with newlib = yes

CONFIG_SHELL is necessary to get round the "fragment: command not
found" bug when binutils-2.18 is configured using bash.

Prepared against crosstool-ng mercurial trunk on 31 March 2012.

Signed-off-by: Martin Guy <martinwguy@gmail.com>
[yann.morin.1998@free.fr: update bundles sample accordingly]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Message-Id: <CAL4-wQrg_NQ7jm-NCADqeyQr9twyhtx42OUGNThP6gWeqZc=kw@mail.gmail.com>
Patchwork-Id: 232612
     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="ftp://sourceware.org/pub/newlib"
    10     local avr32headers_src="http://www.atmel.com/Images"
    11           avr32headers_base="avr-headers-3.2.3.970"    # used below
    12     local avr32headers_ext=".zip"
    13 
    14     if [ "${CT_LIBC_NEWLIB_CUSTOM}" = "y" ]; then
    15         CT_GetCustom "newlib" "${CT_LIBC_VERSION}"      \
    16                      "${CT_LIBC_NEWLIB_CUSTOM_LOCATION}"
    17     else # ! custom location
    18         CT_GetFile "newlib-${CT_LIBC_VERSION}" ${libc_src}
    19     fi # ! custom location
    20 
    21     if [ "${CT_ATMEL_AVR32_HEADERS}" = "y" ]; then
    22         CT_GetFile ${avr32headers_base} ${avr32headers_ext} ${avr32headers_src}
    23     fi
    24 }
    25 
    26 do_libc_extract() {
    27     # If using custom directory location, nothing to do
    28     if [    "${CT_LIBC_NEWLIB_CUSTOM}" != "y"            \
    29          -a -d "${CT_SRC_DIR}/newlib-${CT_LIBC_VERSION}" ]; then
    30         return 0
    31     fi
    32 
    33     CT_Extract "newlib-${CT_LIBC_VERSION}"
    34     CT_Patch "newlib" "${CT_LIBC_VERSION}"
    35 
    36     if [ "${CT_ATMEL_AVR32_HEADERS}" = "y" ]; then
    37         # The avr32header zip file extracts to avr32/*.h
    38         # Put that in its directory, the same as normal tarballs
    39         CT_Extract ${avr32headers_base} -d ${CT_SRC_DIR}/${avr32headers_base}
    40     fi
    41 }
    42 
    43 do_libc_check_config() {
    44     :
    45 }
    46 
    47 do_libc_start_files() {
    48     if [ "${CT_ATMEL_AVR32_HEADERS}" = "y" ]; then
    49         CT_DoStep INFO "Installing C library headers & start files"
    50 
    51         CT_DoLog EXTRA "Installing Atmel's AVR32 headers"
    52         CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/${CT_TARGET}/include"
    53         CT_DoExecLog ALL cp -r "${CT_SRC_DIR}/${avr32headers_base}/avr32"     \
    54                                "${CT_PREFIX_DIR}/${CT_TARGET}/include/"
    55 
    56         CT_EndStep
    57     fi
    58 }
    59 
    60 do_libc() {
    61     local -a newlib_opts
    62 
    63     CT_DoStep INFO "Installing C library"
    64 
    65     mkdir -p "${CT_BUILD_DIR}/build-libc"
    66     cd "${CT_BUILD_DIR}/build-libc"
    67 
    68     CT_DoLog EXTRA "Configuring C library"
    69 
    70     if [ "${CT_LIBC_NEWLIB_IO_C99FMT}" = "y" ]; then
    71         newlib_opts+=( "--enable-newlib-io-c99-formats" )
    72     else
    73         newlib_opts+=( "--disable-newlib-io-c99-formats" )
    74     fi
    75     if [ "${CT_LIBC_NEWLIB_IO_LL}" = "y" ]; then
    76         newlib_opts+=( "--enable-newlib-io-long-long" )
    77     else
    78         newlib_opts+=( "--disable-newlib-io-long-long" )
    79     fi
    80     if [ "${CT_LIBC_NEWLIB_IO_FLOAT}" = "y" ]; then
    81         newlib_opts+=( "--enable-newlib-io-float" )
    82         if [ "${CT_LIBC_NEWLIB_IO_LDBL}" = "y" ]; then
    83             newlib_opts+=( "--enable-newlib-io-long-double" )
    84         else
    85             newlib_opts+=( "--disable-newlib-io-long-double" )
    86         fi
    87     else
    88         newlib_opts+=( "--disable-newlib-io-float" )
    89         newlib_opts+=( "--disable-newlib-io-long-double" )
    90     fi
    91     if [ "${CT_LIBC_NEWLIB_DISABLE_SUPPLIED_SYSCALLS}" = "y" ]; then
    92         newlib_opts+=( "--disable-newlib-supplied-syscalls" )
    93     else
    94         newlib_opts+=( "--enable-newlib-supplied-syscalls" )
    95     fi
    96 
    97     [ "${CT_LIBC_NEWLIB_ENABLE_TARGET_OPTSPACE}" = "y" ] && newlib_opts+=("--enable-target-optspace")
    98 
    99     # Note: newlib handles the build/host/target a little bit differently
   100     # than one would expect:
   101     #   build  : not used
   102     #   host   : the machine building newlib
   103     #   target : the machine newlib runs on
   104     CT_DoExecLog CFG                                    \
   105     CC_FOR_BUILD="${CT_BUILD}-gcc"                      \
   106     CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"             \
   107     AR=${CT_TARGET}-ar                                  \
   108     RANLIB=${CT_TARGET}-ranlib                          \
   109     "${CT_SRC_DIR}/newlib-${CT_LIBC_VERSION}/configure" \
   110         --host=${CT_BUILD}                              \
   111         --target=${CT_TARGET}                           \
   112         --prefix=${CT_PREFIX_DIR}                       \
   113         "${newlib_opts[@]}"                             \
   114         "${CT_LIBC_NEWLIB_EXTRA_CONFIG_ARRAY[@]}"
   115 
   116     CT_DoLog EXTRA "Building C library"
   117     CT_DoExecLog ALL make ${JOBSFLAGS}
   118 
   119     CT_DoLog EXTRA "Installing C library"
   120     CT_DoExecLog ALL make install install_root="${CT_SYSROOT_DIR}"
   121 
   122     if [ "${CT_BUILD_MANUALS}" = "y" ]; then
   123         local -a doc_dir="${CT_BUILD_DIR}/build-libc/${CT_TARGET}"
   124 
   125         CT_DoLog EXTRA "Building and installing the C library manual"
   126         CT_DoExecLog ALL make pdf html
   127 
   128         # NEWLIB install-{pdf.html} fail for some versions
   129         CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/share/doc/newlib"
   130         CT_DoExecLog ALL cp -av "${doc_dir}/newlib/libc/libc.pdf"   \
   131                                 "${doc_dir}/newlib/libm/libm.pdf"   \
   132                                 "${doc_dir}/newlib/libc/libc.html"  \
   133                                 "${doc_dir}/newlib/libm/libm.html"  \
   134                                 "${CT_PREFIX_DIR}/share/doc/newlib"
   135     fi
   136 
   137     CT_EndStep
   138 }