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