scripts/build/libc/newlib.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jul 17 18:01:28 2011 +0200 (2011-07-17)
changeset 2895 86ea5204e9ce
parent 2808 8ad3ba55b973
child 3094 07a87075fa2d
permissions -rw-r--r--
libc/newlib: build newlib in the proper step

Currently, newlib is built in the start_file step, which is wrong, but was
needed when the baremetal integration was... well, 'unfinished'.

Now that we build the baremetal compiler from the final cc step, and a
proper core gcc in pass-1 and pass-2, we can move the newlib build to the
step do_libc, where it belongs.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
     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 libc_newlib_version() {
     9     if [ -z "${CT_LIBC_NEWLIB_CVS}" ]; then
    10         echo "${CT_LIBC_VERSION}"
    11     else
    12         echo "cvs${CT_LIBC_VERSION:+-${CT_LIBC_VERSION}}"
    13     fi
    14 }
    15 
    16 do_libc_get() {
    17     local libc_src
    18     local avr32headers_src
    19 
    20     libc_src="ftp://sources.redhat.com/pub/newlib"
    21     avr32headers_src="http://dev.doredevelopment.dk/avr32-toolchain/sources"
    22 
    23     if [ -z "${CT_LIBC_NEWLIB_CVS}" ]; then
    24         CT_GetFile "newlib-${CT_LIBC_VERSION}" ${libc_src}
    25     else
    26         CT_GetCVS "newlib-$(libc_newlib_version)"                   \
    27                   ":pserver:anoncvs@sources.redhat.com:/cvs/src"    \
    28                   "newlib"                                          \
    29                   "${CT_LIBC_VERSION}"                              \
    30                   "newlib-$(libc_newlib_version)=src"
    31     fi
    32 
    33     if [ "${CT_ATMEL_AVR32_HEADERS}" = "y" ]; then
    34         CT_GetFile "avr32headers" ${avr32headers_src}
    35     fi
    36 }
    37 
    38 do_libc_extract() {
    39     CT_Extract "newlib-$(libc_newlib_version)"
    40     CT_Patch "newlib" "$(libc_newlib_version)"
    41 
    42     if [ "${CT_ATMEL_AVR32_HEADERS}" = "y" ]; then
    43         CT_Extract "avr32headers"
    44     fi
    45 }
    46 
    47 do_libc_check_config() {
    48     :
    49 }
    50 
    51 do_libc_start_files() {
    52     :
    53 }
    54 
    55 do_libc() {
    56     local -a newlib_opts
    57 
    58     CT_DoStep INFO "Installing C library"
    59 
    60     mkdir -p "${CT_BUILD_DIR}/build-libc"
    61     cd "${CT_BUILD_DIR}/build-libc"
    62 
    63     CT_DoLog EXTRA "Configuring C library"
    64 
    65     if [ "${CT_LIBC_NEWLIB_IO_C99FMT}" = "y" ]; then
    66         newlib_opts+=( "--enable-newlib-io-c99-formats" )
    67     else
    68         newlib_opts+=( "--disable-newlib-io-c99-formats" )
    69     fi
    70     if [ "${CT_LIBC_NEWLIB_IO_LL}" = "y" ]; then
    71         newlib_opts+=( "--enable-newlib-io-long-long" )
    72     else
    73         newlib_opts+=( "--disable-newlib-io-long-long" )
    74     fi
    75     if [ "${CT_LIBC_NEWLIB_IO_FLOAT}" = "y" ]; then
    76         newlib_opts+=( "--enable-newlib-io-float" )
    77         if [ "${CT_LIBC_NEWLIB_IO_LDBL}" = "y" ]; then
    78             newlib_opts+=( "--enable-newlib-io-long-double" )
    79         else
    80             newlib_opts+=( "--disable-newlib-io-long-double" )
    81         fi
    82     else
    83         newlib_opts+=( "--disable-newlib-io-float" )
    84         newlib_opts+=( "--disable-newlib-io-long-double" )
    85     fi
    86     if [ "${CT_LIBC_NEWLIB_DISABLE_SUPPLIED_SYSCALLS}" = "y" ]; then
    87         newlib_opts+=( "--disable-newlib-supplied-syscalls" )
    88     else
    89         newlib_opts+=( "--enable-newlib-supplied-syscalls" )
    90     fi
    91 
    92     [ "${CT_LIBC_NEWLIB_ENABLE_TARGET_OPTSPACE}" = "y" ] && newlib_opts+=("--enable-target-optspace")
    93 
    94     # Note: newlib handles the build/host/target a little bit differently
    95     # than one would expect:
    96     #   build  : not used
    97     #   host   : the machine building newlib
    98     #   target : the machine newlib runs on
    99     CT_DoExecLog CFG                                    \
   100     CC_FOR_BUILD="${CT_BUILD}-gcc"                      \
   101     CFLAGS_FOR_TARGET="${CT_TARGET_CFLAGS}"             \
   102     AR=${CT_TARGET}-ar                                  \
   103     RANLIB=${CT_TARGET}-ranlib                          \
   104     "${CT_SRC_DIR}/newlib-$(libc_newlib_version)/configure" \
   105         --host=${CT_BUILD}                              \
   106         --target=${CT_TARGET}                           \
   107         --prefix=${CT_PREFIX_DIR}                       \
   108         "${newlib_opts[@]}"                             \
   109         "${CT_LIBC_NEWLIB_EXTRA_CONFIG_ARRAY[@]}"
   110 
   111     CT_DoLog EXTRA "Building C library"
   112     CT_DoExecLog ALL make ${JOBSFLAGS}
   113 
   114     CT_DoLog EXTRA "Installing C library"
   115     CT_DoExecLog ALL make install install_root="${CT_SYSROOT_DIR}"
   116 
   117     if [ "${CT_BUILD_MANUALS}" = "y" ]; then
   118         local -a doc_dir="${CT_BUILD_DIR}/build-libc/${CT_TARGET}"
   119 
   120         CT_DoLog EXTRA "Building and installing the C library manual"
   121         CT_DoExecLog ALL make pdf html
   122 
   123         # NEWLIB install-{pdf.html} fail for some versions
   124         CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/share/doc/newlib"
   125         CT_DoExecLog ALL cp -av "${doc_dir}/newlib/libc/libc.pdf"   \
   126                                 "${doc_dir}/newlib/libm/libm.pdf"   \
   127                                 "${doc_dir}/newlib/libc/libc.html"  \
   128                                 "${doc_dir}/newlib/libm/libm.html"  \
   129                                 "${CT_PREFIX_DIR}/share/doc/newlib"
   130     fi
   131 
   132     CT_EndStep
   133 }
   134 
   135 do_libc_finish() {
   136     CT_DoStep INFO "Finishing C library"
   137     
   138     if [ "${CT_ATMEL_AVR32_HEADERS}" = "y" ]; then
   139         CT_DoLog EXTRA "Installing Atmel's AVR32 headers"
   140         CT_DoExecLog ALL cp -r ${CT_SRC_DIR}/avr32headers "${CT_PREFIX_DIR}/${CT_TARGET}/include/avr32"
   141     fi
   142 
   143     CT_EndStep
   144 }