scripts/build/companion_libs/140-mpc.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 # This file adds the functions to build the MPC library
     2 # Copyright 2009 Yann E. MORIN
     3 # Licensed under the GPL v2. See COPYING in the root of this package
     4 
     5 do_mpc_get() { :; }
     6 do_mpc_extract() { :; }
     7 do_mpc_for_build() { :; }
     8 do_mpc_for_host() { :; }
     9 
    10 # Overide functions depending on configuration
    11 if [ "${CT_MPC}" = "y" ]; then
    12 
    13 # Download MPC
    14 do_mpc_get() {
    15     CT_GetFile "mpc-${CT_MPC_VERSION}" .tar.gz      \
    16         http://www.multiprecision.org/mpc/download
    17 }
    18 
    19 # Extract MPC
    20 do_mpc_extract() {
    21     CT_Extract "mpc-${CT_MPC_VERSION}"
    22     CT_Patch "mpc" "${CT_MPC_VERSION}"
    23 }
    24 
    25 # Build MPC for running on build
    26 # - always build statically
    27 # - we do not have build-specific CFLAGS
    28 # - install in build-tools prefix
    29 do_mpc_for_build() {
    30     local -a mpc_opts
    31 
    32     case "${CT_TOOLCHAIN_TYPE}" in
    33         native|cross)   return 0;;
    34     esac
    35 
    36     CT_DoStep INFO "Installing MPC for build"
    37     CT_mkdir_pushd "${CT_BUILD_DIR}/build-mpc-build-${CT_BUILD}"
    38 
    39     mpc_opts+=( "host=${CT_BUILD}" )
    40     mpc_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
    41     mpc_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
    42     mpc_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
    43     do_mpc_backend "${mpc_opts[@]}"
    44 
    45     CT_Popd
    46     CT_EndStep
    47 }
    48 
    49 # Build MPC for running on host
    50 do_mpc_for_host() {
    51     local -a mpc_opts
    52 
    53     CT_DoStep INFO "Installing MPC for host"
    54     CT_mkdir_pushd "${CT_BUILD_DIR}/build-mpc-host-${CT_HOST}"
    55 
    56     mpc_opts+=( "host=${CT_HOST}" )
    57     mpc_opts+=( "prefix=${CT_HOST_COMPLIBS_DIR}" )
    58     mpc_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
    59     mpc_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
    60     do_mpc_backend "${mpc_opts[@]}"
    61 
    62     CT_Popd
    63     CT_EndStep
    64 }
    65 
    66 # Build MPC
    67 #     Parameter     : description               : type      : default
    68 #     host          : machine to run on         : tuple     : (none)
    69 #     prefix        : prefix to install into    : dir       : (none)
    70 #     cflags        : cflags to use             : string    : (empty)
    71 #     ldflags       : ldflags to use            : string    : (empty)
    72 do_mpc_backend() {
    73     local host
    74     local prefix
    75     local cflags
    76     local ldflags
    77     local arg
    78 
    79     for arg in "$@"; do
    80         eval "${arg// /\\ }"
    81     done
    82 
    83     CT_DoLog EXTRA "Configuring MPC"
    84 
    85     CT_DoExecLog CFG                                \
    86     CFLAGS="${cflags}"                              \
    87     LDFLAGS="${ldflags}"                            \
    88     "${CT_SRC_DIR}/mpc-${CT_MPC_VERSION}/configure" \
    89         --build=${CT_BUILD}                         \
    90         --host=${host}                              \
    91         --prefix="${prefix}"                        \
    92         --with-gmp="${prefix}"                      \
    93         --with-mpfr="${prefix}"                     \
    94         --disable-shared                            \
    95         --enable-static
    96 
    97     CT_DoLog EXTRA "Building MPC"
    98     CT_DoExecLog ALL make ${JOBSFLAGS}
    99 
   100     if [ "${CT_COMPLIBS_CHECK}" = "y" ]; then
   101         CT_DoLog EXTRA "Checking MPC"
   102         CT_DoExecLog ALL make ${JOBSFLAGS} -s check
   103     fi
   104 
   105     CT_DoLog EXTRA "Installing MPC"
   106     CT_DoExecLog ALL make install
   107 }
   108 
   109 fi # CT_MPC