diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -2,11 +2,11 @@
 6c0000b82e9a27c7b6baeae6c68ee790e6b5a341 mpir-1.2.p3
 8910de51d3da6d9906c39cf8189486f176ed408c mpir-2.1.3.p1
 5cc6cee3d3d156416e5c4053f1479331baa3d5dd mpir-2.1.3.p2
-c7bccdf78798ca44893d002b5dc5ffd0d1995406 mpir-2.1.3.p3
-c7bccdf78798ca44893d002b5dc5ffd0d1995406 mpir-2.1.3.p3
 1ef781ef316a238a9fc4f28b19d0f2426a5196c0 mpir-2.1.3.p3
 8e43565fafb7d3211b4d91de7312744cfc34bf09 mpir-2.1.3.p4
 57a991f5baeeaa9c19d1367ebac8dd071e554b78 mpir-2.1.3.p5
 4f3644c720091f9a584e2c0cfab163f472d1c14e mpir-2.1.3.p6
 3b33192c35c487a7c77c2d623096f1dc1d48695f mpir-2.1.3.p7
 ea29d1f05281a05c2664c8362dcc65e6f0bbb52a mpir-2.1.3.p9
+99dba51e64053e990d9ade3be4e9b5aee69cb0ac mpir-2.1.3.p8
+d76b39da03c3d84bf84bbf26533a6cc511a09e13 mpir-2.4.0.p1
diff --git a/SPKG.txt b/SPKG.txt
--- a/SPKG.txt
+++ b/SPKG.txt
@@ -27,8 +27,6 @@
          each upgrade.)
  * Make sure the patches still apply; also, putting "-Wl,z,noexecstack"
    into LDFLAGS might not be necessary for later versions.
- * There is a race condition in `make install`, supposed to be fixed in
-   MPIR 2.1.4.  Currently we work around this by installing with -j1.
  * Perhaps make sure we still delete the correct files on 32-bit MacOS X
    on Intel hardware (x86) to not break PIC there.
  * Remove some files / directories not needed for Sage from upstream:
@@ -42,6 +40,16 @@
 
 == Changelog ==
 
+=== mpir-2.4.0.p1 (Leif Leonhardy, March 21st, 2012) ===
+ * Upstream upgrade to MPIR 2.4.0 (#11616).
+   The 2.4.0.p0 spkg isn't in this history, as it was based
+   on the 2.1.3.p4 spkg, i.e., is "on another branch",
+   and never got merged into Sage.
+ * Remove forcing a sequential `make install` again, since
+   the potential race condition was fixed in MPIR 2.1.4.
+ * Fix `.hgtags`, which contained duplicate entries, and
+   was missing others. 
+
 === mpir-2.1.3.p9 (Simon King, 11 December 2011) ===
  * #12131: Use --libdir, so that the package works on openSUSE
 
diff --git a/patches/gmp-h.in b/patches/gmp-h.in
--- a/patches/gmp-h.in
+++ b/patches/gmp-h.in
@@ -47,9 +47,6 @@
 #define GMP_NAIL_MASK     (~ GMP_NUMB_MASK)
 
 
-/* The following (everything under ifndef __GNU_MP__) must be identical in
-   mpir.h and mp.h to allow both to be included in an application or during
-   the library build.  */
 #ifndef __GNU_MP__
 #define __GNU_MP__ 4
 
@@ -67,6 +64,10 @@
 #define __GMP_LIBGMP_DLL  @LIBGMP_DLL@
 #endif
 
+/*  #if defined(__GMP_WITHIN_CONFIGURE) && defined(_WIN64)   */
+#ifdef __WIN64
+#define _LONG_LONG_LIMB	1
+#endif
 
 /* __STDC__ - some ANSI compilers define this only to 0, hence the use of
        "defined" and not "__STDC__-0".  In particular Sun workshop C 5.0
@@ -203,10 +204,12 @@
 #endif
 #endif
 
-#if defined( _MSC_VER ) && defined( _WIN64 )
+#ifdef _WIN64
 typedef unsigned long long int	mp_bitcnt_t;
+#define __GMP_BITCNT_MAX  (~(unsigned long long) 0)
 #else
 typedef unsigned long int mp_bitcnt_t;
+#define __GMP_BITCNT_MAX  (~(unsigned long) 0)
 #endif
 
 /* For reference, note that the name __mpz_struct gets into C++ mangled
@@ -228,12 +231,7 @@
 
 typedef mp_limb_t *		mp_ptr;
 typedef __gmp_const mp_limb_t *	mp_srcptr;
-#if defined (_CRAY) && ! defined (_CRAYMPP)
-/* plain `int' is much faster (48 bits) */
-#define __GMP_MP_SIZE_T_INT     1
-typedef int			mp_size_t;
-typedef int			mp_exp_t;
-#elif defined( _WIN64)
+#if defined( _WIN64)
 #define __GMP_MP_SIZE_T_INT     0
 typedef long long int	mp_size_t;
 typedef long int		mp_exp_t;
@@ -294,8 +292,6 @@
 typedef __mpq_struct *mpq_ptr;
 
 
-/* This is not wanted in mp.h, so put it outside the __GNU_MP__ common
-   section. */
 #if __GMP_LIBGMP_DLL
 #if __GMP_WITHIN_GMPXX
 /* compiling to go into a DLL libmpirxx */
@@ -334,7 +330,6 @@
   || defined (__STDIO_H)              /* Borland */             \
   || defined (__STDIO_H__)            /* IRIX */                \
   || defined (_STDIO_INCLUDED)        /* HPUX */                \
-  || defined (__dj_include_stdio_h_)  /* DJGPP */               \
   || defined (_FILE_DEFINED)          /* Microsoft */           \
   || defined (__STDIO__)              /* Apple MPW MrC */       \
   || defined (_MSL_STDIO_H)           /* Metrowerks */          \
@@ -529,13 +524,6 @@
 #define __GMP_UNLIKELY(cond)  (cond)
 #endif
 
-#ifdef _CRAY
-#define __GMP_CRAY_Pragma(str)  _Pragma (str)
-#else
-#define __GMP_CRAY_Pragma(str)
-#endif
-
-
 /* Allow direct user access to numerator and denominator of a mpq_t object.  */
 #define mpq_numref(Q) (&((Q)->_mp_num))
 #define mpq_denref(Q) (&((Q)->_mp_den))
@@ -732,7 +720,7 @@
 __GMP_DECLSPEC void mpz_cdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
 
 #define mpz_cdiv_q_2exp __gmpz_cdiv_q_2exp
-__GMP_DECLSPEC void mpz_cdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long));
+__GMP_DECLSPEC void mpz_cdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t));
 
 #define mpz_cdiv_q_ui __gmpz_cdiv_q_ui
 __GMP_DECLSPEC unsigned long int mpz_cdiv_q_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
@@ -1069,7 +1057,7 @@
 __GMP_DECLSPEC void mpz_realloc2 __GMP_PROTO ((mpz_ptr, mp_bitcnt_t));
 
 #define mpz_remove __gmpz_remove
-__GMP_DECLSPEC unsigned long int mpz_remove __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
+__GMP_DECLSPEC mp_bitcnt_t mpz_remove __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
 
 #define mpz_root __gmpz_root
 __GMP_DECLSPEC int mpz_root __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
@@ -1197,6 +1185,33 @@
 __GMP_DECLSPEC void mpz_xor __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
 
 
+/****** Integer (i.e. Z) routines for intmaax_t/uintmax_t types ******/
+
+#if defined( _STDINT_H ) || defined ( _STDINT_H_ ) || defined ( _STDINT )
+
+#define __GMP_BITS_PER_UINTMAX  (8*sizeof(uintmax_t))
+
+#define mpz_get_ux __gmpz_get_ux
+__GMP_DECLSPEC uintmax_t mpz_get_ux __GMP_PROTO ((mpz_srcptr));
+
+#define mpz_get_sx __gmpz_get_sx
+__GMP_DECLSPEC intmax_t mpz_get_sx __GMP_PROTO ((mpz_srcptr));
+
+#define mpz_set_ux __gmpz_set_ux
+__GMP_DECLSPEC void mpz_set_ux __GMP_PROTO ((mpz_ptr, uintmax_t));
+
+#define mpz_set_sx __gmpz_set_sx
+__GMP_DECLSPEC void mpz_set_sx __GMP_PROTO ((mpz_ptr, intmax_t));
+
+#define mpz_init_set_ux __gmpz_init_set_ux
+__GMP_DECLSPEC void mpz_init_set_ux __GMP_PROTO ((mpz_ptr, uintmax_t));
+
+#define mpz_init_set_sx __gmpz_init_set_sx
+__GMP_DECLSPEC void mpz_init_set_sx __GMP_PROTO ((mpz_ptr, intmax_t));
+
+#endif
+
+
 /**************** Rational (i.e. Q) routines.  ****************/
 
 #define mpq_abs __gmpq_abs
@@ -1354,7 +1369,7 @@
 __GMP_DECLSPEC void mpf_dump __GMP_PROTO ((mpf_srcptr));
 
 #define mpf_eq __gmpf_eq
-__GMP_DECLSPEC int mpf_eq __GMP_PROTO ((mpf_srcptr, mpf_srcptr, unsigned long int)) __GMP_ATTRIBUTE_PURE;
+__GMP_DECLSPEC int mpf_eq __GMP_PROTO ((mpf_srcptr, mpf_srcptr, mp_bitcnt_t)) __GMP_ATTRIBUTE_PURE;
 
 #define mpf_fits_sint_p __gmpf_fits_sint_p
 __GMP_DECLSPEC int mpf_fits_sint_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
@@ -1557,6 +1572,9 @@
 __GMP_DECLSPEC int mpn_cmp __GMP_PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE;
 #endif
 
+#define mpn_redc_1 __MPN(redc_1)
+__GMP_DECLSPEC void mpn_redc_1 __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);)
+
 #define mpn_divexact_by3(dst,src,size) \
   mpn_divexact_by3c (dst, src, size, __GMP_CAST (mp_limb_t, 0))
 
@@ -1877,7 +1895,7 @@
      "__GMP_ULONG_MAX < GMP_NUMB_MASK".  */
 #if GMP_NAIL_BITS == 0 || defined (_LONG_LONG_LIMB)
   /* limb==long and no nails, or limb==longlong, one limb is enough */
-  return (__gmp_n != 0 ? __gmp_l : 0);
+  return (unsigned long)(__gmp_n != 0 ? __gmp_l : 0);
 #else
   /* limb==long and nails, need two limbs when available */
   __gmp_n = __GMP_ABS (__gmp_n);
@@ -1942,7 +1960,7 @@
   mp_bitcnt_t    __gmp_result;
 
   __gmp_usize = __gmp_u->_mp_size;
-  __gmp_result = (__gmp_usize < 0 ? __GMP_ULONG_MAX : 0);
+  __gmp_result = (__gmp_usize < 0 ? __GMP_BITCNT_MAX : 0);
   if (__GMP_LIKELY (__gmp_usize > 0))
     __gmp_result =  mpn_popcount (__gmp_u->_mp_d, __gmp_usize);
   return __gmp_result;
@@ -2211,7 +2229,6 @@
     /* ASSERT ((start) >= 0); */                                \
     /* ASSERT ((start) <= (size)); */                           \
     /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, size)); */     \
-    __GMP_CRAY_Pragma ("_CRI ivdep");                           \
     for (__gmp_j = (start); __gmp_j < (size); __gmp_j++)        \
       (dst)[__gmp_j] = (src)[__gmp_j];                          \
   } while (0)
@@ -2378,14 +2395,14 @@
 /* Major version number is the value of __GNU_MP__ too, above and in mp.h. */
 #define __GNU_MP_VERSION 5 
 #define __GNU_MP_VERSION_MINOR 0 
-#define __GNU_MP_VERSION_PATCHLEVEL 1
-#define GMP_VERSION "5.0.1"
+#define __GNU_MP_VERSION_PATCHLEVEL 2
+#define GMP_VERSION "5.0.2"
 
 #define __MPIR_VERSION 2
-#define __MPIR_VERSION_MINOR 1
-#define __MPIR_VERSION_PATCHLEVEL 3
+#define __MPIR_VERSION_MINOR 4
+#define __MPIR_VERSION_PATCHLEVEL 0
 #if defined( _MSC_VER )
-#define _MSC_MPIR_VERSION "2.1.3"
+#define _MSC_MPIR_VERSION "2.4.0"
 #endif
 
 /* These are for programs like MPFR to use the same CC and CFLAGS as MPIR */
diff --git a/spkg-install b/spkg-install
--- a/spkg-install
+++ b/spkg-install
@@ -75,6 +75,11 @@
         exit 1
     fi
     header_file=$1
+    # We'll probably have to change the following patterns (conditionally) when we
+    # upgrade to MPIR >=2.5.0(?), since MPIR's gmp.h was changed to define __GMP_CC
+    # to (literally) __MPIR_CC, and likewise __GMP_CFLAGS to __MPIR_CFLAGS.
+    # I.e., in later releases __MPIR_CC and __MPIR_CFLAGS will contain the real strings
+    # we need (unless they again change this; I've already complained about that).
     gmp_cc_pat='/^[ 	]*#[ 	]*define[ 	]\+__GMP_CC[ 	]\+/s/.*"\([^"]*\)"/\1/p'
     gmp_cflags_pat='/^[ 	]*#[ 	]*define[ 	]\+__GMP_CFLAGS[ 	]\+/s/.*"\([^"]*\)"/\1/p'
     if ! [ -f "$header_file" ]; then
@@ -128,11 +133,17 @@
 # The Yasm build uses PYTHON from the environment to find python, so unset
 # it since the setting from 'spkg/standard/newest_version' confuses it:
 unset PYTHON
+# This can be removed once #10492 has been merged, which turns the "package
+# version" environment variables into solely `make` variables, such that the
+# (shell) environment does no longer get polluted. 
 
 user_cflags=$CFLAGS # Save them. 'sage-env' sets CC, but not CFLAGS.
 required_cflags="" # Additional mandatory settings required by Sage, accumulated below.
 default_cflags="" # Spkg defaults that can and might get overridden.
+
+# Newer autotools may put libs into .../lib64 (on 64-bit systems):
 SAGE_CONF_OPTS=--libdir="$SAGE_LOCAL/lib"
+# (Further options to `configure` are added below.)
 
 
 if [ -z "$CFLAG32" ]; then
@@ -201,11 +212,11 @@
             # on both 64-bit and 32-bit, though this is likely to change.
             case "`uname -m`" in
             i[3456]86)
-                echo "** Building with FAT Binary Support (32-bit) **"
+                echo "** Building with \"fat binary\" support for 32-bit CPUs **"
                 SAGE_CONF_OPTS="$SAGE_CONF_OPTS --enable-fat"
                 ;;
             x86_64|amd64)
-                echo "** Building with FAT Binary Support (64-bit) **"
+                echo "** Building with \"fat binary\" support for 64-bit CPUs **"
                 SAGE_CONF_OPTS="$SAGE_CONF_OPTS --enable-fat"
                 ;;
             *) # e.g. ia64 (Itanium) or PPC (ppc, ppc64)
@@ -251,7 +262,7 @@
         ;;
     *) # e.g. AIX or HP-UX
         echo "Warning: Your platform ($UNAME) isn't yet explicitly supported" \
-            "in this spkg."
+            "by this MPIR spkg, i.e., by Sage's part of it."
 esac
 
 export ABI CFLAGS CXXFLAGS # Partially redundant, but safe(r).
@@ -382,7 +393,7 @@
     echo "    --prefix=\"$SAGE_LOCAL\" $SAGE_CONF_OPTS"
     echo "You can set MPIR_EXTRA_OPTS to pass additional parameters."
 else
-    echo "Using additional 'configure' options as specified with" \
+    echo "Using additional 'configure' options as specified through" \
         "MPIR_EXTRA_OPTS:"
     echo "    $MPIR_EXTRA_OPTS"
     echo "Configuring MPIR with the following options:"
@@ -431,8 +442,8 @@
 # Now install MPIR:
 ###############################################################################
 
-# Serial make since parallel is broken (#12139).
-$MAKE -j1 install
+# The potential race condition in `make install` was fixed in MPIR 2.1.4.
+$MAKE install
 if [ $? -ne 0 ]; then
     echo >&2 "Error installing MPIR."
     if [ "$UNAME" != "CYGWIN" ]; then  # On Cygwin an error is not fatal.
@@ -443,7 +454,7 @@
 echo "Remember to rebuild the Sage library ('./sage -b') such that it"
 echo "will use the new MPIR."
 echo "You may also have to (or want to) rebuild other Sage packages"
-echo "that use MPIR. Provided that this MPIR spkg is in 'spkg/standard/',"
+echo "that use MPIR.  Provided that this MPIR spkg is in 'spkg/standard/',"
 echo "you can rebuild all packages depending on MPIR by typing:"
 echo "    cd $SAGE_ROOT"
 echo "    env SAGE_UPGRADING=yes make"
