Ticket #11616: mpir-2.4.0.p1-p2.diff

File mpir-2.4.0.p1-p2.diff, 26.3 KB (added by jdemeyer, 3 years ago)

Diff between the 2.4.0.p1 and 2.4.0.p2 spkgs. For reference / review only.

  • SPKG.txt

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1334060092 -7200
    # Node ID 7353f501cc393146517fbc253a2972e45dba4883
    # Parent  f0de181e1710e4fb5e9227cefed4b9d6656a3ae4
    Trac #11616: upgrade MPIR to version 2.4.0; many other fixes
     * Before enabling `-march=native`, minimalistically check whether the
       system's assembler also understands the instructions the compiler emits
       with that option.  (Work-around for e.g. GCC 4.6.3 on MacOS X 10.x and
       Intel Core i7-family CPUs with AVX.)
     * Do not unconditionally unset `PYTHON`, since Sage (>=5.0.beta10) no longer
       pollutes the environment with its package version variables, which previous-
       ly confused yasm's `configure`.
     * Fix extraction of `__GMP_CC` and `__GMP_CFLAGS` from `gmp.h`, since MPIR
       meanwhile defines these to preprocessor variables (rather than literals).
       Also don't use `\+` in `sed` patterns, as this is less portable.
     * Work around GCC 4.7.0 bug (compilation error) on Linux ia64 (Itanium) by
       almost completely disabling optimization on that platform if GCC 4.7.x
       is detected.  This doesn't hurt much if we later rebuild MPIR with a (non-
       broken) GCC from the new GCC spkg.  Cf. #12765.
     * Do not build the C++ interface and static libraries when bootstrapping the
       GCC spkg, i.e. if `SAGE_BUILD_TOOLCHAIN=yes`.  (GMP/MPIR is a prerequisite
       for it, and MPIR will later get rebuilt with both enabled, with the newly
       built GCC.)  Cf. #12782.
     * Fix a potential race condition in yasm's build by patching the re2c source.
       Cf. #11844.
     * Add "`patch` loop" to apply any patches (`*.patch`) located in `patches/`.
       Currently only the re2c patch matches that; the prepatched header to support
       Sun's C compiler is still copied over (and only on SunOS, although it doesn't
       do any harm on other platforms).
     * Minor clean-up; e.g. redirect error messages and warnings to `stderr`,
       quote parameter to `--libdir`, add some comments and messages, also save
       user's setting of `LDFLAGS` and `ABI`.
    
    diff --git a/SPKG.txt b/SPKG.txt
    a b  
    2020 
    2121== Dependencies == 
    2222 * iconv 
     23 * GNU patch 
    2324 
    2425== Special Update/Build Instructions == 
    25  * TODO: Use 'patch' rather than copying over patched upstream files. 
    26          (The currently patched file for Sun CC on SunOS has to be refreshed on 
    27          each upgrade.) 
    28  * Make sure the patches still apply; also, putting "-Wl,z,noexecstack" 
     26 * TODO: 
     27   - Use 'patch' also to (unconditionally) apply the harmless patch for Sun CC  
     28     (on SunOS), as the current prepatched file which is still copied over has 
     29     to get refreshed on each upgrade. 
     30   - Perhaps also modify CXXFLAGS (and/or CPPFLAGS). 
     31   - We currently don't use anything of GMP's/MPIR's CC setting, and matching 
     32     with the current compiler (`$CC`) is perhaps suboptimal. 
     33 * Make sure the patches still apply; also, putting "-Wl,-z,noexecstack" 
    2934   into LDFLAGS might not be necessary for later versions. 
    3035 * Perhaps make sure we still delete the correct files on 32-bit MacOS X 
    3136   on Intel hardware (x86) to not break PIC there. 
     37 * The work-around for the broken GCC 4.7.0 on Linux ia64 (Itanium) is current- 
     38   ly applied for any 4.7.x version (of course only on that platform), as it 
     39   seems unlikely that the bug which breaks the build of MPIR gets fixed soon. 
     40   In case GCC 4.7.1 or a later version is meanwhile released, one should check 
     41   whether the build is still broken with this or these, and eventually change 
     42   the version pattern accordingly. 
    3243 * Remove some files / directories not needed for Sage from upstream: 
    3344     rm -rf src/build.vc*             # Microsoft Visual C build files 
    3445     rm -rf src/yasm/Mkfiles/{dj,vc*} # DJGPP, Microsoft Visual C 
    3546   (Saves 13 of 40 MB uncompressed.) 
    3647 
    3748=== Patches === 
    38  * We currently only apply a trivial patch to gmp-h.in on SunOS such that 
    39    MPIR would compile with Sun CC there. See also `spkg-install`. 
     49 * We currently apply a trivial patch to gmp-h.in on SunOS such that 
     50   MPIR would compile with Sun CC there.  See also `spkg-install`. 
     51   This patch could be applied on all platforms, as the changes only take 
     52   effect if the preprocessor variable `__SUNPRO_CC` is defined. 
     53 * We apply a simple patch to upstream yasm's re2c code, to avoid a potential 
     54   race condition when building yasm in parallel.  (Cf. #11844.) 
    4055 
    4156== Changelog == 
    4257 
     58=== mpir-2.4.0.p2 (Leif Leonhardy, April 4th, 2012) === 
     59 #11616 (upgrading MPIR), further fixes: 
     60 * Before enabling `-march=native`, minimalistically check whether the 
     61   system's assembler also understands the instructions the compiler emits 
     62   with that option.  (Work-around for e.g. GCC 4.6.3 on MacOS X 10.x and 
     63   Intel Core i7-family CPUs with AVX.) 
     64 * Do not unconditionally unset `PYTHON`, since Sage (>=5.0.beta10) no longer 
     65   pollutes the environment with its package version variables, which previous- 
     66   ly confused yasm's `configure`. 
     67 * Fix extraction of `__GMP_CC` and `__GMP_CFLAGS` from `gmp.h`, since MPIR 
     68   meanwhile defines these to preprocessor variables (rather than literals). 
     69   Also don't use `\+` in `sed` patterns, as this is less portable. 
     70 * Work around GCC 4.7.0 bug (compilation error) on Linux ia64 (Itanium) by 
     71   almost completely disabling optimization on that platform if GCC 4.7.x 
     72   is detected.  This doesn't hurt much if we later rebuild MPIR with a (non- 
     73   broken) GCC from the new GCC spkg.  Cf. #12765. 
     74 * Do not build the C++ interface and static libraries when bootstrapping the 
     75   GCC spkg, i.e. if `SAGE_BUILD_TOOLCHAIN=yes`.  (GMP/MPIR is a prerequisite 
     76   for it, and MPIR will later get rebuilt with both enabled, with the newly 
     77   built GCC.)  Cf. #12782. 
     78 * Fix a potential race condition in yasm's build by patching the re2c source. 
     79   Cf. #11844. 
     80 * Add "`patch` loop" to apply any patches (`*.patch`) located in `patches/`. 
     81   Currently only the re2c patch matches that; the prepatched header to support 
     82   Sun's C compiler is still copied over (and only on SunOS, although it doesn't 
     83   do any harm on other platforms). 
     84 * Minor clean-up; e.g. redirect error messages and warnings to `stderr`, 
     85   quote parameter to `--libdir`, add some comments and messages, also save 
     86   user's setting of `LDFLAGS` and `ABI`. 
     87 
    4388=== mpir-2.4.0.p1 (Leif Leonhardy, March 21st, 2012) === 
    4489 * Upstream upgrade to MPIR 2.4.0 (#11616). 
    4590   The 2.4.0.p0 spkg isn't in this history, as it was based 
  • new file patches/yasm__tools__re2c__code.c.patch

    diff --git a/patches/yasm__tools__re2c__code.c.patch b/patches/yasm__tools__re2c__code.c.patch
    new file mode 100644
    - +  
     1--- src/yasm/tools/re2c/code.c  2011-03-05 14:47:11.000000000 +0100 
     2+++ src/yasm/tools/re2c/code.c  2012-04-05 12:34:44.958541522 +0200 
     3@@ -1,5 +1,6 @@ 
     4 #include <stdlib.h> 
     5 #include <string.h> 
     6+#include <errno.h> 
     7 #include <ctype.h> 
     8 #include "tools/re2c/substr.h" 
     9 #include "tools/re2c/globals.h" 
     10@@ -10,7 +11,7 @@ 
     11     while (value >= vUsedLabelAlloc) { 
     12        vUsedLabels = realloc(vUsedLabels, vUsedLabelAlloc * 2); 
     13        if (!vUsedLabels) { 
     14-           fputs("Out of memory.\n", stderr); 
     15+           fputs("Error: re2c: Out of memory.\n", stderr); 
     16            exit(EXIT_FAILURE); 
     17        } 
     18        memset(vUsedLabels + vUsedLabelAlloc, 0, vUsedLabelAlloc); 
     19@@ -844,14 +845,17 @@ 
     20     nOrgOline = oline; 
     21     maxFillIndexes = vFillIndexes; 
     22     orgVFillIndexes = vFillIndexes; 
     23-    tmpo = fopen("re2c.tmp", "wt"); 
     24+    if (!(tmpo = tmpfile())) 
     25+    { 
     26+        fprintf(stderr, "Error: re2c: tmpfile(): %s\n", strerror(errno)); 
     27+        exit(EXIT_FAILURE); 
     28+    } 
     29     for(s = d->head; s; s = s->next){ 
     30        int readCh = 0; 
     31        State_emit(s, tmpo, &readCh); 
     32        Go_genGoto(&s->go, tmpo, s, s->next, &readCh); 
     33     } 
     34     fclose(tmpo); 
     35-    remove("re2c.tmp"); 
     36     maxFillIndexes = vFillIndexes; 
     37     vFillIndexes = orgVFillIndexes; 
     38     oline = nOrgOline; 
  • spkg-check

    diff --git a/spkg-check b/spkg-check
    a b  
    11#!/usr/bin/env bash 
    22 
    33if [ -z "$SAGE_LOCAL" ]; then 
    4     echo "Error: SAGE_LOCAL undefined - exiting..." 
    5     echo "Maybe run 'sage -sh'?" 
     4    echo >&2 "Error: SAGE_LOCAL undefined - exiting..." 
     5    echo >&2 "Maybe run 'sage -sh'?" 
    66    exit 1 
    77fi 
    88 
     
    1111# We don't have to set up any environment variables here since the 
    1212# Makefiles already have them from 'configure'. 
    1313 
     14echo "Now building and running MPIR's test suite..." 
    1415$MAKE check 
    1516if [ $? -ne 0 ]; then 
    16     echo "Error: The MPIR test suite failed." 
     17    echo >&2 "Error: The MPIR test suite failed." 
    1718    exit 1 
    1819fi 
    1920 
  • spkg-install

    diff --git a/spkg-install b/spkg-install
    a b  
    66############################################################################### 
    77 
    88if [ -z "$SAGE_LOCAL" ]; then 
    9     echo "Error: SAGE_LOCAL undefined - exiting..." 
    10     echo "Maybe run 'sage -sh'?" 
     9    echo >&2 "Error: SAGE_LOCAL undefined - exiting..." 
     10    echo >&2 "Maybe run 'sage -sh'?" 
    1111    exit 1 
    1212fi 
    1313 
    1414CUR=`pwd` 
    1515 
     16cd src/ 
     17 
    1618############################################################################### 
    1719# Apply patches (if any): 
    1820############################################################################### 
     
    2527    #       has to be refreshed on each new release, since gmp-h.in also 
    2628    #       contains the full version number. 
    2729    echo "Copying a version of gmp-h.in which is patched for Sun Studio..." 
    28     cp patches/gmp-h.in src/ 
     30    cp ../patches/gmp-h.in . # We are in src/. 
    2931    if [ $? -ne 0 ]; then 
    30         echo "Error: Failed to patch MPIR for Sun Studio." 
     32        echo >&2 "Error: Failed to patch MPIR for Sun Studio." 
    3133        exit 1 
    3234    fi 
    3335fi 
    3436 
     37echo "Applying further patches (if any) to upstream sources..." 
     38for patch in ../patches/*.patch; do 
     39    patch -p1 <"$patch" 
     40    if [ $? -ne 0 ]; then 
     41        echo >&2 "Error: '$patch' failed to apply." 
     42        exit 1 
     43    fi 
     44done 
     45 
    3546############################################################################### 
    3647# Previous MPIR installations are only removed after a *successful* (re)build, 
    3748# before installing the new one. (Done below.) 
     
    7182{ 
    7283    # Internal sanity check: 
    7384    if [ $# -ne 1 ]; then 
    74         echo "Error: get_upstream_selected_cflags() requires 'file' parameter." 
     85        echo >&2 "Error: get_upstream_selected_cflags() requires 'file' parameter." 
    7586        exit 1 
    7687    fi 
    7788    header_file=$1 
    78     # We'll probably have to change the following patterns (conditionally) when we 
    79     # upgrade to MPIR >=2.5.0(?), since MPIR's gmp.h was changed to define __GMP_CC 
    80     # to (literally) __MPIR_CC, and likewise __GMP_CFLAGS to __MPIR_CFLAGS. 
    81     # I.e., in later releases __MPIR_CC and __MPIR_CFLAGS will contain the real strings 
    82     # we need (unless they again change this; I've already complained about that). 
    83     gmp_cc_pat='/^[     ]*#[    ]*define[       ]\+__GMP_CC[    ]\+/s/.*"\([^"]*\)"/\1/p' 
    84     gmp_cflags_pat='/^[         ]*#[    ]*define[       ]\+__GMP_CFLAGS[        ]\+/s/.*"\([^"]*\)"/\1/p' 
    8589    if ! [ -f "$header_file" ]; then 
    8690        upstream_cc="" 
    8791        upstream_cflags="" 
    8892        return 1 
    8993    fi 
     94    # The following patterns only extract the contents of (double-quoted) strings: 
     95    gmp_cc_pat='/^[     ]*#[    ]*define[       ]\{1,\}__GMP_CC[        ]\{1,\}/s/.*"\([^"]*\)"/\1/p' 
     96    gmp_cflags_pat='/^[         ]*#[    ]*define[       ]\{1,\}__GMP_CFLAGS[    ]\{1,\}/s/.*"\([^"]*\)"/\1/p' 
     97    # Extract preprocessor definitions of __GMP_CC and __GMP_CFLAGS: 
    9098    upstream_cc=`sed -n -e "$gmp_cc_pat" "$header_file"` 
    9199    upstream_cflags=`sed -n -e "$gmp_cflags_pat" "$header_file"` 
     100    # At least /some/ newer versions of MPIR define __GMP_CC and __GMP_CFLAGS 
     101    # (also in gmp.h! -- how compatible is that?) to (literally) __MPIR_CC and 
     102    # __MPIR_CFLAGS, respectively, i.e., to preprocessor variables, so we might 
     103    # have to get the real strings from their definitions: 
     104    # (Since we currently only match string literals above, both variables would 
     105    # be empty in that case, and not contain the names of preprocessor variables. 
     106    # We could change the patterns to actually match any definition / "value".)  
     107    case "$upstream_cc" in __MPIR_CC|"") 
     108        upstream_cc=`sed -n -e "${gmp_cc_pat/GMP/MPIR}" "$header_file"` 
     109    esac 
     110    case "$upstream_cflags" in __MPIR_CFLAGS|"") 
     111        upstream_cflags=`sed -n -e "${gmp_cflags_pat/GMP/MPIR}" "$header_file"` 
     112    esac 
     113    # Upstream-selected CFLAGS may be empty, CC shouldn't: 
     114    if [ -z "$upstream_cc" ]; then 
     115        return 1 
     116    fi 
    92117    return 0 
    93118} 
    94119 
     
    96121{ 
    97122    # Internal sanity check: 
    98123    if [ $# -lt 1 ]; then 
    99         echo "Error: get_processor_specific_cflags() requires 'CFLAGS' parameter." 
     124        echo >&2 "Error: get_processor_specific_cflags() requires 'CFLAGS' parameter." 
    100125        exit 1 
    101126    fi 
    102127    flags=$@ 
     
    109134            # We could add further '-m' or '-f' options here, but note that 
    110135            # this function is also used to determine if the user specified 
    111136            # some, which we don't want to override. 
     137            # AFAIK, MPIR currently uses / defines at most '-m{arch,cpu,tune}', 
     138            # not more specific / additional ones like e.g. '-mavx' or '-mvsx'. 
     139            # (-leif, 04/2012) 
    112140        esac 
    113141    done 
    114142    echo $arch_flags 
     
    121149    # (Compilers other than 'gcc' might support it as well, in which case the 
    122150    # following also works. Other flavours could be added, too.) 
    123151    if touch foo.c && $CC -march=native -c foo.c &>/dev/null; then 
    124         echo "-march=native" 
     152        # Ok, the compiler (presumably GCC) understands '-march=native', which 
     153        # doesn't yet mean the *assembler* will know the fancy instructions 
     154        # the compiler emits with that option. 
     155        # For example, Apple's assembler on Mac OS X 10.7.1 apparently doesn't 
     156        # yet support AVX, which could also cause MPIR's 'configure' to fail. 
     157        cat >foo.c <<-"EOF" 
     158                double d; 
     159                unsigned long fancy_insns() { return (unsigned long) d; } 
     160                int main () { return 0; } 
     161        EOF 
     162        if $CC -march=native -o foo foo.c &>/dev/null && ./foo >/dev/null; then 
     163            echo "-march=native" 
     164        else 
     165            echo >&2 "Warning: Your assembler apparently doesn't understand the instructions" 
     166            echo >&2 "         your compiler ($CC) generates with '-march=native'." 
     167            echo >&2 "         You might also try to compile MPIR with (e.g.)" 
     168            echo >&2 "             CFLAGS=\"-march=native -mno-avx\"" 
     169            echo >&2 "         to disable specific instruction set extension (in this case, AVX)." 
     170        fi 
    125171    fi 
    126     rm -f foo.* >/dev/null 
     172    rm -f foo foo.* >/dev/null 
    127173} 
    128174 
    129175############################################################################### 
    130176# Set up environment variables: 
    131177############################################################################### 
    132178 
    133 # The Yasm build uses PYTHON from the environment to find python, so unset 
    134 # it since the setting from 'spkg/standard/newest_version' confuses it: 
    135 unset PYTHON 
    136 # This can be removed once #10492 has been merged, which turns the "package 
    137 # version" environment variables into solely `make` variables, such that the 
    138 # (shell) environment does no longer get polluted.  
     179# The Yasm build uses PYTHON from the environment to find the Python interpreter, 
     180# so unset it in case it apparently contains nothing useful (like it did in Sage 
     181# versions prior to 5.0.beta10; cf. #10492), to not break Yasm's 'configure': 
     182if ! $PYTHON --version &>/dev/null; then 
     183    # Only issue a warning if it was really non-empty, to not confuse users: 
     184    if [ -n "$PYTHON" ]; then 
     185        echo >&2 "Warning: Unsetting PYTHON (=\"$PYTHON\"), since it doesn't seem" 
     186        echo >&2 "         to contain the name of / path to a Python interpreter." 
     187    fi 
     188    unset PYTHON 
     189fi 
    139190 
    140191user_cflags=$CFLAGS # Save them. 'sage-env' sets CC, but not CFLAGS. 
    141 required_cflags="" # Additional mandatory settings required by Sage, accumulated below. 
    142 default_cflags="" # Spkg defaults that can and might get overridden. 
     192required_cflags=""  # Additional mandatory settings required by Sage, accumulated below. 
     193default_cflags=""   # Spkg defaults that can and might get overridden. 
     194user_ldflags=$LDFLAGS # Save them. 
     195required_ldflags=""   # Additional mandatory settings required by Sage, accumulated below. 
     196user_abi=$ABI # Just save it. 
     197# In case we changed CPPFLAGS or CXXFLAGS, too, we should save the user's here as well. 
     198# We don't have to add (e.g.) '-m64' to CFLAGS/CPPFLAGS/CXXFLAGS/LDFLAGS, since 
     199# MPIR's 'configure' is smart enough to add it if necessary or appropriate. 
    143200 
    144 # Newer autotools may put libs into .../lib64 (on 64-bit systems): 
    145 SAGE_CONF_OPTS=--libdir="$SAGE_LOCAL/lib" 
    146 # (Further options to `configure` are added below.) 
     201SAGE_CONF_OPTS="" # Clear them. (Further options to `configure` are added below.) 
    147202 
    148203 
    149204if [ -z "$CFLAG32" ]; then 
     
    157212if [ "$SAGE_DEBUG" = yes ]; then 
    158213    # Disable optimization, add debug symbols: 
    159214    required_cflags="$required_cflags -g -O0" 
    160     echo "Warning: Building MPIR with SAGE_DEBUG=yes disables optimization." 
     215    echo >&2 "Warning: Building MPIR with SAGE_DEBUG=yes disables optimization." 
    161216else 
    162217    # Add debug symbols by default, enable optimization, but do not (yet) 
    163218    # add processor-specific flags (these are eventually added later): 
     
    167222 
    168223case "$UNAME" in 
    169224    SunOS) 
    170         if [ "$SAGE64" = "yes" ]; then 
     225        if [ "$SAGE64" = yes ]; then 
    171226            echo "Building a 64-bit version of MPIR."  
    172227            ABI=64 
    173228        else 
     
    175230            ABI=32 
    176231        fi;; 
    177232    Darwin) 
    178         if [ "$SAGE64" = "yes" ]; then 
    179             # Note that we do not support 64-bit builds on PPC at all, 
     233        if [ "$SAGE64" = yes ]; then 
     234            # Note that we do not support 64-bit builds on MacOS X PPC at all, 
    180235            # so we don't special-case on the architecture here. 
    181236            echo "Building a 64-bit version of MPIR." 
    182237            ABI=64 
    183238        else 
    184             # Do not set ABI=32 on OS X 10.6 (Darwin 10) and later, since 
     239            # Do not set ABI=32 on MacOS X 10.6 (Darwin 10) and later, since 
    185240            # there everything defaults to 64-bit: 
    186241            if [ "`uname -r | sed 's/\..*//'`" -lt 10 ]; then 
    187242                # Assume MacOS X 10.4 or 10.5 (Darwin 8 or 9); also, PPC CPUs 
    188243                # are only supported by these, not later versions. 
     244                echo "Building a 32-bit version of MPIR, which is the only supported option." 
    189245                ABI=32 
    190246                case "`uname -m`" in 
    191247                    i[3456]86) 
     
    198254                        required_cflags="$required_cflags -Wa,-force_cpusubtype_ALL" 
    199255                        ;; 
    200256                esac 
     257            else 
     258                # Darwin 10 (MacOS X 10.6) or later, SAGE64 not "yes" 
     259                # We don't have to set ABI here. 
     260                echo "Building a 64-bit version of MPIR, which is the default." 
    201261            fi 
    202         fi;; 
     262        fi 
     263        ;; # Darwin 
    203264    Linux) 
    204265        # Work around (erroneously) set "executable stack" attributes, 
    205266        # causing runtime errors on Fedora 14 and other SELinux-enabled 
    206267        # systems: 
    207         LDFLAGS="$LDFLAGS -Wl,-z,noexecstack" 
    208         export LDFLAGS # perhaps redundant, but safe(r) 
     268        required_ldflags="$required_ldflags -Wl,-z,noexecstack" 
    209269 
    210270        if [ "$SAGE_FAT_BINARY" = "yes" ]; then 
    211271            # For now we do the same thing -- namely "--enable-fat" -- 
     
    220280                SAGE_CONF_OPTS="$SAGE_CONF_OPTS --enable-fat" 
    221281                ;; 
    222282            *) # e.g. ia64 (Itanium) or PPC (ppc, ppc64) 
    223                 echo "Warning: A \"fat binary\" build is currently not" \ 
     283                echo >&2 "Warning: A \"fat binary\" build is currently not" \ 
    224284                    "supported on this CPU architecture." 
    225285                # XXX exit 1 ? 
    226286            esac 
     
    256316                echo "Your compiler does not support '$CFLAG32' nor '$CFLAG64'.  Leaving ABI unset." 
    257317            fi 
    258318            rm -f foo foo.c 
    259         fi;; 
     319        fi 
     320 
     321        # Work around a bug in GCC 4.7.0 which breaks the build on Itanium CPUs: 
     322        # (Cf. #12765, #12751, and bug URL below.) 
     323        case "`uname -m`-`$CC -dumpversion 2>/dev/null`" in ia64-4.7.*) 
     324            # It's quite unlikely we match other compilers than GCC (e.g. clang) here. 
     325            required_cflags="$required_cflags -O0 -finline-functions -fschedule-insns" 
     326            echo >&2 "Warning: Disabling almost all optimization due to a bug in (at least)" 
     327            echo >&2 "         GCC 4.7.0 on Itanium, which otherwise would break the build." 
     328            echo >&2 "         See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48496" 
     329            echo >&2 "         for current status and further details." 
     330            echo >&2 "         (And please report to e.g. sage-devel in case you feel this bug" 
     331            echo >&2 "          should already be fixed in GCC `$CC -dumpversion`.)" 
     332        esac 
     333        ;; # Linux 
    260334    CYGWIN) 
    261335        # Nothing special performed (yet). 
    262336        ;; 
    263337    *) # e.g. AIX or HP-UX 
    264         echo "Warning: Your platform ($UNAME) isn't yet explicitly supported" \ 
     338        echo >&2 "Warning: Your platform ($UNAME) isn't yet explicitly supported" \ 
    265339            "by this MPIR spkg, i.e., by Sage's part of it." 
    266340esac 
    267341 
    268342export ABI CFLAGS CXXFLAGS # Partially redundant, but safe(r). 
     343# We don't export CPPFLAGS here, since we don't (have to) modify them. 
     344if [ -n "$required_ldflags" ]; then 
     345    export LDFLAGS # Probably redundant, but safe(r). 
     346fi 
    269347 
    270348############################################################################### 
    271349# Now configure MPIR, eventually modifying CFLAGS [further]: 
    272350############################################################################### 
    273351 
    274 cd src 
     352SAGE_CONF_OPTS="--enable-gmpcompat --enable-shared $SAGE_CONF_OPTS" 
    275353 
    276  
    277 SAGE_CONF_OPTS="--enable-gmpcompat --enable-cxx=yes $SAGE_CONF_OPTS" 
    278 # Also build the static library to be used by e.g. ECM: 
    279 # SAGE_CONF_OPTS="--enable-shared --disable-static $SAGE_CONF_OPTS" 
    280 SAGE_CONF_OPTS="--enable-shared --enable-static $SAGE_CONF_OPTS" 
     354# If we're bootstrapping GCC from the GCC spkg, don't build the C++ interface 
     355# and static libraries in the first place (cf. #12782): 
     356if [ "$SAGE_BUILD_TOOLCHAIN" = yes ]; then 
     357    echo "Building a reduced version of MPIR to bootstrap GCC." 
     358    echo "MPIR will later get rebuilt (with the C++ interface and static libraries" 
     359    echo "enabled) using the new compiler." 
     360    SAGE_CONF_OPTS="--disable-cxx --disable-static $SAGE_CONF_OPTS" 
     361else 
     362    # Also build the static library to be used by e.g. ECM: 
     363    echo "Building MPIR with the C++ interface and (also) static libraries." 
     364    SAGE_CONF_OPTS="--enable-cxx --enable-static $SAGE_CONF_OPTS" 
     365fi 
    281366# (Further options to 'configure' are added below.) 
    282367 
    283368 
     
    293378        echo "  CC:      $mpir_cc" 
    294379        echo "  CFLAGS:  $mpir_cflags" 
    295380    else 
    296         echo "Warning: Couldn't determine MPIR-selected CFLAGS from 'mpir.h'" 
     381        echo >&2 "Warning: Couldn't determine MPIR-selected CFLAGS from 'mpir.h'" 
    297382    fi 
    298383else 
    299384    # We ignore errors in the first place, since we redirected all 
     
    314399done 
    315400 
    316401echo "Settings required to properly build MPIR, taking into account SAGE_DEBUG etc.:" 
    317 echo "  CFLAGS:  $required_cflags" 
    318 echo "  LDFLAGS: $LDFLAGS" # Might be empty, or specified by the user. 
    319 echo "  ABI:     $ABI" # Might be empty, or specified by the user. 
     402echo "  CFLAGS:  $required_cflags"  # Might be empty. 
     403echo "  LDFLAGS: $required_ldflags" # Might be empty. 
     404echo "  ABI:     $ABI" # Might be empty, or the one specified by the user. 
    320405echo "Settings from the \"global\" environment:" 
    321406echo "  CC:      $CC" # Set by Sage, maybe overridden by the user. 
    322407echo "  CFLAGS:  $user_cflags" 
    323 echo "  (CPPFLAGS, CXX and CXXFLAGS are listed below; these don't get modified.)" 
     408echo "  LDFLAGS: $user_ldflags" 
     409echo "  ABI:     $user_abi" 
     410echo "  (CPP, CPPFLAGS, CXX and CXXFLAGS are listed below; these don't get modified.)" 
    324411 
    325412if [ -z "$user_cflags" ]; then 
    326413    # No CFLAGS specified by user => Use either MPIR's, GMP's or our default 
     
    374461    fi 
    375462fi 
    376463 
     464LDFLAGS="$required_ldflags $user_ldflags" 
     465 
    377466echo "Finally using the following settings:" 
    378467echo "  CC=$CC" 
    379468echo "  CFLAGS=$CFLAGS" 
     469echo "  CPP=$CPP" 
    380470echo "  CPPFLAGS=$CPPFLAGS" 
    381471echo "  CXX=$CXX" 
    382472echo "  CXXFLAGS=$CXXFLAGS" 
     
    388478# Now really configure MPIR with proper settings: 
    389479############################################################################### 
    390480 
     481# We also add '--libdir="$SAGE_LOCAL/lib"' below, since newer autotools may 
     482# otherwise put the libraries into .../lib64 on 64-bit systems (cf. #12131). 
     483 
    391484if [ -z "$MPIR_EXTRA_OPTS" ]; then 
    392485    echo "Configuring MPIR with the following options:" 
    393     echo "    --prefix=\"$SAGE_LOCAL\" $SAGE_CONF_OPTS" 
     486    echo "    --prefix=\"$SAGE_LOCAL\" --libdir=\"$SAGE_LOCAL/lib\" $SAGE_CONF_OPTS" 
    394487    echo "You can set MPIR_EXTRA_OPTS to pass additional parameters." 
    395488else 
    396489    echo "Using additional 'configure' options as specified through" \ 
    397490        "MPIR_EXTRA_OPTS:" 
    398491    echo "    $MPIR_EXTRA_OPTS" 
    399492    echo "Configuring MPIR with the following options:" 
    400     echo "    --prefix=\"$SAGE_LOCAL\" $SAGE_CONF_OPTS $MPIR_EXTRA_OPTS" 
     493    echo "    --prefix=\"$SAGE_LOCAL\" --libdir=\"$SAGE_LOCAL/lib\" $SAGE_CONF_OPTS $MPIR_EXTRA_OPTS" 
    401494fi 
    402495 
    403 ./configure --prefix="$SAGE_LOCAL" $SAGE_CONF_OPTS $MPIR_EXTRA_OPTS 
     496./configure --prefix="$SAGE_LOCAL" --libdir="$SAGE_LOCAL/lib" $SAGE_CONF_OPTS $MPIR_EXTRA_OPTS 
    404497if [ $? -ne 0 ]; then 
    405     echo "Error configuring MPIR. (See above for the options passed to it.)" 
     498    echo >&2 "Error configuring MPIR. (See above for the options passed to it.)" 
    406499    exit 1 
    407500fi 
    408501 
     
    410503# Now build MPIR: 
    411504############################################################################### 
    412505 
     506echo "Now building MPIR..." 
    413507$MAKE 
    414508if [ $? -ne 0 ]; then 
    415     echo "Error building MPIR." 
     509    echo >&2 "Error building MPIR." 
    416510    exit 1 
    417511fi 
    418512 
     
    442536# Now install MPIR: 
    443537############################################################################### 
    444538 
     539echo "Now installing MPIR..." 
    445540# The potential race condition in `make install` was fixed in MPIR 2.1.4. 
    446541$MAKE install 
    447542if [ $? -ne 0 ]; then 
     
    451546    fi 
    452547fi 
    453548 
     549echo 
    454550echo "Remember to rebuild the Sage library ('./sage -b') such that it" 
    455551echo "will use the new MPIR." 
    456552echo "You may also have to (or want to) rebuild other Sage packages" 
     
    459555echo "    cd $SAGE_ROOT" 
    460556echo "    env SAGE_UPGRADING=yes make" 
    461557echo "but note that this will usually take quite a lot of time." 
     558echo