scripts/build/companion_libs/110-mpfr.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
yann@466
     1
# This file adds the functions to build the MPFR library
yann@466
     2
# Copyright 2008 Yann E. MORIN
yann@466
     3
# Licensed under the GPL v2. See COPYING in the root of this package
yann@466
     4
yann@602
     5
do_mpfr_get() { :; }
yann@602
     6
do_mpfr_extract() { :; }
yann@2929
     7
do_mpfr_for_build() { :; }
yann@2927
     8
do_mpfr_for_host() { :; }
yann@602
     9
yann@602
    10
# Overide function depending on configuration
yann@2099
    11
if [ "${CT_MPFR}" = "y" ]; then
yann@468
    12
yann@466
    13
# Download MPFR
yann@466
    14
do_mpfr_get() {
yann@1119
    15
    CT_GetFile "mpfr-${CT_MPFR_VERSION}" http://www.mpfr.org/mpfr-current/  \
yann@522
    16
                                 http://www.mpfr.org/mpfr-${CT_MPFR_VERSION}/
yann@466
    17
}
yann@466
    18
yann@466
    19
# Extract MPFR
yann@466
    20
do_mpfr_extract() {
yann@1126
    21
    CT_Extract "mpfr-${CT_MPFR_VERSION}"
yann@1901
    22
    CT_Patch "mpfr" "${CT_MPFR_VERSION}"
yann@466
    23
yann@584
    24
    # OK, Gentoo have a sanity check that libtool.m4 and ltmain.sh have the
yann@584
    25
    # same version number. Unfortunately, some tarballs of MPFR are not
yann@584
    26
    # built sanely, and thus ./configure fails on Gentoo.
yann@584
    27
    # See: http://sourceware.org/ml/crossgcc/2008-05/msg00080.html
yann@584
    28
    # and: http://sourceware.org/ml/crossgcc/2008-06/msg00005.html
yann@598
    29
    # This hack is not bad per se, but the MPFR guys would be better not to
yann@584
    30
    # do that in the future...
yann@1251
    31
    # It seems that MPFR >= 2.4.0 do not need this...
yann@1251
    32
    case "${CT_MPFR_VERSION}" in
yann@1889
    33
        2.4.*)
oron@1449
    34
            CT_Pushd "${CT_SRC_DIR}/mpfr-${CT_MPFR_VERSION}"
oron@1449
    35
            if [ ! -f .autoreconf.ct-ng ]; then
oron@1449
    36
                CT_DoLog DEBUG "Running autoreconf"
yann@1904
    37
                CT_DoExecLog ALL autoreconf
oron@1449
    38
                touch .autoreconf.ct-ng
oron@1449
    39
            fi
oron@1449
    40
            CT_Popd
oron@1449
    41
            ;;
yann@1251
    42
        1.*|2.0.*|2.1.*|2.2.*|2.3.*)
yann@1251
    43
            CT_Pushd "${CT_SRC_DIR}/mpfr-${CT_MPFR_VERSION}"
yann@1251
    44
            if [ ! -f .autotools.ct-ng ]; then
yann@1251
    45
                CT_DoLog DEBUG "Re-building autotools files"
yann@1251
    46
                CT_DoExecLog ALL autoreconf -fi
yann@1251
    47
                # Starting with libtool-1.9f, config.{guess,sub} are no longer
yann@1251
    48
                # installed without -i, but starting with libtool-2.2.6, they
yann@1251
    49
                # are no longer removed without -i. Sight... Just use -i with
yann@1251
    50
                # libtool >=2
yann@1251
    51
                # See: http://sourceware.org/ml/crossgcc/2008-11/msg00046.html
yann@1251
    52
                # and: http://sourceware.org/ml/crossgcc/2008-11/msg00048.html
yann@1251
    53
                libtoolize_opt=
yann@1299
    54
                case "$(libtoolize --version |head -n 1 |awk '{ print $(NF); }')" in
yann@1251
    55
                    0.*)    ;;
yann@1251
    56
                    1.*)    ;;
yann@1251
    57
                    *)      libtoolize_opt=-i;;
yann@1251
    58
                esac
yann@1251
    59
                CT_DoExecLog ALL libtoolize -f ${libtoolize_opt}
yann@1251
    60
                touch .autotools.ct-ng
yann@1251
    61
            fi
yann@1251
    62
            CT_Popd
yann@1251
    63
            ;;
yann@1251
    64
    esac
yann@595
    65
}
yann@595
    66
yann@2929
    67
# Build MPFR for running on build
yann@2929
    68
# - always build statically
yann@2929
    69
# - we do not have build-specific CFLAGS
yann@2929
    70
# - install in build-tools prefix
yann@2929
    71
do_mpfr_for_build() {
yann@2929
    72
    local -a mpfr_opts
yann@2929
    73
yann@2929
    74
    case "${CT_TOOLCHAIN_TYPE}" in
yann@2929
    75
        native|cross)   return 0;;
yann@2929
    76
    esac
yann@2929
    77
yann@2929
    78
    CT_DoStep INFO "Installing MPFR for build"
yann@2929
    79
    CT_mkdir_pushd "${CT_BUILD_DIR}/build-mpfr-build-${CT_BUILD}"
yann@2929
    80
yann@2929
    81
    mpfr_opts+=( "host=${CT_BUILD}" )
yann@2929
    82
    mpfr_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
diorcet@3119
    83
    mpfr_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
diorcet@3119
    84
    mpfr_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
yann@2929
    85
    do_mpfr_backend "${mpfr_opts[@]}"
yann@2929
    86
yann@2929
    87
    CT_Popd
yann@2929
    88
    CT_EndStep
yann@2929
    89
}
yann@2929
    90
yann@2927
    91
# Build MPFR for running on host
yann@2927
    92
do_mpfr_for_host() {
yann@2927
    93
    local -a mpfr_opts
yann@595
    94
yann@2927
    95
    CT_DoStep INFO "Installing MPFR for host"
yann@2927
    96
    CT_mkdir_pushd "${CT_BUILD_DIR}/build-mpfr-host-${CT_HOST}"
yann@2927
    97
yann@2927
    98
    mpfr_opts+=( "host=${CT_HOST}" )
yann@2931
    99
    mpfr_opts+=( "prefix=${CT_HOST_COMPLIBS_DIR}" )
yann@2927
   100
    mpfr_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
diorcet@3119
   101
    mpfr_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
yann@2927
   102
    do_mpfr_backend "${mpfr_opts[@]}"
yann@2927
   103
yann@2927
   104
    CT_Popd
yann@2927
   105
    CT_EndStep
yann@2927
   106
}
yann@2927
   107
yann@2927
   108
# Build MPFR
yann@2927
   109
#     Parameter     : description               : type      : default
yann@2927
   110
#     host          : machine to run on         : tuple     : (none)
yann@2927
   111
#     prefix        : prefix to install into    : dir       : (none)
diorcet@3119
   112
#     cflags        : cflags to use             : string    : (empty)
diorcet@3119
   113
#     ldflags       : ldflags to use            : string    : (empty)
yann@2927
   114
do_mpfr_backend() {
yann@2927
   115
    local host
yann@2927
   116
    local prefix
yann@2927
   117
    local cflags
diorcet@3119
   118
    local ldflags
yann@2927
   119
    local arg
yann@2927
   120
yann@2927
   121
    for arg in "$@"; do
yann@2927
   122
        eval "${arg// /\\ }"
yann@2927
   123
    done
yann@584
   124
yann@1251
   125
    # Under Cygwin, we can't build a thread-safe library
yann@1205
   126
    case "${CT_HOST}" in
yann@1892
   127
        *cygwin*)   mpfr_opts+=( --disable-thread-safe );;
yann@1892
   128
        *mingw*)    mpfr_opts+=( --disable-thread-safe );;
yann@1892
   129
        *darwin*)   mpfr_opts+=( --disable-thread-safe );;
yann@1892
   130
        *)          mpfr_opts+=( --enable-thread-safe  );;
yann@1205
   131
    esac
yann@1205
   132
yann@466
   133
    CT_DoLog EXTRA "Configuring MPFR"
yann@2347
   134
    CT_DoExecLog CFG                                    \
yann@2927
   135
    CC="${host}-gcc"                                    \
diorcet@3119
   136
    CFLAGS="${cflags}"                                  \
diorcet@3119
   137
    LDFLAGS="${ldflags}"                                \
yann@1119
   138
    "${CT_SRC_DIR}/mpfr-${CT_MPFR_VERSION}/configure"   \
yann@1119
   139
        --build=${CT_BUILD}                             \
yann@2927
   140
        --host=${host}                                  \
yann@2927
   141
        --prefix="${prefix}"                            \
yann@2927
   142
        --with-gmp="${prefix}"                          \
yann@2381
   143
        --disable-shared                                \
yann@2381
   144
        --enable-static
yann@466
   145
yann@466
   146
    CT_DoLog EXTRA "Building MPFR"
yann@2275
   147
    CT_DoExecLog ALL make ${JOBSFLAGS}
yann@466
   148
yann@1890
   149
    if [ "${CT_COMPLIBS_CHECK}" = "y" ]; then
yann@466
   150
        CT_DoLog EXTRA "Checking MPFR"
yann@2275
   151
        CT_DoExecLog ALL make ${JOBSFLAGS} -s check
yann@466
   152
    fi
yann@466
   153
yann@466
   154
    CT_DoLog EXTRA "Installing MPFR"
yann@656
   155
    CT_DoExecLog ALL make install
yann@466
   156
}
yann@468
   157
yann@1810
   158
fi # CT_MPFR