scripts/build/companion_libs/200-libelf.sh
author Daniel Price <daniel.price@gmail.com>
Tue Nov 20 16:59:17 2012 -0800 (2012-11-20)
changeset 3126 333d3e40cbd1
parent 3115 1c68438f44f7
permissions -rw-r--r--
scripts: refine static linking check to better guide the user

The current mechanism to check if static linking is possible, and the mesage
displayed on failure, can be puzzling to the unsuspecting user.

Also, the current implementation is not using the existing infrastructure,
and is thus difficult to enhance with new tests.

So, switch to using the standard CT_DoExecLog infra, and use four tests to
check for the host compiler:
- check we can run it
- check it can build a trivial program
- check it can statically link that program
- check if it statically link with libstdc++

That should cover most of the problems. Hopefully.

(At the same time, fix a typo in a comment)

Signed-off-by: Daniel Price <daniel.price@gmail.com>
[yann.morin.1998@free.fr: split original patch for self-contained changes]
[yann.morin.1998@free.fr: use steps to better see gcc's output]
[yann.morin.1998@free.fr: commit log]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Message-Id: <163f86b5216fc08c672a.1353459722@nipigon.dssd.com>
Patchwork-Id: 200536
     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