scripts/build/companion_libs/200-libelf.sh
author Yann Diorcet <diorcet.yann@gmail.com>
Fri Nov 16 15:25:57 2012 +0100 (2012-11-16)
changeset 3119 1c56c03b7ed5
parent 3115 1c68438f44f7
permissions -rw-r--r--
scripts: add BUILD/HOST extra cflags/ldflags

On some hosts, and for certain toolchains (eg. toolchain targetting
the upcoming Darwin), it may be necessary to pass arbitrary CFLAGS
and/or LDFLAGS when building the components.

And necessary infrastructure:
- EXTRA_{CFLAGS,LDFLAGS}_FOR_{BUILD,HOST} as config options
- pass those extra flags to components

Fix-up a slight typo in elf2flt at the same time (misnamed cflags).

Signed-off-by: Yann Diorcet <diorcet.yann@gmail.com>
Message-Id: <d24043276c9243a35421.1353077450@macbook-smorlat.local>
Patchwork-Id: 199645
     1 # Build script for libelf
     2 
     3 do_libelf_get() { :; }
     4 do_libelf_extract() { :; }
     5 do_libelf_for_build() { :; }
     6 do_libelf_for_host() { :; }
     7 do_libelf_for_target() { :; }
     8 
     9 if [ "${CT_LIBELF}" = "y" -o "${CT_LIBELF_TARGET}" = "y" ]; then
    10 
    11 do_libelf_get() {
    12     # The server hosting libelf will return an "HTTP 300 : Multiple Choices"
    13     # error code if we try to download a file that does not exists there.
    14     # So we have to request the file with an explicit extension.
    15     CT_GetFile "libelf-${CT_LIBELF_VERSION}" .tar.gz http://www.mr511.de/software/
    16 }
    17 
    18 do_libelf_extract() {
    19     CT_Extract "libelf-${CT_LIBELF_VERSION}"
    20     CT_Patch "libelf" "${CT_LIBELF_VERSION}"
    21 }
    22 
    23 if [ "${CT_LIBELF}" = "y" ]; then
    24 
    25 # Build libelf for running on build
    26 # - always build statically
    27 # - we do not have build-specific CFLAGS
    28 # - install in build-tools prefix
    29 do_libelf_for_build() {
    30     local -a libelf_opts
    31 
    32     case "${CT_TOOLCHAIN_TYPE}" in
    33         native|cross)   return 0;;
    34     esac
    35 
    36     CT_DoStep INFO "Installing libelf for build"
    37     CT_mkdir_pushd "${CT_BUILD_DIR}/build-libelf-build-${CT_BUILD}"
    38 
    39     libelf_opts+=( "host=${CT_BUILD}" )
    40     libelf_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
    41     libelf_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
    42     libelf_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
    43     do_libelf_backend "${libelf_opts[@]}"
    44 
    45     CT_Popd
    46     CT_EndStep
    47 }
    48 
    49 # Build libelf for running on host
    50 do_libelf_for_host() {
    51     local -a libelf_opts
    52 
    53     CT_DoStep INFO "Installing libelf for host"
    54     CT_mkdir_pushd "${CT_BUILD_DIR}/build-libelf-host-${CT_HOST}"
    55 
    56     libelf_opts+=( "host=${CT_HOST}" )
    57     libelf_opts+=( "prefix=${CT_HOST_COMPLIBS_DIR}" )
    58     libelf_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
    59     libelf_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
    60     do_libelf_backend "${libelf_opts[@]}"
    61 
    62     CT_Popd
    63     CT_EndStep
    64 }
    65 
    66 fi # CT_LIBELF
    67 
    68 if [ "${CT_LIBELF_TARGET}" = "y" ]; then
    69 
    70 do_libelf_for_target() {
    71     local -a libelf_opts
    72 
    73     CT_DoStep INFO "Installing libelf for the target"
    74     CT_mkdir_pushd "${CT_BUILD_DIR}/build-libelf-target-${CT_TARGET}"
    75 
    76     libelf_opts+=( "destdir=${CT_SYSROOT_DIR}" )
    77     libelf_opts+=( "host=${CT_TARGET}" )
    78     libelf_opts+=( "prefix=/usr" )
    79     libelf_opts+=( "shared=y" )
    80     do_libelf_backend "${libelf_opts[@]}"
    81 
    82     CT_Popd
    83     CT_EndStep
    84 }
    85 
    86 fi # CT_LIBELF_TARGET
    87 
    88 # Build libelf
    89 #     Parameter     : description               : type      : default
    90 #     destdir       : out-of-tree install dir   : string    : /
    91 #     host          : machine to run on         : tuple     : (none)
    92 #     prefix        : prefix to install into    : dir       : (none)
    93 #     cflags        : cflags to use             : string    : (empty)
    94 #     ldflags       : ldflags to use            : string    : (empty)
    95 #     shared        : also buils shared lib     : bool      : n
    96 do_libelf_backend() {
    97     local destdir="/"
    98     local host
    99     local prefix
   100     local cflags
   101     local ldflags
   102     local shared
   103     local -a extra_config
   104     local arg
   105 
   106     for arg in "$@"; do
   107         eval "${arg// /\\ }"
   108     done
   109 
   110     CT_DoLog EXTRA "Configuring libelf"
   111 
   112     if [ "${shared}" = "y" ]; then
   113         extra_config+=( --enable-shared )
   114     else
   115         extra_config+=( --disable-shared )
   116     fi
   117 
   118     CT_DoExecLog CFG                                        \
   119     CC="${host}-gcc"                                        \
   120     RANLIB="${host}-ranlib"                                 \
   121     CFLAGS="${cflags} -fPIC"                                \
   122     LDFLAGS="${ldflags}"                                    \
   123     "${CT_SRC_DIR}/libelf-${CT_LIBELF_VERSION}/configure"   \
   124         --build=${CT_BUILD}                                 \
   125         --host=${host}                                      \
   126         --target=${CT_TARGET}                               \
   127         --prefix="${prefix}"                                \
   128         --enable-compat                                     \
   129         --enable-elf64                                      \
   130         --enable-extended-format                            \
   131         --enable-static                                     \
   132         "${extra_config[@]}"
   133 
   134     CT_DoLog EXTRA "Building libelf"
   135     CT_DoExecLog ALL make
   136 
   137     CT_DoLog EXTRA "Installing libelf"
   138     CT_DoExecLog ALL make instroot="${destdir}" install
   139 }
   140 
   141 fi # CT_LIBELF || CT_LIBELF_TARGET