Ticket #11666: trac_11666_spkg.patch

File trac_11666_spkg.patch, 24.5 KB (added by jpflori, 7 years ago)

spkg diff, for review only

  • .hgtags

    diff -r c24b1e8f4ba1 -r f762203bee23 .hgtags
    a b  
    117b48a0b7db66d47bd5b361fb6b0f690c241a9ef5 mpfr-2.4.2.p0
    228094e7388f5bae4105a4e3ff49967fd246817559 mpfr-2.4.2.p1
     3c24b1e8f4ba1fce31bb2ea48bb069bedaebe3d32 mpfr-2.4.2.p2
     4ad149c890ee193fbe7d2fdbebf94dee20eb6a612 mpfr-3.1.0
     5834f2c4e0347c2e4249d94188203d93cea44d92a mpfr-3.1.0.p0
  • SPKG.txt

    diff -r c24b1e8f4ba1 -r f762203bee23 SPKG.txt
    a b  
    22
    33== Description ==
    44
    5 From http://mpfr.org/: The MPFR library is a C library for multiple-precision
    6 floating-point computations with correct rounding. MPFR has continuously been
    7 supported by the INRIA and the current main authors come from the CACAO and
    8 Arenaire project-teams at Loria (Nancy, France) and LIP (Lyon, France)
    9 respectively; see more on the credit page. MPFR is based on the GMP
    10 multiple-precision library.
     5The MPFR library is a C library for multiple-precision floating-point
     6computations with correct rounding. MPFR has continuously been supported by
     7the INRIA and the current main authors come from the Caramel and Arénaire
     8project-teams at Loria (Nancy, France) and LIP (Lyon, France) respectively;
     9see more on the credit page. MPFR is based on the GMP multiple-precision
     10library.
     11
     12The main goal of MPFR is to provide a library for multiple-precision
     13floating-point computation which is both efficient and has a well-defined
     14semantics. It copies the good ideas from the ANSI/IEEE-754 standard for
     15double-precision floating-point arithmetic (53-bit significand).
    1116
    1217== License ==
    1318
    14 MPFR is free. It is distributed under the GNU Lesser General Public License
    15 (GNU Lesser GPL), version 2.1 or later.
     19MPFR is free. It is distributed under the GNU Lesser General Public License
     20(GNU Lesser GPL), version 3 or later (2.1 or later for MPFR versions until
     212.4.x). The library has been registered in France by the Agence de Protection
     22des Programmes under the number IDDN FR 001 120020 00 R P 2000 000 10800, on
     2315 March 2000. This license guarantees your freedom to share and change MPFR,
     24to make sure MPFR is free for all its users. Unlike the ordinary General
     25Public License, the Lesser GPL enables developers of non-free programs to use
     26MPFR in their programs. If you have written a new function for MPFR or improved
     27an existing one, please share your work!
    1628
    1729== SPKG Maintainers ==
    1830
     
    2638
    2739== Dependencies ==
    2840
    29  * GMP
     41 * MPIR
    3042
    3143== IMPORTANT ==
    32 When building Sage binaries for widespead distribution, set the variable 
     44When building Sage binaries for widespead distribution, set the variable
    3345INCLUDE_MPFR_PATCH to 1, to include a patch, which can cause failures
    34 on sun4v machines. 
     46on sun4v machines.
    3547
    3648== Changelog ==
    3749
     50=== mpfr-3.1.0.p0 (Jean-Pierre Flori, February 22nd, 2012) ===
     51 * #11666: Further cleanups and rebase on #12131, #12366 and #12548.
     52 * Let configure get the MPIR flags.
     53
     54=== mpfr-3.1.0 (Mike Hansen, December 17th, 2011) ===
     55 * #11666: Upgrade MPFR to 3.1.0
     56 * Update spkg-install and spkg-check files to current standards
     57
    3858=== mpfr-2.4.2.p2 (Jeroen Demeyer, 20 February 2012) ===
    3959 * #12548: do not delete old libraries
    4060
     
    5474 * Make SAGE64 work also on Open Solaris 64 bit
    5575
    5676=== mpfr-2.4.1p0 (David Kirkby, July 17th 2009) ===
    57  * Sage TRAC #6453 http://sagetrac.org/sage_trac/ticket/6453 
    58    Implement a patch to mpn_exp.c developed by Paul Zimmermann 
    59    (Paul.Zimmermann@loria.fr) to bypass what may be a Solaris or gcc bug. 
    60    This avoids 20 test failures on a Sun T5240 running Solaris 10 (both 
     77 * Sage TRAC #6453 http://sagetrac.org/sage_trac/ticket/6453
     78   Implement a patch to mpn_exp.c developed by Paul Zimmermann
     79   (Paul.Zimmermann@loria.fr) to bypass what may be a Solaris or gcc bug.
     80   This avoids 20 test failures on a Sun T5240 running Solaris 10 (both
    6181   updates 4 and 7 have been tried on this machine). Since it's only seen
    6282   there, the patch is very specific and is only applied on those machines, not
    6383   all Solaris systems by default, but can be over-ridden with an environment
    64    variable INCLUDE_MPFR_PATCH (set to 1 to include patch, 0 to exclude it). 
    65    If INCLUDE_MPFR_PATCH is unset, the patch will be included on sun4v systems, 
     84   variable INCLUDE_MPFR_PATCH (set to 1 to include patch, 0 to exclude it).
     85   If INCLUDE_MPFR_PATCH is unset, the patch will be included on sun4v systems,
    6686   but exluded on all others. Please set it to 1 if building binaries for others.
    6787
    6888   This is a bug in Solaris's memset() function, for more information see
    6989   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40757
    7090
    7191 * Remove a comment at the bottom of spkg-install telling developers to bypass
    72    check on release systems. Given failures have occured, it would be unwise to
    73    bypass any checks.
    74    Note, the checks were performed in Sage 4.1, so despite a coment saying
    75    checks should be bypassed in 'releases' they were in fact not bypassed.
    76    The tests were already executed, which is how the bug was discovered.
    77    
    78  * Add a comment to remind people not to bypass the tests, pointing out
    79    failures had occured, so it would be unwise to bypass checks.
     92   check on release systems. Given failures have occured, it would be unwise to
     93   bypass any checks.
     94   Note, the checks were performed in Sage 4.1, so despite a coment saying
     95   checks should be bypassed in 'releases' they were in fact not bypassed.
     96   The tests were already executed, which is how the bug was discovered.
    8097
    81  * Update the source to use the latest patches, as strongly reccommened in the
     98 * Add a comment to remind people not to bypass the tests, pointing out
     99   failures had occured, so it would be unwise to bypass checks.
     100
     101 * Update the source to use the latest patches, as strongly reccommened in the
    82102   INSTALL file. This brings the code to MPFR 2.4.1 patch level 5, though I'm
    83103   considering it mpfr-2.4.1p0 for Sage purposes.
    84104
     
    108128=== mpfr-2.3.0 (Michael Abshoff, Sept. 14th, 2007) ===
    109129 * upgrade to mpfr 2.3.0 release
    110130 * add spkg-check
    111 
  • patches/mpn_exp.c

    diff -r c24b1e8f4ba1 -r f762203bee23 patches/mpn_exp.c
    a b  
    11/* mpfr_mpn_exp -- auxiliary function for mpfr_get_str and mpfr_set_str
    22
    3 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
    4 Contributed by the Arenaire and Cacao projects, INRIA.
    5 Contributed by Alain Delplanque and Paul Zimmermann.
     3Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
     4Contributed by the Arenaire and Caramel projects, INRIA.
    65
    76This file is part of the GNU MPFR Library.
    87
    98The GNU MPFR Library is free software; you can redistribute it and/or modify
    109it under the terms of the GNU Lesser General Public License as published by
    11 the Free Software Foundation; either version 2.1 of the License, or (at your
     10the Free Software Foundation; either version 3 of the License, or (at your
    1211option) any later version.
    1312
    1413The GNU MPFR Library is distributed in the hope that it will be useful, but
     
    1716License for more details.
    1817
    1918You should have received a copy of the GNU Lesser General Public License
    20 along with the GNU MPFR Library; see the file COPYING.LIB.  If not, write to
    21 the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
    22 MA 02110-1301, USA. */
     19along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
     20http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
     2151 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
    2322
    2423
    2524#define MPFR_NEED_LONGLONG_H
    2625#include "mpfr-impl.h"
    2726
    2827/* this function computes an approximation of b^e in {a, n}, with exponent
    29    stored in exp_r. The computed value is rounded towards zero (truncated).
     28   stored in exp_r. The computed value is rounded toward zero (truncated).
    3029   It returns an integer f such that the final error is bounded by 2^f ulps,
    3130   that is:
    3231   a*2^exp_r <= b^e <= 2^exp_r (a + 2^f),
    3332   where a represents {a, n}, i.e. the integer
    34    a[0] + a[1]*B + ... + a[n-1]*B^(n-1) where B=2^BITS_PER_MP_LIMB
     33   a[0] + a[1]*B + ... + a[n-1]*B^(n-1) where B=2^GMP_NUMB_BITS
    3534
    3635   Return -1 is the result is exact.
    3736   Return -2 if an overflow occurred in the computation of exp_r.
    3837*/
    3938
    4039long
    41 mpfr_mpn_exp (mp_limb_t *a, mp_exp_t *exp_r, int b, mp_exp_t e, size_t n)
     40mpfr_mpn_exp (mp_limb_t *a, mpfr_exp_t *exp_r, int b, mpfr_exp_t e, size_t n)
    4241{
    4342  mp_limb_t *c, B;
    44   mp_exp_t f, h;
     43  mpfr_exp_t f, h;
    4544  int i;
    4645  unsigned long t; /* number of bits in e */
    4746  unsigned long bits;
     
    5352  MPFR_TMP_DECL(marker);
    5453
    5554  MPFR_ASSERTN(e > 0);
    56   MPFR_ASSERTN((2 <= b) && (b <= 36));
     55  MPFR_ASSERTN((2 <= b) && (b <= 62));
    5756
    5857  MPFR_TMP_MARK(marker);
    5958
     
    6362  B = (mp_limb_t) b;
    6463  count_leading_zeros (h, B);
    6564
    66   bits = BITS_PER_MP_LIMB - h;
     65  bits = GMP_NUMB_BITS - h;
    6766
    6867  B = B << h;
    6968  h = - h;
    7069
    7170  /* allocate space for A and set it to B */
    72   c = (mp_limb_t*) MPFR_TMP_ALLOC(2 * n * BYTES_PER_MP_LIMB);
     71  c = MPFR_TMP_LIMBS_ALLOC (2 * n);
    7372  a [n - 1] = B;
    7473  /* The following couple of lines work around a bug seen so far only on
    7574  a Sun T5240 with a pair of T2+ processors. It only happens with some versions
     
    8483    MPN_ZERO (a, n - 1);
    8584
    8685  /* initial exponent for A: invariant is A = {a, n} * 2^f */
    87   f = h - (n - 1) * BITS_PER_MP_LIMB;
     86  f = h - (n - 1) * GMP_NUMB_BITS;
    8887
    8988  /* determine number of bits in e */
    9089  count_leading_zeros (t, (mp_limb_t) e);
    9190
    92   t = BITS_PER_MP_LIMB - t; /* number of bits of exponent e */
     91  t = GMP_NUMB_BITS - t; /* number of bits of exponent e */
    9392
    94   error = t; /* error <= BITS_PER_MP_LIMB */
     93  error = t; /* error <= GMP_NUMB_BITS */
    9594
    9695  MPN_ZERO (c, 2 * n);
    9796
     
    9998    {
    10099
    101100      /* determine precision needed */
    102       bits = n * BITS_PER_MP_LIMB - mpn_scan1 (a, 0);
    103       n1 = (n * BITS_PER_MP_LIMB - bits) / BITS_PER_MP_LIMB;
     101      bits = n * GMP_NUMB_BITS - mpn_scan1 (a, 0);
     102      n1 = (n * GMP_NUMB_BITS - bits) / GMP_NUMB_BITS;
    104103
    105104      /* square of A : {c+2n1, 2(n-n1)} = {a+n1, n-n1}^2 */
    106105      mpn_sqr_n (c + 2 * n1, a + n1, n - n1);
     
    114113          MPFR_TMP_FREE(marker);
    115114          return -2;
    116115        }
    117       /* FIXME: Could f = 2*f + n * BITS_PER_MP_LIMB be used? */
     116      /* FIXME: Could f = 2*f + n * GMP_NUMB_BITS be used? */
    118117      f = 2*f;
    119       MPFR_SADD_OVERFLOW (f, f, n * BITS_PER_MP_LIMB,
    120                           mp_exp_t, mp_exp_unsigned_t,
     118      MPFR_SADD_OVERFLOW (f, f, n * GMP_NUMB_BITS,
     119                          mpfr_exp_t, mpfr_uexp_t,
    121120                          MPFR_EXP_MIN, MPFR_EXP_MAX,
    122121                          goto overflow, goto overflow);
    123122      if ((c[2*n - 1] & MPFR_LIMB_HIGHBIT) == 0)
     
    133132        MPN_COPY (a, c + n, n);
    134133
    135134      if ((error == t) && (2 * n1 <= n) &&
    136           (mpn_scan1 (c + 2 * n1, 0) < (n - 2 * n1) * BITS_PER_MP_LIMB))
     135          (mpn_scan1 (c + 2 * n1, 0) < (n - 2 * n1) * GMP_NUMB_BITS))
    137136        error = i;
    138137
    139       if (e & ((mp_exp_t) 1 << i))
     138      if (e & ((mpfr_exp_t) 1 << i))
    140139        {
    141140          /* multiply A by B */
    142141          c[2 * n - 1] = mpn_mul_1 (c + n - 1, a, n, B);
    143           f += h + BITS_PER_MP_LIMB;
     142          f += h + GMP_NUMB_BITS;
    144143          if ((c[2 * n - 1] & MPFR_LIMB_HIGHBIT) == 0)
    145144            { /* shift A by one bit to the left */
    146145              mpn_lshift (a, c + n, n, 1);
     
    164163
    165164  if (error == t)
    166165    return -1; /* result is exact */
    167   else /* error <= t-2 <= BITS_PER_MP_LIMB-2
     166  else /* error <= t-2 <= GMP_NUMB_BITS-2
    168167          err_s_ab, err_s_a2 <= t-1       */
    169168    {
    170169      /* if there are p loops after the first inexact result, with
     
    174173      */
    175174      error = error + err_s_ab + err_s_a2 / 2 + 3; /* <= 5t/2-1/2 */
    176175#if 0
    177       if ((error - 1) >= ((n * BITS_PER_MP_LIMB - 1) / 2))
    178         error = n * BITS_PER_MP_LIMB; /* result is completely wrong:
     176      if ((error - 1) >= ((n * GMP_NUMB_BITS - 1) / 2))
     177        error = n * GMP_NUMB_BITS; /* result is completely wrong:
    179178                                         this is very unlikely since error is
    180179                                         at most 5/2*log_2(e), and
    181                                          n * BITS_PER_MP_LIMB is at least
     180                                         n * GMP_NUMB_BITS is at least
    182181                                         3*log_2(e) */
    183182#endif
    184183      return error;
  • patches/mpn_exp.c.patch

    diff -r c24b1e8f4ba1 -r f762203bee23 patches/mpn_exp.c.patch
    a b  
    1 --- mpn_exp.c.orig      Fri Feb 20 01:43:17 2009
    2 +++ mpn_exp.c   Thu Jul 16 17:25:20 2009
    3 @@ -71,7 +71,18 @@
     1--- ../src/src/mpn_exp.c        2011-10-03 09:17:09.000000000 +0100
     2+++ mpn_exp.c   2011-12-17 09:57:30.000000000 +0000
     3@@ -70,7 +70,18 @@
    44   /* allocate space for A and set it to B */
    5    c = (mp_limb_t*) MPFR_TMP_ALLOC(2 * n * BYTES_PER_MP_LIMB);
     5   c = MPFR_TMP_LIMBS_ALLOC (2 * n);
    66   a [n - 1] = B;
    77-  MPN_ZERO (a, n - 1);
    88+  /* The following couple of lines work around a bug seen so far only on
     
    1818+    MPN_ZERO (a, n - 1);
    1919+
    2020   /* initial exponent for A: invariant is A = {a, n} * 2^f */
    21    f = h - (n - 1) * BITS_PER_MP_LIMB;
     21   f = h - (n - 1) * GMP_NUMB_BITS;
    2222 
  • spkg-check

    diff -r c24b1e8f4ba1 -r f762203bee23 spkg-check
    a b  
     1#!/usr/bin/env bash
     2
     3if [ -z "$SAGE_LOCAL" ]; then
     4    echo "Error: SAGE_LOCAL undefined - exiting..."
     5    echo "Maybe run 'sage -sh'?"
     6    exit 1
     7fi
     8
     9# unset RM since it messes with libtool
     10unset RM
     11
    112cd src
    2 make check
    313
     14$MAKE check
    415if [ $? -ne 0 ]; then
    5   echo "There was a problem during the mpfr tests."
     16  echo "Error: the MPFR test suite failed."
    617  exit 1
    718fi
    8 
  • spkg-install

    diff -r c24b1e8f4ba1 -r f762203bee23 spkg-install
    a b  
    1 #!/bin/sh
     1#!/usr/bin/env bash
    22
    3 if [ "$SAGE_LOCAL" = "" ]; then
    4    echo "SAGE_LOCAL undefined ... exiting";
    5    echo "Maybe run 'sage -sh'?"
    6    exit 1
     3if [ -z "$SAGE_LOCAL" ]; then
     4    echo "Error: SAGE_LOCAL undefined - exiting..."
     5    echo "Maybe run 'sage -sh'?"
     6    exit 1
    77fi
    88
    9 # unset RM since it messes with libtool for "make check"
     9# unset RM since it messes with libtool
    1010unset RM
    1111
    12 build()
     12mpfr_patch()
    1313{
    14     if [ "$SAGE64" = "yes" ]; then
    15          echo "64 bit build"
    16          CFLAGS="-O2 -g -m64 "; export CFLAGS
    17          CXXFLAGS="-O2 -g -m64 "; export CXXFLAGS
    18          CPPFLAGS="-O2 -g -m64 "; export CPPFLAGS
    19     fi
    20 
    21     EXTRA=""
    2214    # Apply a patch on Solaris, but only on the sun4v architecture
    23     # by default. On other Solaris systems, it can be over-ridden
     15    # by default. On other Solaris systems, it can be overridden
    2416
    2517    # The patch to the C code was developed by Paul Zimmermann, the patch
    26     # to the spkg-install by David Kirkby. See  Ticket #6453
     18    # to the spkg-install by David Kirkby. See Ticket #6453
    2719
    2820    if [ `uname` = "SunOS" ]; then
    2921       # Add a patch to MPFR on Solaris if either:
    3022       # 1) The machine is a sun4v architecture
    3123       # 2) The environment variable INCLUDE_MPFR_PATCH is set to 1
    32        #    This will allow creating of binaries on a machine other than 
    33        #    sun4v, which will run on sun4v. 
     24       #    This will allow creating of binaries on a machine other than
     25       #    sun4v, which will run on sun4v.
    3426       echo "\nThis computer is running Solaris on which some problems have been observed"
    3527       echo "with the MPFR library running on a T2+ processor (sun4v architecture)."
    3628       echo "See http://sagetrac.org/sage_trac/ticket/6453 A patch can be applied"
     
    4941
    5042       # Note, "/usr/bin/arch" will return "sun4" on any SPARC system
    5143       # If given the '-k' option, aditional information will be displayed
    52        # to indicate if the system is sun4m (very old), sun4u or sun4v 
     44       # to indicate if the system is sun4m (very old), sun4u or sun4v
    5345
    5446       # Set the variable PATCH_MPFR to something other than 0 or 1"
    5547       PATCH_MPFR="${INCLUDE_MPFR_PATCH-2}"
    5648       if [ $PATCH_MPFR = "1" ] ; then
    5749          echo "Since INCLUDE_MPFR_PATCH was set to 1, the MPFR library will be patched."
    5850          echo "The binaries should be safe on any Solaris system"
    59           cp ../patches/mpn_exp.c mpn_exp.c
    60        elif [ $PATCH_MPFR = "0" ] ; then 
     51          cp ../patches/mpn_exp.c src/mpn_exp.c
     52       elif [ $PATCH_MPFR = "0" ] ; then
    6153          echo "Since INCLUDE_MPFR_PATCH was set to 0, the MPFR library will not"
    6254          echo "be patched. You would be unwise to distribute SPARC binaries"
    6355          echo "unless you are sure they will not be used on sun4v systems"
     
    6557          echo "This is a sun4v system, so the MPFR library will be patched. The binaries"
    6658          echo "should run correctly on any SPARC system whose operating system is"
    6759          echo "no older than the system used to build the binaries."
    68           cp ../patches/mpn_exp.c mpn_exp.c
     60          cp ../patches/mpn_exp.c src/mpn_exp.c
    6961       elif [ $PATCH_MPFR = "2" -a `arch -k` != "sun4v" ] ; then
    7062          echo "Since this is not a sun4v system, the MPFR binary will not"
    7163          echo "be patched"
     
    7870          fi
    7971       else
    8072          echo "The environment variable INCLUDE_MPFR_PATCH was set incorrectly The MPFR"
    81           echo "library will be patched as a precaution." 
    82           cp ../patches/mpn_exp.c mpn_exp.c
     73          echo "library will be patched as a precaution."
     74          cp ../patches/mpn_exp.c src/mpn_exp.c
    8375       fi
    8476    fi
     77
     78}
     79
     80mpfr_get_upstream_selected_cflags() # Get MPFR's choice on empty CC and CFLAGS.
     81{
     82    if [ $# -ne 1 ]; then
     83        echo "Error: mpfr_get_upstream_selected_cflags() requires 'file' parameter."
     84        exit 1
     85    fi
     86    header_file=$1
     87    mpfr_cc_pat="s/^CC='\([^']*\)'/\1/p"
     88    mpfr_cflags_pat="s/^CFLAGS='\([^']*\)'/\1/p"
     89    if ! [ -f "$header_file" ]; then
     90        upstream_cc=""
     91        upstream_cflags=""
     92        return 1
     93    fi
     94    upstream_cc=`sed -n -e "$mpfr_cc_pat" "$header_file"`
     95    upstream_cflags=`sed -n -e "$mpfr_cflags_pat" "$header_file"`
     96    return 0
     97}
     98
     99mpfr_configure()
     100{
     101    sage_cc=$CC # Save Sage CC, because we need to unset it later.
     102    user_cflags=$CFLAGS # Save them. 'sage-env' sets CC, but not CFLAGS.
     103    required_cflags="" # Additional mandatory settings required by Sage, accumulated below.
     104    default_cflags="" # Spkg defaults that can and might get overridden.
     105
     106    if [ "$SAGE_DEBUG" = yes ]; then
     107        # Disable optimization, add debug symbols:
     108        required_cflags="$required_cflags -g -O0"
     109        echo "Warning: Building MPFR with SAGE_DEBUG=yes disables optimization."
     110    else
     111        # Add debug symbols by default, enable optimization, but do not (yet)
     112        # add processor-specific flags (these are eventually added later):
     113        default_cflags="$default_cflags -g -O3"
     114    fi
     115
     116    if [ "$SAGE64" = "yes" ]; then
     117        echo "Building a 64-bit version of MPFR."
     118        default_cflags="$default_cflags -m64"
     119    else
     120        default_cflags="$default_cflags"
     121    fi
     122
     123    SAGE_CONF_OPTS="--libdir=$SAGE_LOCAL/lib --disable-thread-safe"
    85124    if [ ! -f "$SAGE_LOCAL/include/gmp.h" ]; then
    86          EXTRA="--disable-static --enable-shared"
     125         SAGE_CONF_OPTS="$SAGE_CONF_OPTS --disable-static --enable-shared"
    87126    fi
    88127
    89128    if [ $UNAME = "CYGWIN" ]; then
    90          EXTRA="--disable-static --enable-shared"
     129         SAGE_CONF_OPTS="$SAGE_CONF_OPTS --disable-static --enable-shared"
     130
    91131    fi
    92132
    93     ./configure --prefix=$SAGE_LOCAL --libdir="$SAGE_LOCAL/lib" --with-gmp=$SAGE_LOCAL \
    94                  CFLAGS="$CFLAGS $SHAREDFLAGS -O2" CXX="$CXX" \
    95                  CXXFLAGS="$CXXFLAGS $SHAREDFLAGS" LDFLAGS="$LDFLAGS" \
    96                  GMP_PREFIX="$SAGE_LOCAL" $EXTRA
    97     if [ $? -ne 0 ];  then
    98         echo >&2 "Error configuring mpfr."
     133    # Pre-configure MPFR to get the settings it would use if CC and CFLAGS were empty:
     134    echo "Checking what CC and CFLAGS MPFR would use if they were empty..."
     135    if (unset CC CFLAGS CPPFLAGS CXXFLAGS &&
     136        ./configure --with-gmp="$SAGE_LOCAL" $SAGE_CONF_OPTS $MPFR_EXTRA_OPTS) &>/dev/null;
     137    then
     138        if mpfr_get_upstream_selected_cflags config.status; then
     139            mpfr_cflags=$upstream_cflags
     140            mpfr_cc=$upstream_cc
     141            echo "Settings chosen by MPFR when configuring with CC and CFLAGS unset:"
     142            echo "  CC:      $mpfr_cc"
     143            echo "  CFLAGS:  $mpfr_cflags"
     144        else
     145            echo "Warning: Couldn't determine MPFR-selected CC and CFLAGS from 'mpfr.h'"
     146        fi
     147    else
     148        # We ignore errors in the first place, since we redirected all
     149        # messages to /dev/null. (The messages can be found in the 'config.log'
     150        # files if someone really wants to read them.)
     151        :;
     152    fi
     153    find . -name config.cache -o -name config.status -exec rm -f {} \;
     154    CC=$sage_cc
     155
     156    echo "Settings required to properly build MPFR, taking into account SAGE_DEBUG etc.:"
     157    echo "  CFLAGS:  $required_cflags"
     158    echo "  LDFLAGS: $LDFLAGS" # Might be empty, or specified by the user.
     159    echo "  ABI:     $ABI" # Might be empty, or specified by the user.
     160    echo "Settings from the \"global\" environment:"
     161    echo "  CC:      $CC" # Set by Sage, maybe overridden by the user.
     162    echo "  CFLAGS:  $user_cflags"
     163    echo "  (CPPFLAGS, CXX and CXXFLAGS are listed below; these don't get modified.)"
     164
     165    if [ -z "$user_cflags" ]; then
     166        # No CFLAGS specified by user => Use either MPFR's or our default ones,
     167        # plus those required by Sage for the package to build properly:
     168        if [ -n "$mpfr_cflags" ]; then
     169            # Fine. Use upstream settings.
     170            echo "Using MPFR's settings (plus mandatory ones)."
     171            CFLAGS="$mpfr_cflags $required_cflags"
     172        else # Use spkg's defaults.
     173            echo "Using the spkg's (i.e. Sage's) default (plus mandatory) settings."
     174            CFLAGS="$default_cflags $required_cflags"
     175        fi
     176    else
     177        # CFLAGS were specified by the user, so don't override them (unless
     178        # necessary).
     179        echo "Using user-specified settings (overriding defaults), with some additions."
     180        CFLAGS="$default_cflags $user_cflags $required_cflags"
     181    fi
     182
     183    echo "Finally using the following settings:"
     184    echo "  CC=$CC"
     185    echo "  CFLAGS=$CFLAGS"
     186    echo "  CPPFLAGS=$CPPFLAGS"
     187    echo "  CXX=$CXX"
     188    echo "  CXXFLAGS=$CXXFLAGS"
     189    echo "  LDFLAGS=$LDFLAGS"
     190    echo "  ABI=$ABI"
     191    echo "(These settings may still get overridden by 'configure' or Makefiles.)"
     192
     193    ###############################################################################
     194    # Now really configure MPFR with proper settings:
     195    ###############################################################################
     196    if [ -z "$MPFR_EXTRA_OPTS" ]; then
     197        echo "Configuring MPFR with the following options:"
     198        echo "    --prefix=\"$SAGE_LOCAL\" --with-gmp=\"$SAGE_LOCAL\" $SAGE_CONF_OPTS"
     199        echo "You can set MPFR_EXTRA_OPTS to pass additional parameters."
     200    else
     201        echo "Using additional 'configure' options as specified with" \
     202            "MPFR_EXTRA_OPTS:"
     203        echo "    $MPFR_EXTRA_OPTS"
     204        echo "Configuring MPFR with the following options:"
     205        echo "    --prefix=\"$SAGE_LOCAL\" --with-gmp=\"$SAGE_LOCAL\" $SAGE_CONF_OPTS $MPFR_EXTRA_OPTS"
     206    fi
     207
     208    ./configure --prefix="$SAGE_LOCAL" --with-gmp="$SAGE_LOCAL" $SAGE_CONF_OPTS $MPFR_EXTRA_OPTS
     209}
     210
     211mpfr_build()
     212{
     213    echo "Patching MPFR"
     214    mpfr_patch
     215    if [ $? -ne 0 ];  then
     216        echo >&2 "Error patching MPFR."
    99217        exit 1
    100     fi
     218    fi
     219
     220    echo "Configuring MPFR"
     221    mpfr_configure
     222    if [ $? -ne 0 ]; then
     223        echo >&2 "Error configuring MPFR."\
     224            "(See above for the options passed to it.)"
     225        exit 1
     226    fi
    101227
    102228    echo "Building MPFR"
    103229    $MAKE
    104     if [ $? -ne 0 ];  then 
    105         echo >&2 "Error building mpfr."
     230    if [ $? -ne 0 ];  then
     231        echo >&2 "Error building MPFR."
    106232        exit 1
    107     fi 
     233    fi
    108234
    109235    echo "Deleting old headers"
    110236    rm -f "$SAGE_LOCAL"/include/*mpfr*
     
    114240
    115241    echo "Installing MPFR"
    116242    $MAKE install
    117     if [ $? -ne 0 ];  then 
    118         echo >&2 "Error installing mpfr."
     243    if [ $? -ne 0 ];  then
     244        echo >&2 "Error installing MPFR."
    119245        exit 1
    120     fi 
     246    fi
    121247}
    122248
    123249cd src
    124250
    125 build
     251mpfr_build