scripts/build/binutils/elf2flt.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jul 24 23:52:28 2011 +0200 (2011-07-24)
changeset 2928 3f70dd642d34
parent 2926 d304c8a7bfa8
child 3090 a221c86d9b33
permissions -rw-r--r--
binutils: add frontends for building to run on the build machine

In canadian-cross, we need binutils running on the build machine to be
able to build the target C library.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
     1 # This file adds functions to build elf2flt
     2 # Copyright 2009 John Williams
     3 # Copyright 2007 Yann E. MORIN
     4 # Licensed under the GPL v2. See COPYING in the root of this package
     5 
     6 # Default: do nothing
     7 do_elf2flt_get()        { :; }
     8 do_elf2flt_extract()    { :; }
     9 do_elf2flt_for_build()  { :; }
    10 do_elf2flt_for_host()   { :; }
    11 
    12 if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
    13 
    14 # Download elf2flt
    15 do_elf2flt_get() {
    16     CT_GetCVS "elf2flt-cvs-${CT_ELF2FLT_VERSION}"           \
    17               ":pserver:anonymous@cvs.uclinux.org:/var/cvs" \
    18               "elf2flt"                                     \
    19               "" \
    20               "elf2flt-cvs-${CT_ELF2FLT_VERSION}"
    21 }
    22 
    23 # Extract elf2flt
    24 do_elf2flt_extract() {
    25     CT_Extract "elf2flt-cvs-${CT_ELF2FLT_VERSION}"
    26     CT_Patch "elf2flt-cvs" "${CT_ELF2FLT_VERSION}"
    27 }
    28 
    29 # Build elf2flt for build -> target
    30 do_elf2flt_for_build() {
    31     local -a elf2flt_opts
    32 
    33     case "${CT_TOOLCHAIN_TYPE}" in
    34         native|cross)   return 0;;
    35     esac
    36 
    37     CT_DoStep INFO "Installing elf2flt for build"
    38     CT_mkdir_pushd "${CT_BUILD_DIR}/build-elf2flt-build-${CT_BUILD}"
    39 
    40     elf2flt_opts+=( "host=${CT_BUILD}" )
    41     elf2flt_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
    42     elf2flt_opts+=( "binutils_bld=${CT_BUILD_DIR}/build-binutils-build-${CT_HOST}" )
    43 
    44     do_elf2flt_backend "${elf2flt_opts[@]}"
    45 
    46     CT_Popd
    47     CT_EndStep
    48 }
    49 
    50 # Build elf2flt for host -> target
    51 do_elf2flt_for_host() {
    52     local -a elf2flt_opts
    53 
    54     CT_DoStep INFO "Installing elf2flt for host"
    55     CT_mkdir_pushd "${CT_BUILD_DIR}/build-elf2flt-host-${CT_HOST}"
    56 
    57     elf2flt_opts+=( "host=${CT_HOST}" )
    58     elf2flt_opts+=( "prefix=${CT_PREFIX_DIR}" )
    59     elf2flt_opts+=( "static_build=${CT_STATIC_TOOLCHAIN}" )
    60     elf2flt_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
    61     elf2flt_opts+=( "binutils_bld=${CT_BUILD_DIR}/build-binutils-host-${CT_HOST}" )
    62 
    63     do_elf2flt_backend "${elf2flt_opts[@]}"
    64 
    65     # Make those new tools available to the core C compilers to come.
    66     # Note: some components want the ${TARGET}-{ar,as,ld,strip} commands as
    67     # well. Create that.
    68     # Don't do it for canadian or cross-native, because the binutils
    69     # are not executable on the build machine.
    70     case "${CT_TOOLCHAIN_TYPE}" in
    71         cross|native)
    72             mkdir -p "${CT_BUILDTOOLS_PREFIX_DIR}/${CT_TARGET}/bin"
    73             mkdir -p "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
    74             for t in elf2flt flthdr; do
    75                 CT_DoExecLog ALL ln -sv                                         \
    76                                     "${CT_PREFIX_DIR}/bin/${CT_TARGET}-${t}"    \
    77                                     "${CT_BUILDTOOLS_PREFIX_DIR}/${CT_TARGET}/bin/${t}"
    78                 CT_DoExecLog ALL ln -sv                                         \
    79                                     "${CT_PREFIX_DIR}/bin/${CT_TARGET}-${t}"    \
    80                                     "${CT_BUILDTOOLS_PREFIX_DIR}/bin/${CT_TARGET}-${t}"
    81             done
    82             ;;
    83         *)  ;;
    84     esac
    85 
    86     CT_Popd
    87     CT_EndStep
    88 }
    89 
    90 # Build elf2flt for X -> target
    91 #     Parameter     : description               : type      : default
    92 #     host          : machine to run on         : tuple     : (none)
    93 #     prefix        : prefix to install into    : dir       : (none)
    94 #     static_build  : build statcially          : bool      : no
    95 #     cflags        : host cflags to use        : string    : (empty)
    96 do_elf2flt_backend() {
    97     local host
    98     local prefix
    99     local static_build
   100     local cflags
   101     local binutils_bld
   102     local binutils_src
   103     local arg
   104 
   105     for arg in "$@"; do
   106         eval "${arg// /\\ }"
   107     done
   108 
   109     binutils_src="${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}"
   110 
   111     CT_DoLog EXTRA "Configuring elf2flt"
   112     CT_DoExecLog CFG                                            \
   113     CFLAGS="${host_cflags}"                                     \
   114     "${CT_SRC_DIR}/elf2flt-cvs-${CT_ELF2FLT_VERSION}/configure" \
   115         --build=${CT_BUILD}                                     \
   116         --host=${host}                                          \
   117         --target=${CT_TARGET}                                   \
   118         --prefix=${prefix}                                      \
   119         --with-bfd-include-dir=${binutils_bld}/bfd              \
   120         --with-binutils-include-dir=${binutils_src}/include     \
   121         --with-libbfd=${binutils_bld}/bfd/libbfd.a              \
   122         --with-libiberty=${binutils_bld}/libiberty/libiberty.a  \
   123         ${elf2flt_opts}                                         \
   124         "${CT_ELF2FLT_EXTRA_CONFIG_ARRAY[@]}"
   125 
   126     CT_DoLog EXTRA "Building elf2flt"
   127     CT_DoExecLog ALL make ${JOBSFLAGS}
   128 
   129     CT_DoLog EXTRA "Installing elf2flt"
   130     CT_DoExecLog ALL make install
   131 }
   132 
   133 fi # CT_ARCH_BINFMT_FLAT