about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/science/math
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-04-28 14:39:00 +0000
committerAlyssa Ross <hi@alyssa.is>2021-06-10 08:52:36 +0000
commit693e64ef7421374338ddb1dc12b9573feec75972 (patch)
tree2526ac075d248699c35d63e04499890ee4381f5f /nixpkgs/pkgs/applications/science/math
parent7014df2256694d97093d6f2bb1db340d346dea88 (diff)
parent8e4fe32876ca15e3d5eb3ecd3ca0b224417f5f17 (diff)
downloadnixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.gz
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.bz2
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.lz
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.xz
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.zst
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.zip
Merge commit '8e4fe32876ca15e3d5eb3ecd3ca0b224417f5f17'
Diffstat (limited to 'nixpkgs/pkgs/applications/science/math')
-rw-r--r--nixpkgs/pkgs/applications/science/math/calc/default.nix4
-rw-r--r--nixpkgs/pkgs/applications/science/math/gap/default.nix31
-rw-r--r--nixpkgs/pkgs/applications/science/math/gmsh/default.nix4
-rw-r--r--nixpkgs/pkgs/applications/science/math/pynac/default.nix34
-rw-r--r--nixpkgs/pkgs/applications/science/math/qalculate-gtk/default.nix4
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/default.nix12
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch92
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/dont-grep-threejs-version-from-minified-js.patch16
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/eclib-20210223-test-formatting.patch131
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch34
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/patches/sympy-1.7-update.patch25
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/sage-env.nix6
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/sage-src.nix154
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/sage_docbuild.nix20
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/sagedoc.nix12
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/sagelib.nix16
-rw-r--r--nixpkgs/pkgs/applications/science/math/sage/threejs-sage.nix18
-rw-r--r--nixpkgs/pkgs/applications/science/math/singular/default.nix149
-rw-r--r--nixpkgs/pkgs/applications/science/math/singular/disable-docs-for-optional-unpackaged-deps.patch112
-rw-r--r--nixpkgs/pkgs/applications/science/math/singular/disable-vspace-on-aarch64.patch15
-rw-r--r--nixpkgs/pkgs/applications/science/math/singular/redhat-aarch64.patch38
-rw-r--r--nixpkgs/pkgs/applications/science/math/singular/use-older-ax-prog-cc-for-build.patch194
22 files changed, 654 insertions, 467 deletions
diff --git a/nixpkgs/pkgs/applications/science/math/calc/default.nix b/nixpkgs/pkgs/applications/science/math/calc/default.nix
index c5a3fd606c00..f209e2de8c3e 100644
--- a/nixpkgs/pkgs/applications/science/math/calc/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/calc/default.nix
@@ -3,14 +3,14 @@
 
 stdenv.mkDerivation rec {
   pname = "calc";
-  version = "2.12.9.1";
+  version = "2.13.0.1";
 
   src = fetchurl {
     urls = [
       "https://github.com/lcn2/calc/releases/download/${version}/${pname}-${version}.tar.bz2"
       "http://www.isthe.com/chongo/src/calc/${pname}-${version}.tar.bz2"
     ];
-    sha256 = "sha256-B3ko+RNT+LYSJG1P5cujgRMc1OJhDPqm1ONrMh+7fI4=";
+    sha256 = "sha256-auU49XeFxXAacBEszwB6tVU6vTMq4t6q2vVk9AHHNK0=";
   };
 
   postPatch = ''
diff --git a/nixpkgs/pkgs/applications/science/math/gap/default.nix b/nixpkgs/pkgs/applications/science/math/gap/default.nix
index ce93c14b334f..3b3d8a58b569 100644
--- a/nixpkgs/pkgs/applications/science/math/gap/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/gap/default.nix
@@ -5,6 +5,7 @@
 , makeWrapper
 , readline
 , gmp
+, zlib
 # one of
 # - "minimal" (~400M):
 #     Install the bare minimum of packages required by gap to start.
@@ -61,11 +62,11 @@ in
 stdenv.mkDerivation rec {
   pname = "gap";
   # https://www.gap-system.org/Releases/
-  version = "4.10.2";
+  version = "4.11.0";
 
   src = fetchurl {
     url = "https://files.gap-system.org/gap-${lib.versions.major version}.${lib.versions.minor version}/tar.bz2/gap-${version}.tar.bz2";
-    sha256 = "0cp6ddk0469zzv1m1vair6gm27ic6c5m77ri8rn0znq3gaps6x94";
+    sha256 = "sha256-vwcKENwqxgWT/mXfD4c9ctTWdQHobrJipva9SPyGhgI=";
   };
 
   # remove all non-essential packages (which take up a lot of space)
@@ -76,6 +77,7 @@ stdenv.mkDerivation rec {
   buildInputs = [
     readline
     gmp
+    zlib
   ];
 
   nativeBuildInputs = [
@@ -83,34 +85,22 @@ stdenv.mkDerivation rec {
   ];
 
   patches = [
-    # https://github.com/gap-system/gap/pull/3294
-    (fetchpatch {
-      name = "add-make-install-targets.patch";
-      url = "https://github.com/gap-system/gap/commit/3361c172e6c5ff3bb3f01ba9d6f1dd4ad42cea80.patch";
-      sha256 = "1kwp9qnfvmlbpf1c3rs6j5m2jz22rj7a4hb5x1gj9vkpiyn5pdyj";
-    })
-
     # Fix for locale specific tests causing issues. Already upstream.
     # Backport of https://github.com/gap-system/gap/pull/4022
-    # WHEN REMOVING: also remove the`rm tst/testinstall/strings.tst` line in
-    # `postPatch` below. That line is necessary since the patch is not intended
-    # for gap 4.10.
     (fetchpatch {
       name = "remove-locale-specific-tests.patch";
       url = "https://github.com/gap-system/gap/commit/c18b0c4215b5212a2cc4f305e2d5b94ba716bee8.patch";
-      excludes = ["tst/testinstall/stringobj.tst"];
-      sha256 = "1mz5b4mbw2jdd1ypp5s0dy6pp0jsvwsxr2dm4kbkls20r1r192sc";
+      sha256 = "sha256-De+T9Y7ewRT6plJrj2VR8axRvD/JCTYKOBWB7Bw0oq0=";
     })
 
     # fixes aarch64 gc crashes: https://github.com/gap-system/gap/pull/3965
-    ./mark-genstackfuncbags-as-noinline.patch
+    (fetchpatch {
+      name = "mark-genstackfuncbags-as-noinline.patch";
+      url = "https://github.com/gap-system/gap/commit/f0a8f49ff8dad0a5fa77253d45457c6f40f96778.patch";
+      sha256 = "sha256-GU9tOP1stX2vn8m8kXOBupEpxIYArA76ibKL8eLn0MY=";
+    })
   ];
 
-  postPatch = ''
-    # File not covered by the remove-locale-specific-tests.patch patch above.
-    rm tst/testinstall/strings.tst
-  '';
-
   # "teststandard" is a superset of testinstall. It takes ~1h instead of ~1min.
   # tests are run twice, once with all packages loaded and once without
   # checkTarget = "teststandard";
@@ -155,7 +145,6 @@ stdenv.mkDerivation rec {
 
     mkdir -p "$out/bin" "$out/share/gap/"
 
-    mkdir -p "$out/share/gap"
     echo "Copying files to target directory"
     cp -ar . "$out/share/gap/build-dir"
 
diff --git a/nixpkgs/pkgs/applications/science/math/gmsh/default.nix b/nixpkgs/pkgs/applications/science/math/gmsh/default.nix
index fabb3b08c4da..c0d91a284458 100644
--- a/nixpkgs/pkgs/applications/science/math/gmsh/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/gmsh/default.nix
@@ -5,11 +5,11 @@ assert (!blas.isILP64) && (!lapack.isILP64);
 
 stdenv.mkDerivation rec {
   pname = "gmsh";
-  version = "4.8.0";
+  version = "4.8.1";
 
   src = fetchurl {
     url = "http://gmsh.info/src/gmsh-${version}-source.tgz";
-    sha256 = "sha256-JYd4PEsClj+divtxfJlUyu+kY+ouChLhZZMH5qDX6ms=";
+    sha256 = "sha256-1QOPXyWuhZc1NvsFzIhv6xvX1n4mBanYeJvMJSj6izU=";
   };
 
   buildInputs = [ blas lapack gmm fltk libjpeg zlib libGLU libGL
diff --git a/nixpkgs/pkgs/applications/science/math/pynac/default.nix b/nixpkgs/pkgs/applications/science/math/pynac/default.nix
index 00d35b491d62..9cdcd2b9ea30 100644
--- a/nixpkgs/pkgs/applications/science/math/pynac/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/pynac/default.nix
@@ -1,6 +1,6 @@
 { lib, stdenv
 , fetchFromGitHub
-, fetchurl
+, fetchpatch
 , autoreconfHook
 , pkg-config
 , flint
@@ -11,16 +11,36 @@
 }:
 
 stdenv.mkDerivation rec {
-  version = "0.7.26";
+  version = "0.7.27";
   pname = "pynac";
 
   src = fetchFromGitHub {
     owner = "pynac";
     repo = "pynac";
     rev = "pynac-${version}";
-    sha256 = "09d2p74x1arkydlxy6pw4p4byi7r8q7f29w373h4d8a215kadc6d";
+    sha256 = "sha256-1HHCIeaNE2UsJNX92UlDGLJS8I4nC/8FnwX7Y4F9HpU=";
   };
 
+  patches = [
+    (fetchpatch {
+      name = "handle_factor.patch";
+      url = "https://git.sagemath.org/sage.git/plain/build/pkgs/pynac/patches/handle_factor.patch?h=9.3.rc3";
+      sha256 = "sha256-U1lb5qwBqZZgklfDMhBX4K5u8bz5x42O4w7hyNy2YVw=";
+    })
+
+    (fetchpatch {
+      name = "power_inf_loop.patch";
+      url = "https://git.sagemath.org/sage.git/plain/build/pkgs/pynac/patches/power_inf_loop.patch?h=9.3.rc3";
+      sha256 = "sha256-VYeaJl8u2wl7FQ/6xnpZv1KpdNYEmJoPhuMrBADyTRs=";
+    })
+
+    (fetchpatch {
+      name = "too_much_sub.patch";
+      url = "https://git.sagemath.org/sage.git/plain/build/pkgs/pynac/patches/too_much_sub.patch?h=9.3.rc3";
+      sha256 = "sha256-lw7xSQ/l+rzPu+ghWF4omYF0mKksGGPuuHJTktvbdis=";
+    })
+  ];
+
   buildInputs = [
     flint
     gmp
@@ -34,14 +54,6 @@ stdenv.mkDerivation rec {
     pkg-config
   ];
 
-  patches = [
-    (fetchurl {
-      name = "py_ssize_t_clean.patch";
-      url = "https://git.sagemath.org/sage.git/plain/build/pkgs/pynac/patches/py_ssize_t_clean.patch?h=9.2";
-      sha256 = "0l3gbg9hc4v671zf4w376krnk3wh8hj3649610nlvzzxckcryzab";
-    })
-  ];
-
   meta = with lib; {
     description = "Python is Not a CAS -- modified version of Ginac";
     longDescription = ''
diff --git a/nixpkgs/pkgs/applications/science/math/qalculate-gtk/default.nix b/nixpkgs/pkgs/applications/science/math/qalculate-gtk/default.nix
index 7ee867930895..56b6df94e8fb 100644
--- a/nixpkgs/pkgs/applications/science/math/qalculate-gtk/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/qalculate-gtk/default.nix
@@ -2,13 +2,13 @@
 
 stdenv.mkDerivation rec {
   pname = "qalculate-gtk";
-  version = "3.17.0";
+  version = "3.18.0";
 
   src = fetchFromGitHub {
     owner = "qalculate";
     repo = "qalculate-gtk";
     rev = "v${version}";
-    sha256 = "sha256-Nxe1DZL8mh9aBWXQdlp5wC1l5b9mchlrRyE+LKC+yLI=";
+    sha256 = "sha256-hE0di7B6dCnMmMBLgFkb6vPS4hS/7zD6BbviIucrn1I=";
   };
 
   hardeningDisable = [ "format" ];
diff --git a/nixpkgs/pkgs/applications/science/math/sage/default.nix b/nixpkgs/pkgs/applications/science/math/sage/default.nix
index 8ef1f5189e5b..e39db4b1ac2d 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/sage/default.nix
@@ -19,6 +19,10 @@ let
         linbox = pkgs.linbox.override { withSage = true; };
         pkg-config = pkgs.pkg-config; # not to confuse with pythonPackages.pkg-config
       };
+
+      sage_docbuild = self.callPackage ./sage_docbuild.nix {
+        inherit sage-src;
+      };
     };
   };
 
@@ -38,14 +42,16 @@ let
     logo64 = "${sage-src}/doc/common/themes/sage/static/sageicon.png";
   };
 
+  three = callPackage ./threejs-sage.nix { };
+
   # A bash script setting various environment variables to tell sage where
   # the files its looking fore are located. Also see `sage-env`.
   env-locations = callPackage ./env-locations.nix {
     inherit pari_data;
     inherit singular maxima-ecl;
+    inherit three;
     ecl = maxima-ecl.ecl;
     cysignals = python3.pkgs.cysignals;
-    three = nodePackages.three;
     mathjax = nodePackages.mathjax;
   };
 
@@ -53,6 +59,7 @@ let
   # the env-locations file.
   sage-env = callPackage ./sage-env.nix {
     sagelib = python3.pkgs.sagelib;
+    sage_docbuild = python3.pkgs.sage_docbuild;
     inherit env-locations;
     inherit python3 singular palp flint pynac pythonEnv maxima-ecl;
     ecl = maxima-ecl.ecl;
@@ -70,8 +77,8 @@ let
     inherit python3 pythonEnv;
     inherit sage-env;
     inherit pynac singular maxima-ecl;
+    inherit three;
     pkg-config = pkgs.pkg-config; # not to confuse with pythonPackages.pkg-config
-    three = nodePackages.three;
   };
 
   # Doesn't actually build anything, just runs sages testsuite. This is a
@@ -86,6 +93,7 @@ let
 
   pythonRuntimeDeps = with python3.pkgs; [
     sagelib
+    sage_docbuild
     cvxopt
     networkx
     service-identity
diff --git a/nixpkgs/pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch
index 981759202386..0dbfba642e82 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch
+++ b/nixpkgs/pkgs/applications/science/math/sage/patches/do-not-test-find-library.patch
@@ -1,13 +1,13 @@
 diff --git a/src/sage/env.py b/src/sage/env.py
-index 1ddfc7cfb9..45033d6328 100644
+index 2908f5d04f..81dfd75c0d 100644
 --- a/src/sage/env.py
 +++ b/src/sage/env.py
-@@ -203,97 +203,13 @@ var('ARB_LIBRARY',                   'arb')
- var('SAGE_BANNER', '')
- var('SAGE_IMPORTALL', 'yes')
+@@ -218,93 +218,12 @@ NTL_LIBDIR = var("NTL_LIBDIR")
+ SAGE_BANNER = var("SAGE_BANNER", "")
+ SAGE_IMPORTALL = var("SAGE_IMPORTALL", "yes")
  
 -
--def _get_shared_lib_filename(libname, *additional_libnames):
+-def _get_shared_lib_path(*libnames: str) -> Optional[str]:
 -    """
 -    Return the full path to a shared library file installed in
 -    ``$SAGE_LOCAL/lib`` or the directories associated with the
@@ -25,80 +25,76 @@ index 1ddfc7cfb9..45033d6328 100644
 -    For distributions like Debian that use a multiarch layout, we also try the
 -    multiarch lib paths (i.e. ``/usr/lib/<arch>/``).
 -
--    This returns ``None`` if the file does not exist.
+-    This returns ``None`` if no matching library file could be found.
 -
 -    EXAMPLES::
 -
 -        sage: import sys
 -        sage: from fnmatch import fnmatch
--        sage: from sage.env import _get_shared_lib_filename
--        sage: lib_filename = _get_shared_lib_filename("Singular",
--        ....:                                         "singular-Singular")
+-        sage: from sage.env import _get_shared_lib_path
+-        sage: lib_filename = _get_shared_lib_path("Singular", "singular-Singular")
 -        sage: if sys.platform == 'cygwin':
 -        ....:     pattern = "*/cygSingular-*.dll"
 -        ....: elif sys.platform == 'darwin':
--        ....:     pattern = "*/libSingular.dylib"
+-        ....:     pattern = "*/libSingular-*.dylib"
 -        ....: else:
--        ....:     pattern = "*/lib*Singular.so"
--        sage: fnmatch(lib_filename, pattern)
+-        ....:     pattern = "*/lib*Singular-*.so"
+-        sage: fnmatch(str(lib_filename), pattern)
 -        True
--        sage: _get_shared_lib_filename("an_absurd_lib") is None
+-        sage: _get_shared_lib_path("an_absurd_lib") is None
 -        True
 -    """
 -
--    for libname in (libname,) + additional_libnames:
+-    for libname in libnames:
+-        search_directories: List[Path] = []
+-        patterns: List[str] = []
 -        if sys.platform == 'cygwin':
--            # Later down we take the last matching DLL found, so search
--            # SAGE_LOCAL second so that it takes precedence
--            bindirs = [
--                sysconfig.get_config_var('BINDIR'),
--                os.path.join(SAGE_LOCAL, 'bin')
+-            # Later down we take the first matching DLL found, so search
+-            # SAGE_LOCAL first so that it takes precedence
+-            search_directories = [
+-                Path(SAGE_LOCAL) / 'bin',
+-                Path(sysconfig.get_config_var('BINDIR')),
 -            ]
--            pats = ['cyg{}.dll'.format(libname), 'cyg{}-*.dll'.format(libname)]
--            filenames = []
--            for bindir in bindirs:
--                for pat in pats:
--                    filenames += glob.glob(os.path.join(bindir, pat))
--
--            # Note: This is not very robust, since if there are multi DLL
+-            # Note: The following is not very robust, since if there are multible
 -            # versions for the same library this just selects one more or less
--            # at arbitrary.  However, practically speaking, on Cygwin, there
+-            # at arbitrary. However, practically speaking, on Cygwin, there
 -            # will only ever be one version
--            if filenames:
--                return filenames[-1]
+-            patterns = [f'cyg{libname}.dll', f'cyg{libname}-*.dll']
 -        else:
 -            if sys.platform == 'darwin':
 -                ext = 'dylib'
 -            else:
 -                ext = 'so'
 -
--            libdirs = [
--                os.path.join(SAGE_LOCAL, 'lib'),
--                sysconfig.get_config_var('LIBDIR')
--            ]
--            multilib = sysconfig.get_config_var('MULTILIB')
--            if multilib:
--                libdirs.insert(1, os.path.join(libdirs[0], multilib))
+-            search_directories = [Path(SAGE_LOCAL) / 'lib']
+-            libdir = sysconfig.get_config_var('LIBDIR')
+-            if libdir is not None:
+-                libdir = Path(libdir)
+-                search_directories.append(libdir)
+-
+-                multiarchlib = sysconfig.get_config_var('MULTIARCH')
+-                if multiarchlib is not None: 
+-                    search_directories.append(libdir / multiarchlib),
 -
--            for libdir in libdirs:
--                basename = 'lib{}.{}'.format(libname, ext)
--                filename = os.path.join(libdir, basename)
--                if os.path.exists(filename):
--                    return filename
+-            patterns = [f'lib{libname}.{ext}']
+-
+-        for directory in search_directories:
+-            for pattern in patterns:
+-                path = next(directory.glob(pattern), None)
+-                if path is not None:
+-                    return str(path.resolve())
 -
 -    # Just return None if no files were found
 -    return None
 -
--
  # locate singular shared object
  # On Debian it's libsingular-Singular so try that as well
--SINGULAR_SO = _get_shared_lib_filename('Singular', 'singular-Singular')
-+SINGULAR_SO = '/default'
- var('SINGULAR_SO', SINGULAR_SO)
+-SINGULAR_SO = var("SINGULAR_SO", _get_shared_lib_path("Singular", "singular-Singular"))
++SINGULAR_SO = var("SINGULAR_SO", '/default')
  
  # locate libgap shared object
--GAP_SO= _get_shared_lib_filename('gap','')
-+GAP_SO = '/default'
- var('GAP_SO', GAP_SO)
+-GAP_SO = var("GAP_SO", _get_shared_lib_path("gap", ""))
++GAP_SO = var("GAP_SO", '/default')
  
  # post process
+ if ' ' in DOT_SAGE:
diff --git a/nixpkgs/pkgs/applications/science/math/sage/patches/dont-grep-threejs-version-from-minified-js.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/dont-grep-threejs-version-from-minified-js.patch
deleted file mode 100644
index 88cb66506b1d..000000000000
--- a/nixpkgs/pkgs/applications/science/math/sage/patches/dont-grep-threejs-version-from-minified-js.patch
+++ /dev/null
@@ -1,16 +0,0 @@
-diff --git a/src/sage/repl/rich_output/display_manager.py b/src/sage/repl/rich_output/display_manager.py
-index fb21f7a9c9..f39470777d 100644
---- a/src/sage/repl/rich_output/display_manager.py
-+++ b/src/sage/repl/rich_output/display_manager.py
-@@ -749,9 +749,9 @@ class DisplayManager(SageObject):
-             import sage.env
-             import re
-             import os
--            with open(os.path.join(sage.env.THREEJS_DIR, 'build', 'three.min.js')) as f:
-+            with open(os.path.join(sage.env.THREEJS_DIR, 'build', 'three.js')) as f:
-                 text = f.read().replace('\n','')
--            version = re.search(r'REVISION="(\d+)"', text).group(1)
-+            version = re.search(r"REVISION = '(\d+)'", text).group(1)
-             return """
- <script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js@r{0}/build/three.min.js"></script>
- <script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js@r{0}/examples/js/controls/OrbitControls.js"></script>
diff --git a/nixpkgs/pkgs/applications/science/math/sage/patches/eclib-20210223-test-formatting.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/eclib-20210223-test-formatting.patch
deleted file mode 100644
index 3fdb8f768e9d..000000000000
--- a/nixpkgs/pkgs/applications/science/math/sage/patches/eclib-20210223-test-formatting.patch
+++ /dev/null
@@ -1,131 +0,0 @@
-diff --git a/src/sage/libs/eclib/interface.py b/src/sage/libs/eclib/interface.py
-index e898456720..6b98c12328 100644
---- a/src/sage/libs/eclib/interface.py
-+++ b/src/sage/libs/eclib/interface.py
-@@ -758,78 +758,78 @@ class mwrank_MordellWeil(SageObject):
- 
-         sage: EQ = mwrank_MordellWeil(E, verbose=True)
-         sage: EQ.search(1)
--        P1 = [0:1:0]     is torsion point, order 1
--        P1 = [-3:0:1]     is generator number 1
--        saturating up to 20...Checking 2-saturation
-+        P1 = [0:1:0]         is torsion point, order 1
-+        P1 = [-3:0:1]         is generator number 1
-+        saturating up to 20...Checking 2-saturation...
-         Points have successfully been 2-saturated (max q used = 7)
--        Checking 3-saturation
-+        Checking 3-saturation...
-         Points have successfully been 3-saturated (max q used = 7)
--        Checking 5-saturation
-+        Checking 5-saturation...
-         Points have successfully been 5-saturated (max q used = 23)
--        Checking 7-saturation
-+        Checking 7-saturation...
-         Points have successfully been 7-saturated (max q used = 41)
--        Checking 11-saturation
-+        Checking 11-saturation...
-         Points have successfully been 11-saturated (max q used = 17)
--        Checking 13-saturation
-+        Checking 13-saturation...
-         Points have successfully been 13-saturated (max q used = 43)
--        Checking 17-saturation
-+        Checking 17-saturation...
-         Points have successfully been 17-saturated (max q used = 31)
--        Checking 19-saturation
-+        Checking 19-saturation...
-         Points have successfully been 19-saturated (max q used = 37)
-         done
--        P2 = [-2:3:1]     is generator number 2
--        saturating up to 20...Checking 2-saturation
-+        P2 = [-2:3:1]         is generator number 2
-+        saturating up to 20...Checking 2-saturation...
-         possible kernel vector = [1,1]
-         This point may be in 2E(Q): [14:-52:1]
-         ...and it is!
-         Replacing old generator #1 with new generator [1:-1:1]
-         Points have successfully been 2-saturated (max q used = 7)
-         Index gain = 2^1
--        Checking 3-saturation
-+        Checking 3-saturation...
-         Points have successfully been 3-saturated (max q used = 13)
--        Checking 5-saturation
-+        Checking 5-saturation...
-         Points have successfully been 5-saturated (max q used = 67)
--        Checking 7-saturation
-+        Checking 7-saturation...
-         Points have successfully been 7-saturated (max q used = 53)
--        Checking 11-saturation
-+        Checking 11-saturation...
-         Points have successfully been 11-saturated (max q used = 73)
--        Checking 13-saturation
-+        Checking 13-saturation...
-         Points have successfully been 13-saturated (max q used = 103)
--        Checking 17-saturation
-+        Checking 17-saturation...
-         Points have successfully been 17-saturated (max q used = 113)
--        Checking 19-saturation
-+        Checking 19-saturation...
-         Points have successfully been 19-saturated (max q used = 47)
-         done (index = 2).
-         Gained index 2, new generators = [ [1:-1:1] [-2:3:1] ]
--        P3 = [-14:25:8]   is generator number 3
--        saturating up to 20...Checking 2-saturation
-+        P3 = [-14:25:8]       is generator number 3
-+        saturating up to 20...Checking 2-saturation...
-         Points have successfully been 2-saturated (max q used = 11)
--        Checking 3-saturation
-+        Checking 3-saturation...
-         Points have successfully been 3-saturated (max q used = 13)
--        Checking 5-saturation
-+        Checking 5-saturation...
-         Points have successfully been 5-saturated (max q used = 71)
--        Checking 7-saturation
-+        Checking 7-saturation...
-         Points have successfully been 7-saturated (max q used = 101)
--        Checking 11-saturation
-+        Checking 11-saturation...
-         Points have successfully been 11-saturated (max q used = 127)
--        Checking 13-saturation
-+        Checking 13-saturation...
-         Points have successfully been 13-saturated (max q used = 151)
--        Checking 17-saturation
-+        Checking 17-saturation...
-         Points have successfully been 17-saturated (max q used = 139)
--        Checking 19-saturation
-+        Checking 19-saturation...
-         Points have successfully been 19-saturated (max q used = 179)
-         done (index = 1).
--        P4 = [-1:3:1]    = -1*P1 + -1*P2 + -1*P3 (mod torsion)
--        P4 = [0:2:1]     = 2*P1 + 0*P2 + 1*P3 (mod torsion)
--        P4 = [2:13:8]    = -3*P1 + 1*P2 + -1*P3 (mod torsion)
--        P4 = [1:0:1]     = -1*P1 + 0*P2 + 0*P3 (mod torsion)
--        P4 = [2:0:1]     = -1*P1 + 1*P2 + 0*P3 (mod torsion)
--        P4 = [18:7:8]    = -2*P1 + -1*P2 + -1*P3 (mod torsion)
--        P4 = [3:3:1]     = 1*P1 + 0*P2 + 1*P3 (mod torsion)
--        P4 = [4:6:1]     = 0*P1 + -1*P2 + -1*P3 (mod torsion)
--        P4 = [36:69:64]  = 1*P1 + -2*P2 + 0*P3 (mod torsion)
--        P4 = [68:-25:64]         = -2*P1 + -1*P2 + -2*P3 (mod torsion)
--        P4 = [12:35:27]  = 1*P1 + -1*P2 + -1*P3 (mod torsion)
-+        P4 = [-1:3:1]        = -1*P1 + -1*P2 + -1*P3 (mod torsion)
-+        P4 = [0:2:1]         = 2*P1 + 0*P2 + 1*P3 (mod torsion)
-+        P4 = [2:13:8]        = -3*P1 + 1*P2 + -1*P3 (mod torsion)
-+        P4 = [1:0:1]         = -1*P1 + 0*P2 + 0*P3 (mod torsion)
-+        P4 = [2:0:1]         = -1*P1 + 1*P2 + 0*P3 (mod torsion)
-+        P4 = [18:7:8]        = -2*P1 + -1*P2 + -1*P3 (mod torsion)
-+        P4 = [3:3:1]         = 1*P1 + 0*P2 + 1*P3 (mod torsion)
-+        P4 = [4:6:1]         = 0*P1 + -1*P2 + -1*P3 (mod torsion)
-+        P4 = [36:69:64]      = 1*P1 + -2*P2 + 0*P3 (mod torsion)
-+        P4 = [68:-25:64]     = -2*P1 + -1*P2 + -2*P3 (mod torsion)
-+        P4 = [12:35:27]      = 1*P1 + -1*P2 + -1*P3 (mod torsion)
-         sage: EQ
-         Subgroup of Mordell-Weil group: [[1:-1:1], [-2:3:1], [-14:25:8]]
- 
-@@ -1076,7 +1076,7 @@ class mwrank_MordellWeil(SageObject):
-             sage: EQ.search(1)
-             P1 = [0:1:0]         is torsion point, order 1
-             P1 = [-3:0:1]         is generator number 1
--            saturating up to 20...Checking 2-saturation
-+            saturating up to 20...Checking 2-saturation...
-             ...
-             P4 = [12:35:27]      = 1*P1 + -1*P2 + -1*P3 (mod torsion)
-             sage: EQ
diff --git a/nixpkgs/pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch
index 661077cfa8cd..3c64be100d25 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch
+++ b/nixpkgs/pkgs/applications/science/math/sage/patches/sphinx-docbuild-subprocesses.patch
@@ -1,8 +1,8 @@
-diff --git a/src/sage_setup/docbuild/__init__.py b/src/sage_setup/docbuild/__init__.py
-index 73a078e619..059125c59f 100644
---- a/src/sage_setup/docbuild/__init__.py
-+++ b/src/sage_setup/docbuild/__init__.py
-@@ -86,27 +86,6 @@ def builder_helper(type):
+diff --git a/src/sage_docbuild/__init__.py b/src/sage_docbuild/__init__.py
+index 79005b903a..fbe6fe2595 100644
+--- a/src/sage_docbuild/__init__.py
++++ b/src/sage_docbuild/__init__.py
+@@ -85,27 +85,6 @@ def builder_helper(type):
      """
      Returns a function which builds the documentation for
      output type ``type``.
@@ -11,16 +11,16 @@ index 73a078e619..059125c59f 100644
 -
 -    Check that :trac:`25161` has been resolved::
 -
--        sage: from sage_setup.docbuild import DocBuilder, setup_parser
+-        sage: from sage_docbuild import DocBuilder, setup_parser
 -        sage: DocBuilder._options = setup_parser().parse_args([])[0] # builder_helper needs _options to be set
 -
--        sage: import sage_setup.docbuild.sphinxbuild
+-        sage: import sage_docbuild.sphinxbuild
 -        sage: def raiseBaseException():
 -        ....:     raise BaseException("abort pool operation")
--        sage: original_runsphinx, sage_setup.docbuild.sphinxbuild.runsphinx = sage_setup.docbuild.sphinxbuild.runsphinx, raiseBaseException
+-        sage: original_runsphinx, sage_docbuild.sphinxbuild.runsphinx = sage_docbuild.sphinxbuild.runsphinx, raiseBaseException
 -
--        sage: from sage_setup.docbuild import builder_helper, build_ref_doc
--        sage: from sage_setup.docbuild import _build_many as build_many
+-        sage: from sage_docbuild import builder_helper, build_ref_doc
+-        sage: from sage_docbuild import _build_many as build_many
 -        sage: helper = builder_helper("html")
 -        sage: try:
 -        ....:     build_many(build_ref_doc, [("docname", "en", "html", {})])
@@ -30,24 +30,24 @@ index 73a078e619..059125c59f 100644
      """
      def f(self, *args, **kwds):
          output_dir = self._output_dir(type)
-@@ -128,10 +107,9 @@ def builder_helper(type):
+@@ -127,10 +106,9 @@ def builder_helper(type):
          logger.debug(build_command)
  
          # Run Sphinx with Sage's special logger
 -        sys.argv = ["sphinx-build"] + build_command.split()
 -        from .sphinxbuild import runsphinx
-+        args = "python3 -um sage_setup.docbuild.sphinxbuild -N".split() + build_command.split()
++        args = "python3 -um sage_docbuild.sphinxbuild -N".split() + build_command.split()
          try:
 -            runsphinx()
 +            subprocess.check_call(args)
          except Exception:
              if ABORT_ON_ERROR:
                  raise
-diff --git a/src/sage_setup/docbuild/sphinxbuild.py b/src/sage_setup/docbuild/sphinxbuild.py
-index fe7eba43b2..463790965c 100644
---- a/src/sage_setup/docbuild/sphinxbuild.py
-+++ b/src/sage_setup/docbuild/sphinxbuild.py
-@@ -321,3 +321,8 @@ def runsphinx():
+diff --git a/src/sage_docbuild/sphinxbuild.py b/src/sage_docbuild/sphinxbuild.py
+index f58f6c61d7..ef51a55411 100644
+--- a/src/sage_docbuild/sphinxbuild.py
++++ b/src/sage_docbuild/sphinxbuild.py
+@@ -326,3 +326,8 @@ def runsphinx():
          sys.stderr = saved_stderr
          sys.stdout.flush()
          sys.stderr.flush()
diff --git a/nixpkgs/pkgs/applications/science/math/sage/patches/sympy-1.7-update.patch b/nixpkgs/pkgs/applications/science/math/sage/patches/sympy-1.7-update.patch
deleted file mode 100644
index 1d21622a2354..000000000000
--- a/nixpkgs/pkgs/applications/science/math/sage/patches/sympy-1.7-update.patch
+++ /dev/null
@@ -1,25 +0,0 @@
-diff --git a/src/sage/interfaces/sympy.py b/src/sage/interfaces/sympy.py
-index cc35a42a9f..6e577d5d8d 100644
---- a/src/sage/interfaces/sympy.py
-+++ b/src/sage/interfaces/sympy.py
-@@ -397,7 +397,7 @@ def _sympysage_rf(self):
-         sage: from sympy import Symbol, rf
-         sage: _ = var('x, y')
-         sage: rfxy = rf(Symbol('x'), Symbol('y'))
--        sage: assert rising_factorial(x,y)._sympy_() == rfxy.rewrite('gamma')
-+        sage: assert rising_factorial(x,y)._sympy_() == rfxy.rewrite('gamma', piecewise=False)
-         sage: assert rising_factorial(x,y) == rfxy._sage_()
-     """
-     from sage.arith.all import rising_factorial
-diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx
-index 7c18ec1efa..c2619ac42d 100644
---- a/src/sage/symbolic/expression.pyx
-+++ b/src/sage/symbolic/expression.pyx
-@@ -955,6 +955,6 @@ cdef class Expression(CommutativeRingElement):
-             sage: unicode_art(13 - I)
-             13 - ⅈ
-             sage: unicode_art(1.3 - I)
--            1.3 - 1.0⋅ⅈ
-+            1.3 - ⅈ
-             sage: unicode_art(cos(I))
-             cosh(1)
diff --git a/nixpkgs/pkgs/applications/science/math/sage/sage-env.nix b/nixpkgs/pkgs/applications/science/math/sage/sage-env.nix
index 568a4a39f393..fd67076c97de 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/sage-env.nix
+++ b/nixpkgs/pkgs/applications/science/math/sage/sage-env.nix
@@ -2,6 +2,7 @@
 , lib
 , writeTextFile
 , sagelib
+, sage_docbuild
 , env-locations
 , gfortran
 , bash
@@ -191,6 +192,7 @@ writeTextFile rec {
   # for find_library
     export DYLD_LIBRARY_PATH="${lib.makeLibraryPath [stdenv.cc.libc singular]}''${DYLD_LIBRARY_PATH:+:}$DYLD_LIBRARY_PATH"
   '';
-} // {
-  lib = sagelib; # equivalent of `passthru`, which `writeTextFile` doesn't support
+} // { # equivalent of `passthru`, which `writeTextFile` doesn't support
+  lib = sagelib;
+  docbuild = sage_docbuild;
 }
diff --git a/nixpkgs/pkgs/applications/science/math/sage/sage-src.nix b/nixpkgs/pkgs/applications/science/math/sage/sage-src.nix
index 1fb605b35998..91e855777f0e 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/sage-src.nix
+++ b/nixpkgs/pkgs/applications/science/math/sage/sage-src.nix
@@ -24,14 +24,14 @@ let
   );
 in
 stdenv.mkDerivation rec {
-  version = "9.2";
+  version = "9.3.rc4";
   pname = "sage-src";
 
   src = fetchFromGitHub {
     owner = "sagemath";
     repo = "sage";
     rev = version;
-    sha256 = "103j8d5x6szl9fxaz0dvdi4y47q1af9h9y5hmjh2xayi62qmp5ql";
+    sha256 = "sha256-LDY07By2j6JagkgT9zeDJ93+m2/oXXEnDRTDzmR8ftk=";
   };
 
   # Patches needed because of particularities of nix or the way this is packaged.
@@ -53,14 +53,6 @@ stdenv.mkDerivation rec {
     # Parallelize docubuild using subprocesses, fixing an isolation issue. See
     # https://groups.google.com/forum/#!topic/sage-packaging/YGOm8tkADrE
     ./patches/sphinx-docbuild-subprocesses.patch
-
-    # Register sorted dict pprinter earlier (https://trac.sagemath.org/ticket/31053)
-    (fetchSageDiff {
-      base = "9.3.beta4";
-      name = "register-pretty-printer-earlier.patch";
-      rev = "d658230ce06ca19f4a3b3a4576297ee82f2d2151";
-      sha256 = "sha256-9mPUV7K5PoLDH2vVaYaOfvDLDpmxU0Aj7m/eaXYotDs=";
-    })
   ];
 
   # Since sage unfortunately does not release bugfix releases, packagers must
@@ -70,31 +62,6 @@ stdenv.mkDerivation rec {
     # To help debug the transient error in
     # https://trac.sagemath.org/ticket/23087 when it next occurs.
     ./patches/configurationpy-error-verbose.patch
-
-    # fix intermittent errors in Sage 9.2's psage.py (this patch is
-    # already included in Sage 9.3): https://trac.sagemath.org/ticket/30730
-    (fetchSageDiff {
-      base = "9.2.rc2";
-      name = "fix-psage-is-locked.patch";
-      rev = "75df605f216ddc7b6ca719be942d666b241520e9";
-      sha256 = "0g9pl1wbb3sgs26d3bvv70cpa77sfskylv4kd255y1794f1fgk4q";
-    })
-
-    # fix intermittent errors in sagespawn.pyx: https://trac.sagemath.org/ticket/31052
-    (fetchSageDiff {
-      base = "9.2";
-      name = "sagespawn-implicit-casting.patch";
-      rev = "2959ac792ebd6107fe87c9af1541083de5ba02d6";
-      sha256 = "sha256-bWIpEGir9Kawak5CJegBMNcHm/CqhWmdru+emeSsvO0=";
-    })
-
-    # fix intermittent errors in doctest/test.py: https://trac.sagemath.org/ticket/26912
-    (fetchSageDiff {
-      base = "9.3.beta8";
-      name = "set-cysignals-crash-ndebug.patch";
-      rev = "ca5257a5d0f32efc9f8f07e126020856270b1a18";
-      sha256 = "sha256-KViw63xE3O0eUiOYzoxNrr4NL+csql9GPJLDJCf/EZs=";
-    })
   ];
 
   # Patches needed because of package updates. We could just pin the versions of
@@ -111,120 +78,29 @@ stdenv.mkDerivation rec {
 
     # ignore a deprecation warning for usage of `cmp` in the attrs library in the doctests
     ./patches/ignore-cmp-deprecation.patch
-
-    # adapt sage's Image class to pillow 8.0.1 (https://trac.sagemath.org/ticket/30971)
-    (fetchSageDiff {
-      base = "9.3.beta2";
-      name = "pillow-8.0.1-update.patch";
-      rev = "f05f2d0aac9c4b5abe68105cee2cc7f2c8461847";
-      sha256 = "sha256-uY2UlgSd5hhOUUukB4Xc3Gjy0/e7p/qyq9jdvz10IOs=";
-    })
-
-    # don't use deprecated numpy type aliases (https://trac.sagemath.org/ticket/31364)
-    (fetchSageDiff {
-      base = "9.3.beta7";
-      name = "dont-use-deprecated-numpy-type-aliases.patch";
-      rev = "dfdef60515d4a4269e82d91280f76a7fdf10bf97";
-      sha256 = "sha256-77/3LkT5J7DQN8IPlGJKB6ZcJPaF7xwje06JNns+0AE=";
-    })
-
-    # fix test output with sympy 1.7 (https://trac.sagemath.org/ticket/30985)
-    ./patches/sympy-1.7-update.patch
-
-    # workaround until we use sage's fork of threejs, which contains a "version" file
-    ./patches/dont-grep-threejs-version-from-minified-js.patch
-
-    # updated eclib output has punctuation changes and tidier whitespace
-    ./patches/eclib-20210223-test-formatting.patch
-
-    # upgrade arb to 2.18.1 (https://trac.sagemath.org/ticket/28623)
-    (fetchSageDiff {
-      base = "9.3.beta3";
-      name = "arb-2.18.1-update.patch";
-      rev = "0c9c4ed35c2eaf34ae0d19387c07b7f460e4abce";
-      sha256 = "sha256-CjOJIsyyVCziAfvE6pWSihPO35IZMcY2/taXAsqhPLY=";
-    })
-
-    # giac 1.6.0-47 update (https://trac.sagemath.org/ticket/30537)
-    (fetchSageDiff {
-      base = "9.3.beta7";
-      name = "giac-1.6.0-47-update.patch";
-      rev = "f05720bf63dfaf33a4e3b6d3ed2c2c0ec46b5d31";
-      sha256 = "sha256-gDUq+84eXd5GxLBWUSI61GMJpBF2KX4LBVOt3mS1NF8=";
-    })
-
-    # Make gcd/lcm interact better with pari and gmpy2 (https://trac.sagemath.org/ticket/30849)
-    # needed for pari 2.13.1 update, which we will do in the future
-    (fetchSageDiff {
-      base = "9.3.beta0";
-      name = "make-gcd-lcm-interact-better-with-pari-and-gmpy2.patch";
-      rev = "75c1516f0abb9e6f8c335e38e4031f6ef674ed30";
-      sha256 = "sha256-RukkieIZcXNrju904H2oyGKdtpdE+9vNzvyjN2IBNg0=";
-    })
-
-    # cypari 2.1.2 update (https://trac.sagemath.org/ticket/31029)
-    (fetchSageDiff {
-      base = "9.3.beta3";
-      name = "cypari-2.1.2-update.patch";
-      rev = "b9aadfd08e81d74ca7c229bb80eb853b592887d0";
-      sha256 = "sha256-eKaMy7kpu+YKdL8bPStgocxBCTfc2Z/10RrGy2LENFw=";
-    })
   ];
 
   patches = nixPatches ++ bugfixPatches ++ packageUpgradePatches;
 
   postPatch = ''
-    # make sure shebangs etc are fixed, but sage-python23 still works
-    find . -type f -exec sed \
-      -e 's/sage-python23/python3/g' \
-      -i {} \;
-
-    echo '#!${runtimeShell}
-    python3 "$@"' > build/bin/sage-python23
-
     # Make sure sage can at least be imported without setting any environment
     # variables. It won't be close to feature complete though.
     sed -i \
-      "s|var('SAGE_ROOT'.*|var('SAGE_ROOT', '$out')|" \
+      "s|var(\"SAGE_ROOT\".*|var(\"SAGE_ROOT\", \"$out\")|" \
       src/sage/env.py
 
-    # Do not use sage-env-config (generated by ./configure).
-    # Instead variables are set manually.
-    echo '# do nothing' >  src/bin/sage-env-config
-  '';
-
-  # Test src/doc/en/reference/spkg/conf.py will fail if
-  # src/doc/en/reference/spkg/index.rst is not generated.  It is
-  # generated by src/doc/bootstrap, so I've copied the relevant part
-  # here. An alternative would be to create an empty
-  # src/doc/en/reference/spkg/index.rst file.
-  configurePhase = ''
-    OUTPUT_DIR="src/doc/en/reference/spkg"
-    mkdir -p "$OUTPUT_DIR"
-    OUTPUT_INDEX="$OUTPUT_DIR"/index.rst
-    cat > "$OUTPUT_INDEX" <<EOF
-
-    External Packages
-    =================
-
-    .. toctree::
-       :maxdepth: 1
-
-    EOF
-    for PKG_SCRIPTS in build/pkgs/*; do
-        if [ -d "$PKG_SCRIPTS" ]; then
-            PKG_BASE=$(basename "$PKG_SCRIPTS")
-            if [ -f "$PKG_SCRIPTS"/SPKG.rst ]; then
-                # Instead of just copying, we may want to call
-                # a version of sage-spkg-info to format extra information.
-                cp "$PKG_SCRIPTS"/SPKG.rst "$OUTPUT_DIR"/$PKG_BASE.rst
-                echo >> "$OUTPUT_INDEX" "   $PKG_BASE"
-            fi
-        fi
-    done
-    cat >> "$OUTPUT_INDEX" <<EOF
-    .. include:: ../footer.txt
-    EOF
+    # src/doc/en/reference/spkg/conf.py expects index.rst in its directory,
+    # a list of external packages in the sage distribution (build/pkgs)
+    # generated by the bootstrap script (which we don't run).  this is not
+    # relevant for other distributions, so remove it.
+    rm src/doc/en/reference/spkg/conf.py
+    sed -i "/spkg/d" src/doc/en/reference/index.rst
+
+    # the bootstrap script also generates installation instructions for
+    # arch, debian, fedora, cygwin and homebrew using data from build/pkgs.
+    # we don't run the bootstrap script, so disable including the generated
+    # files. docbuilding fails otherwise.
+    sed -i "/literalinclude/d" src/doc/en/installation/source.rst
   '';
 
   buildPhase = "# do nothing";
diff --git a/nixpkgs/pkgs/applications/science/math/sage/sage_docbuild.nix b/nixpkgs/pkgs/applications/science/math/sage/sage_docbuild.nix
new file mode 100644
index 000000000000..ed78d46b4451
--- /dev/null
+++ b/nixpkgs/pkgs/applications/science/math/sage/sage_docbuild.nix
@@ -0,0 +1,20 @@
+{ buildPythonPackage
+, sage-src
+, sphinx
+}:
+
+buildPythonPackage rec {
+  version = src.version;
+  pname = "sage_docbuild";
+  src = sage-src;
+
+  propagatedBuildInputs = [
+    sphinx
+  ];
+
+  preBuild = ''
+    cd build/pkgs/sage_docbuild/src
+  '';
+
+  doCheck = false; # we will run tests in sagedoc.nix
+}
diff --git a/nixpkgs/pkgs/applications/science/math/sage/sagedoc.nix b/nixpkgs/pkgs/applications/science/math/sage/sagedoc.nix
index a10672f3a092..603c1a585c79 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/sagedoc.nix
+++ b/nixpkgs/pkgs/applications/science/math/sage/sagedoc.nix
@@ -23,6 +23,7 @@ stdenv.mkDerivation rec {
     jmol
     cddlib
   ] ++ (with python3.pkgs; [
+    sage_docbuild
     psutil
     future
     sphinx
@@ -44,13 +45,6 @@ stdenv.mkDerivation rec {
     chmod -R 755 "$SAGE_DOC_SRC_OVERRIDE"
   '';
 
-  postPatch = ''
-    # src/doc/bootstrap generates installation instructions for
-    # arch, debian, fedora, cygwin and homebrew. as a hack, disable
-    # including the generated files.
-    sed -i "/literalinclude/d" $SAGE_DOC_SRC_OVERRIDE/en/installation/source.rst
-  '';
-
   buildPhase = ''
     export SAGE_NUM_THREADS="$NIX_BUILD_CORES"
     export HOME="$TMPDIR/sage_home"
@@ -59,13 +53,13 @@ stdenv.mkDerivation rec {
     # needed to link them in the sage docs using intersphinx
     export PPLPY_DOCS=${python3.pkgs.pplpy.doc}/share/doc/pplpy
 
-    # adapted from src/doc/bootstrap
+    # adapted from src/doc/bootstrap (which we don't run)
     OUTPUT_DIR="$SAGE_DOC_SRC_OVERRIDE/en/reference/repl"
     mkdir -p "$OUTPUT_DIR"
     OUTPUT="$OUTPUT_DIR/options.txt"
     ${sage-with-env}/bin/sage -advanced > "$OUTPUT"
 
-    ${sage-with-env}/bin/sage -python -m sage_setup.docbuild \
+    ${sage-with-env}/bin/sage --docbuild \
       --mathjax \
       --no-pdf-links \
       all html
diff --git a/nixpkgs/pkgs/applications/science/math/sage/sagelib.nix b/nixpkgs/pkgs/applications/science/math/sage/sagelib.nix
index 245ddcedeee0..f60cb64d2e8d 100644
--- a/nixpkgs/pkgs/applications/science/math/sage/sagelib.nix
+++ b/nixpkgs/pkgs/applications/science/math/sage/sagelib.nix
@@ -63,7 +63,6 @@ assert (!blas.isILP64) && (!lapack.isILP64);
 # `sage-tests` and will not have html docs without `sagedoc`.
 
 buildPythonPackage rec {
-  format = "other";
   version = src.version;
   pname = "sagelib";
   src = sage-src;
@@ -74,6 +73,7 @@ buildPythonPackage rec {
     jupyter_core
     pkg-config
     pip # needed to query installed packages
+    ecl
   ];
 
   buildInputs = [
@@ -130,7 +130,7 @@ buildPythonPackage rec {
     sqlite
   ];
 
-  buildPhase = ''
+  preBuild = ''
     export SAGE_ROOT="$PWD"
     export SAGE_LOCAL="$SAGE_ROOT"
     export SAGE_SHARE="$SAGE_LOCAL/share"
@@ -146,15 +146,13 @@ buildPythonPackage rec {
     mkdir -p "$SAGE_SHARE/sage/ext/notebook-ipython"
     mkdir -p "var/lib/sage/installed"
 
-    source build/bin/sage-dist-helpers
-    cd src
-
-    ${python.interpreter} -u setup.py --no-user-cfg build
+    # src/setup.py should not be used, see https://trac.sagemath.org/ticket/31377#comment:124
+    cd build/pkgs/sagelib/src
   '';
 
-  installPhase = ''
-    ${python.interpreter} -u setup.py --no-user-cfg install --prefix=$out
-
+  postInstall = ''
     rm -r "$out/${python.sitePackages}/sage/cython_debug"
   '';
+
+  doCheck = false; # we will run tests in sage-tests.nix
 }
diff --git a/nixpkgs/pkgs/applications/science/math/sage/threejs-sage.nix b/nixpkgs/pkgs/applications/science/math/sage/threejs-sage.nix
new file mode 100644
index 000000000000..0e4ad4dee955
--- /dev/null
+++ b/nixpkgs/pkgs/applications/science/math/sage/threejs-sage.nix
@@ -0,0 +1,18 @@
+{ stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  pname = "threejs-sage";
+  version = "r122";
+
+  src = fetchFromGitHub {
+    owner = "sagemath";
+    repo = "threejs-sage";
+    rev = version;
+    sha256 = "sha256-xPAPt36Fon3hYQq6SOmGkIyUzAII2LMl10nqYG4UPI0=";
+  };
+
+  installPhase = ''
+    mkdir -p $out/lib/node_modules/three
+    cp -r build version $out/lib/node_modules/three
+  '';
+}
diff --git a/nixpkgs/pkgs/applications/science/math/singular/default.nix b/nixpkgs/pkgs/applications/science/math/singular/default.nix
index fad05099a733..695af3d17440 100644
--- a/nixpkgs/pkgs/applications/science/math/singular/default.nix
+++ b/nixpkgs/pkgs/applications/science/math/singular/default.nix
@@ -1,57 +1,96 @@
-{ stdenv, fetchurl, gmp, bison, perl, ncurses, readline, coreutils, pkg-config
+{ stdenv, fetchFromGitHub, gmp, bison, perl, ncurses, readline, coreutils, pkg-config
 , lib
 , fetchpatch
 , autoreconfHook
+, sharutils
 , file
 , flint
 , ntl
 , cddlib
-, enableFactory ? true
+, gfan
+, lrcalc
+, doxygen
+, graphviz
+# upstream generates docs with texinfo 4. later versions of texinfo
+# use letters instead of numbers for post-appendix chapters, and we
+# want it to match the upstream format because sage depends on it.
+, texinfo4
+, texlive
+, enableDocs ? true
 , enableGfanlib ? true
 }:
 
 stdenv.mkDerivation rec {
   pname = "singular";
-  version = "4.1.1p2";
-
-  src = let
-    # singular sorts its tarballs in directories by base release (without patch version)
-    # for example 4.1.1p1 will be in the directory 4-1-1
-    baseVersion = builtins.head (lib.splitString "p" version);
-    urlVersion = builtins.replaceStrings [ "." ] [ "-" ] baseVersion;
-  in
-  fetchurl {
-    url = "http://www.mathematik.uni-kl.de/ftp/pub/Math/Singular/SOURCES/${urlVersion}/singular-${version}.tar.gz";
-    sha256 = "07x9kri8vl4galik7lr6pscq3c51n8570pyw64i7gbj0m706f7wf";
+  version = "4.2.0p2";
+
+  # since the tarball does not contain tests or documentation (and
+  # there is no separate tests tarball for 4.2.0), we fetch from
+  # GitHub.
+  src = fetchFromGitHub {
+    owner = "Singular";
+    repo = "Singular";
+
+    # 4.2.0p2 is not tagged, but the tarball matches commit
+    # 6f68939ddf612d96e3caaaaa8275f77613ac1da8. the commit below has
+    # two extra fixes.
+    rev = "3cda50c00a849455efa2502e56596955491a353a";
+    sha256 = "sha256-OizPhGE6L2LTOrKfeDdDB6BSdvYkDVXvbbYjV14hnHM=";
+
+    # if a release is tagged it will be in the format below.
+    # rev = "Release${lib.replaceStrings ["."] ["-"] version}";
+
+    # the repository's .gitattributes file contains the lines "/Tst/
+    # export-ignore" and "/doc/ export-ignore" so some directories are
+    # not included in the tarball downloaded by fetchzip. setting
+    # fetchSubmodules works around this by using fetchgit instead of
+    # fetchzip.
+    fetchSubmodules = true;
   };
 
+  patches = [
+    # add aarch64 support to cpu-check.m4. copied from redhat.
+    ./redhat-aarch64.patch
+
+    # vspace causes hangs in modstd and other libraries on aarch64
+    ./disable-vspace-on-aarch64.patch
+
+    # the newest version of ax-prog-cc-for-build.m4 seems to trigger
+    # linker errors. see
+    # https://github.com/alsa-project/alsa-firmware/issues/3 for a
+    # related issue.
+    ./use-older-ax-prog-cc-for-build.patch
+  ] ++ lib.optionals enableDocs [
+    # singular supports building without 4ti2, bertini, normaliz or
+    # topcom just fine, but the docbuilding does not skip manual pages
+    # tagged as depending on those binaries (probably a bug in
+    # doc2tex.pl::HandleLib, since it seems to ignore "-exclude"
+    # argumens). skip them manually.
+    ./disable-docs-for-optional-unpackaged-deps.patch
+  ];
+
   configureFlags = [
     "--with-ntl=${ntl}"
-  ] ++ lib.optionals enableFactory [
-    "--enable-factory"
+    "--disable-pyobject-module"
+  ] ++ lib.optionals enableDocs [
+    "--enable-doc-build"
   ] ++ lib.optionals enableGfanlib [
     "--enable-gfanlib"
   ];
 
-  postUnpack = ''
+  prePatch = ''
+    # don't let the tests depend on `hostname`
+    substituteInPlace Tst/regress.cmd --replace 'mysystem_catch("hostname")' 'nix_test_runner'
+
     patchShebangs .
+  '' + lib.optionalString enableDocs ''
+    # work around encoding problem
+    sed -i -e 's/\xb7/@cdot{}/g' doc/decodegb.doc
   '';
 
-  patches = [
-    # NTL error handler was introduced in the library part, preventing users of
-    # the library from implementing their own error handling
-    # https://www.singular.uni-kl.de/forum/viewtopic.php?t=2769
-    (fetchpatch {
-      name = "move_error_handler_out_of_libsingular.patch";
-      # rebased version of https://github.com/Singular/Sources/commit/502cf86d0bb2a96715be6764774b64a69c1ca34c.patch
-      url = "https://git.sagemath.org/sage.git/plain/build/pkgs/singular/patches/singular-ntl-error-handler.patch?h=50b9ae2fd233c30860e1cbb3e63a26f2cc10560a";
-      sha256 = "0vgh4m9zn1kjl0br68n04j4nmn5i1igfn28cph0chnwf7dvr9194";
-    })
-  ];
-
   # For reference (last checked on commit 75f460d):
-  # https://github.com/Singular/Sources/blob/spielwiese/doc/Building-Singular-from-source.md
-  # https://github.com/Singular/Sources/blob/spielwiese/doc/external-packages-dynamic-modules.md
+  # https://github.com/Singular/Singular/blob/spielwiese/doc/Building-Singular-from-source.md
+  # https://github.com/Singular/Singular/blob/spielwiese/doc/external-packages-dynamic-modules.md
   buildInputs = [
     # necessary
     gmp
@@ -60,6 +99,8 @@ stdenv.mkDerivation rec {
     readline
     ntl
     flint
+    lrcalc
+    gfan
   ] ++ lib.optionals enableGfanlib [
     cddlib
   ];
@@ -68,6 +109,12 @@ stdenv.mkDerivation rec {
     perl
     pkg-config
     autoreconfHook
+    sharutils # needed for regress.cmd install checks
+  ] ++ lib.optionals enableDocs [
+    doxygen
+    graphviz
+    texinfo4
+    texlive.combined.scheme-small
   ];
 
   preAutoreconf = ''
@@ -85,23 +132,62 @@ stdenv.mkDerivation rec {
     # do nothing
   '';
 
+  doCheck = true; # very basic checks, does not test any libraries
+
   installPhase = ''
     mkdir -p "$out"
     cp -r Singular/LIB "$out/lib"
     make install
-
+  '' + lib.optionalString enableDocs ''
+    # Sage uses singular.hlp (which is not in the tarball)
+    mkdir -p $out/share/info
+    cp doc/singular.hlp $out/share/info
+  '' + ''
     # Make sure patchelf picks up the right libraries
     rm -rf libpolys factory resources omalloc Singular
   '';
 
+  # singular tests are a bit complicated, see
+  # https://github.com/Singular/Singular/tree/spielwiese/Tst
+  # https://www.singular.uni-kl.de/forum/viewtopic.php&t=2773
+  testsToRun = [
+    "Old/universal.lst"
+    "Buch/buch.lst"
+    "Plural/short.lst"
+    "Old/factor.tst"
+  ] ++ lib.optionals enableGfanlib [
+    # tests that require gfanlib
+    "Short/ok_s.lst"
+  ];
+
   # simple test to make sure singular starts and finds its libraries
   doInstallCheck = true;
   installCheckPhase = ''
+    # Very basic sanity check to make sure singular starts and finds its libraries.
+    # This is redundant with the below tests. It is only kept because the singular test
+    # runner is a bit complicated. In case we decide to give up those tests in the future,
+    # this will still be useful. It takes barely any time.
     "$out/bin/Singular" -c 'LIB "freegb.lib"; exit;'
     if [ $? -ne 0 ]; then
         echo >&2 "Error loading the freegb library in Singular."
         exit 1
     fi
+
+    # Run the test suite
+    cd Tst
+    perl ./regress.cmd \
+      -s "$out/bin/Singular" \
+      ${lib.concatStringsSep " " (map lib.escapeShellArg testsToRun)} \
+      2>"$TMPDIR/out-err.log"
+
+    # unfortunately regress.cmd always returns exit code 0, so check stderr
+    # https://www.singular.uni-kl.de/forum/viewtopic.php&t=2773
+    if [[ -s "$TMPDIR/out-err.log" ]]; then
+      cat "$TMPDIR/out-err.log"
+      exit 1
+    fi
+
+    echo "Exit status $?"
   '';
 
   enableParallelBuilding = true;
@@ -110,6 +196,7 @@ stdenv.mkDerivation rec {
     description = "A CAS for polynomial computations";
     maintainers = teams.sage.members;
     # 32 bit x86 fails with some link error: `undefined reference to `__divmoddi4@GCC_7.0.0'`
+    # https://www.singular.uni-kl.de:8002/trac/ticket/837
     platforms = subtractLists platforms.i686 platforms.unix;
     license = licenses.gpl3; # Or GPLv2 at your option - but not GPLv4
     homepage = "http://www.singular.uni-kl.de";
diff --git a/nixpkgs/pkgs/applications/science/math/singular/disable-docs-for-optional-unpackaged-deps.patch b/nixpkgs/pkgs/applications/science/math/singular/disable-docs-for-optional-unpackaged-deps.patch
new file mode 100644
index 000000000000..46d92922f3ce
--- /dev/null
+++ b/nixpkgs/pkgs/applications/science/math/singular/disable-docs-for-optional-unpackaged-deps.patch
@@ -0,0 +1,112 @@
+commit 9e8b044d982e132cf35a106a1cc0cf7e77b27f7c
+Author: Mauricio Collares <mauricio@collares.org>
+Date:   Thu Apr 15 20:33:21 2021 -0300
+
+    Disable manual sections using optional packages not yet in Nixpkgs
+
+        * normaliz.lib depends on normaliz.
+        * polymake.lib depends on topcom.
+        * recover.lib depends on bertini.
+        * sing4ti2.lib depends on 4ti2.
+        * tateProdCplxNegGrad.lib uses multigrading.lib, which depends on 4ti2.
+
+diff --git a/doc/singular.doc b/doc/singular.doc
+index 64b969d39..e704f95f0 100644
+--- a/doc/singular.doc
++++ b/doc/singular.doc
+@@ -407,7 +407,6 @@ LIB "all.lib";
+ * nfmodsyz_lib:: Syzygy modules of submodules of free modules over algebraic number fields
+ * noether_lib:: Noether normalization of an ideal
+ * normal_lib:: procedure for normalization
+-* normaliz_lib:: integral closure, normalization for monomial ideals, toric ideals
+ * pointid_lib:: factorized lex GB of the vanishing ideal of a set of points
+ * primdec_lib:: procedures for primary decomposition
+ * primdecint_lib:: primary decomposition over the integers
+@@ -416,7 +415,6 @@ LIB "all.lib";
+ * reesclos_lib:: Rees Algebra and integral closure of an ideal
+ * rstandard_lib:: Janet bases and border bases for ideals
+ * sagbi_lib:: Subalgebras bases Analogous to Groebner bases for ideals
+-* sing4ti2_lib:: interface to program 4ti2
+ * symodstd_lib:: Groebner bases for symmetric ideals
+ * toric_lib:: toric ideals
+ @end menu
+@@ -521,10 +519,6 @@ LIB "all.lib";
+ @node normal_lib
+ @subsection normal_lib
+ @c lib normal.lib
+-@c ---------------------------------------------------------
+-@node normaliz_lib
+-@subsection normaliz_lib
+-@c lib normaliz.lib tag:normaliz
+ @c ----------------------------------------------------------
+ @node pointid_lib
+ @subsection pointid_lib
+@@ -558,10 +552,6 @@ LIB "all.lib";
+ @subsection sagbi_lib
+ @c lib sagbi.lib
+ @c ---------------------------------------------------------
+-@node sing4ti2_lib
+-@subsection sing4ti2_lib
+-@c lib sing4ti2.lib tag:sing4ti2
+-@c ----------------------------------------------------------
+ @node symodstd_lib
+ @subsection symodstd_lib
+ @c lib symodstd.lib
+@@ -873,7 +863,6 @@ iniD, reslist, sumlist, dividelist, createlist
+ * solve_lib:: procedures to solve polynomial systems
+ * triang_lib:: procedures for decomposing zero-dimensional ideals
+ * ntsolve_lib:: one real solution of polynomial systems (Newton iteration)
+-* recover_lib:: Hybrid numerical/symbolical algorithms
+ * rootisolation_lib:: real root isolation with intervals
+ * signcond_lib:: computing realizable sign conditions
+ * zeroset_lib:: procedures for roots and factorization
+@@ -904,10 +893,6 @@ iniD, reslist, sumlist, dividelist, createlist
+ @subsection ntsolve_lib
+ @c lib ntsolve.lib
+ @c ---------------------------------------------------------
+-@node recover_lib
+-@subsection recover_lib
+-@c lib recover.lib tag:bertini
+-@c ----------------------------------------------------------
+ @node rootisolation_lib
+ @subsection rootisolation_lib
+ @c lib rootisolation.lib
+@@ -1108,7 +1093,6 @@ but not for serious computations.
+ * cimonom_lib:: complete intersection for toric ideals
+ * gfan_lib:: A gfanlib interface for Singular
+ * gitfan_lib:: Compute GIT-fans
+-* polymake_lib:: interface to TOPCOM
+ * realizationMatroids_lib:: Realizability for Tropical Fan Curves
+ * tropical_lib:: interface to gfan
+ * tropicalNewton_lib:: Newton polygons in tropical geometry
+@@ -1125,10 +1109,7 @@ but not for serious computations.
+ @node gitfan_lib
+ @subsection gitfan_lib
+ @c lib gitfan.lib
+-@c ----------------------------------------------------------
+-@node polymake_lib
+-@subsection polymake_lib
+-@c lib polymake.lib tag:topcom
++
+ @c ----------------------------------------------------------
+ @node realizationMatroids_lib
+ @subsection realizationMatroids_lib
+@@ -1219,7 +1200,6 @@ Comments should be send to the author of the library directly.
+ * stanleyreisner_lib:: T1 and T2 for a general Stanley-Reiser ring
+ * swalk_lib:: Sagbi Walk Conversion Algorithm
+ * systhreads_lib:: multi-threaded objects
+-* tateProdCplxNegGrad_lib:: sheaf cohomology on product of projective spaces
+ * VecField_lib:: vector fields
+ @end menu
+ @c ----------------------------------------------------------
+@@ -1310,10 +1290,6 @@ Todos/Issues:
+ @subsection systhreads_lib
+ @c lib systhreads.lib
+ @c ---------------------------------------------------------
+-@node tateProdCplxNegGrad_lib
+-@subsection tateProdCplxNegGrad_lib
+-@c lib tateProdCplxNegGrad.lib
+-@c ---------------------------------------------------------
+ @node VecField_lib
+ @subsection VecField_lib
+ @c lib VecField.lib
diff --git a/nixpkgs/pkgs/applications/science/math/singular/disable-vspace-on-aarch64.patch b/nixpkgs/pkgs/applications/science/math/singular/disable-vspace-on-aarch64.patch
new file mode 100644
index 000000000000..3e51b7fb2cec
--- /dev/null
+++ b/nixpkgs/pkgs/applications/science/math/singular/disable-vspace-on-aarch64.patch
@@ -0,0 +1,15 @@
+diff --git a/kernel/mod2.h b/kernel/mod2.h
+index 867fcae47..2abd84f23 100644
+--- a/kernel/mod2.h
++++ b/kernel/mod2.h
+@@ -60,8 +60,10 @@
+ 
+ /* define for parallel processes with shared memory */
+ #ifndef __CCYGWIN__
++#ifndef SI_CPU_AARCH64
+ #define HAVE_VSPACE 1
+ #endif
++#endif
+ 
+ /*#define PROFILING*/
+ #ifdef PROFILING
diff --git a/nixpkgs/pkgs/applications/science/math/singular/redhat-aarch64.patch b/nixpkgs/pkgs/applications/science/math/singular/redhat-aarch64.patch
new file mode 100644
index 000000000000..e0db6e87f994
--- /dev/null
+++ b/nixpkgs/pkgs/applications/science/math/singular/redhat-aarch64.patch
@@ -0,0 +1,38 @@
+diff --git a/m4/cpu-check.m4 b/m4/cpu-check.m4
+index 3cf0a7f08..12bb926ac 100644
+--- a/m4/cpu-check.m4
++++ b/m4/cpu-check.m4
+@@ -37,6 +37,18 @@ if test "$ac_cv_singcpuname" = ppc; then
+   AC_DEFINE(SI_CPU_PPC,1,"PPC")
+   AC_SUBST(SI_CPU_PPC)
+ fi
++if test "$ac_cv_singcpuname" = arm -o "$ac_cv_singcpuname" = armel; then
++  AC_DEFINE(SI_CPU_ARM,1,"ARM")
++  AC_SUBST(SI_CPU_ARM)
++fi
++if test "$ac_cv_singcpuname" = aarch64; then
++  AC_DEFINE(SI_CPU_AARCH64,1,"AARCH64")
++  AC_SUBST(SI_CPU_AARCH64)
++fi
++if test "$ac_cv_singcpuname" = s390; then
++  AC_DEFINE(SI_CPU_S390,1,"S390")
++  AC_SUBST(SI_CPU_S390)
++fi
+ 
+ # UNAME and PATH
+ AC_MSG_CHECKING(uname for Singular)
+@@ -65,6 +77,14 @@ dnl testet on: ppc_Linux, 740/750 PowerMac G3, 512k L2 cache
+   [powerpc*|ppc*], [AC_DEFINE(HAVE_GENERIC_MULT,1,multiplication is fast on the cpu: a*b is with mod otherwise using tables of logartihms)],
+ dnl the following settings seems to be better on arm processors
+   [arm*], [],
++dnl FIXME: need to run some tests
++  [aarch64*], [
++            AC_DEFINE(HAVE_MULT_MOD,1,multiplication is fast on the cpu: a*b is with mod otherwise using tables of logartihms)
++            AC_DEFINE(HAVE_GENERIC_ADD,1,use branch for addition in Z/p otherwise it uses a generic add)
++            AC_DEFINE(HAVE_DIV_MOD,1,division using extend euclidian algorithm otherwise using tables of logartihms)
++            ],
++dnl FIXME: need to run some tests
++  [s390*], [AC_DEFINE(HAVE_GENERIC_ADD,1,use branch for addition in Z/p otherwise it uses a generic add)],
+   []
+ )
+ 
diff --git a/nixpkgs/pkgs/applications/science/math/singular/use-older-ax-prog-cc-for-build.patch b/nixpkgs/pkgs/applications/science/math/singular/use-older-ax-prog-cc-for-build.patch
new file mode 100644
index 000000000000..f664378617cf
--- /dev/null
+++ b/nixpkgs/pkgs/applications/science/math/singular/use-older-ax-prog-cc-for-build.patch
@@ -0,0 +1,194 @@
+diff --git a/m4/ax_prog_cc_for_build.m4 b/m4/ax_prog_cc_for_build.m4
+index f7410d74b..12cb005a5 100644
+--- a/m4/ax_prog_cc_for_build.m4
++++ b/m4/ax_prog_cc_for_build.m4
+@@ -32,35 +32,31 @@
+ #   and this notice are preserved. This file is offered as-is, without any
+ #   warranty.
+ 
+-#serial 18
++#serial 9
+ 
+ AU_ALIAS([AC_PROG_CC_FOR_BUILD], [AX_PROG_CC_FOR_BUILD])
+ AC_DEFUN([AX_PROG_CC_FOR_BUILD], [dnl
+ AC_REQUIRE([AC_PROG_CC])dnl
+ AC_REQUIRE([AC_PROG_CPP])dnl
+-AC_REQUIRE([AC_CANONICAL_BUILD])dnl
++AC_REQUIRE([AC_EXEEXT])dnl
++AC_REQUIRE([AC_CANONICAL_HOST])dnl
+ 
+ dnl Use the standard macros, but make them use other variable names
+ dnl
+ pushdef([ac_cv_prog_CPP], ac_cv_build_prog_CPP)dnl
+-pushdef([ac_cv_prog_cc_c89], ac_cv_build_prog_cc_c89)dnl
+ pushdef([ac_cv_prog_gcc], ac_cv_build_prog_gcc)dnl
+ pushdef([ac_cv_prog_cc_works], ac_cv_build_prog_cc_works)dnl
+ pushdef([ac_cv_prog_cc_cross], ac_cv_build_prog_cc_cross)dnl
+ pushdef([ac_cv_prog_cc_g], ac_cv_build_prog_cc_g)dnl
+-pushdef([ac_cv_c_compiler_gnu], ac_cv_build_c_compiler_gnu)dnl
+ pushdef([ac_cv_exeext], ac_cv_build_exeext)dnl
+ pushdef([ac_cv_objext], ac_cv_build_objext)dnl
+ pushdef([ac_exeext], ac_build_exeext)dnl
+ pushdef([ac_objext], ac_build_objext)dnl
+ pushdef([CC], CC_FOR_BUILD)dnl
+ pushdef([CPP], CPP_FOR_BUILD)dnl
+-pushdef([GCC], GCC_FOR_BUILD)dnl
+ pushdef([CFLAGS], CFLAGS_FOR_BUILD)dnl
+ pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl
+-pushdef([EXEEXT], BUILD_EXEEXT)dnl
+ pushdef([LDFLAGS], LDFLAGS_FOR_BUILD)dnl
+-pushdef([OBJEXT], BUILD_OBJEXT)dnl
+ pushdef([host], build)dnl
+ pushdef([host_alias], build_alias)dnl
+ pushdef([host_cpu], build_cpu)dnl
+@@ -71,29 +67,27 @@ pushdef([ac_cv_host_alias], ac_cv_build_alias)dnl
+ pushdef([ac_cv_host_cpu], ac_cv_build_cpu)dnl
+ pushdef([ac_cv_host_vendor], ac_cv_build_vendor)dnl
+ pushdef([ac_cv_host_os], ac_cv_build_os)dnl
+-pushdef([ac_tool_prefix], ac_build_tool_prefix)dnl
+-pushdef([am_cv_CC_dependencies_compiler_type], am_cv_build_CC_dependencies_compiler_type)dnl
+-pushdef([am_cv_prog_cc_c_o], am_cv_build_prog_cc_c_o)dnl
+-pushdef([cross_compiling], cross_compiling_build)dnl
++pushdef([ac_cpp], ac_build_cpp)dnl
++pushdef([ac_compile], ac_build_compile)dnl
++pushdef([ac_link], ac_build_link)dnl
+ 
+-cross_compiling_build=no
++save_cross_compiling=$cross_compiling
++save_ac_tool_prefix=$ac_tool_prefix
++cross_compiling=no
++ac_tool_prefix=
+ 
+-ac_build_tool_prefix=
+-AS_IF([test -n "$build"],      [ac_build_tool_prefix="$build-"],
+-      [test -n "$build_alias"],[ac_build_tool_prefix="$build_alias-"])
+-
+-AC_LANG_PUSH([C])
+ AC_PROG_CC
+-_AC_COMPILER_EXEEXT
+-_AC_COMPILER_OBJEXT
+ AC_PROG_CPP
++AC_EXEEXT
++
++ac_tool_prefix=$save_ac_tool_prefix
++cross_compiling=$save_cross_compiling
+ 
+ dnl Restore the old definitions
+ dnl
+-popdef([cross_compiling])dnl
+-popdef([am_cv_prog_cc_c_o])dnl
+-popdef([am_cv_CC_dependencies_compiler_type])dnl
+-popdef([ac_tool_prefix])dnl
++popdef([ac_link])dnl
++popdef([ac_compile])dnl
++popdef([ac_cpp])dnl
+ popdef([ac_cv_host_os])dnl
+ popdef([ac_cv_host_vendor])dnl
+ popdef([ac_cv_host_cpu])dnl
+@@ -104,33 +98,25 @@ popdef([host_vendor])dnl
+ popdef([host_cpu])dnl
+ popdef([host_alias])dnl
+ popdef([host])dnl
+-popdef([OBJEXT])dnl
+ popdef([LDFLAGS])dnl
+-popdef([EXEEXT])dnl
+ popdef([CPPFLAGS])dnl
+ popdef([CFLAGS])dnl
+-popdef([GCC])dnl
+ popdef([CPP])dnl
+ popdef([CC])dnl
+ popdef([ac_objext])dnl
+ popdef([ac_exeext])dnl
+ popdef([ac_cv_objext])dnl
+ popdef([ac_cv_exeext])dnl
+-popdef([ac_cv_c_compiler_gnu])dnl
+ popdef([ac_cv_prog_cc_g])dnl
+ popdef([ac_cv_prog_cc_cross])dnl
+ popdef([ac_cv_prog_cc_works])dnl
+-popdef([ac_cv_prog_cc_c89])dnl
+ popdef([ac_cv_prog_gcc])dnl
+ popdef([ac_cv_prog_CPP])dnl
+ 
+-dnl restore global variables ac_ext, ac_cpp, ac_compile,
+-dnl ac_link, ac_compiler_gnu (dependant on the current
+-dnl language after popping):
+-AC_LANG_POP([C])
+-
+ dnl Finally, set Makefile variables
+ dnl
++BUILD_EXEEXT=$ac_build_exeext
++BUILD_OBJEXT=$ac_build_objext
+ AC_SUBST(BUILD_EXEEXT)dnl
+ AC_SUBST(BUILD_OBJEXT)dnl
+ AC_SUBST([CFLAGS_FOR_BUILD])dnl
+diff --git a/m4/ax_prog_cxx_for_build.m4 b/m4/ax_prog_cxx_for_build.m4
+index 4d976769f..17c19a89f 100644
+--- a/m4/ax_prog_cxx_for_build.m4
++++ b/m4/ax_prog_cxx_for_build.m4
+@@ -31,7 +31,7 @@
+ #   and this notice are preserved. This file is offered as-is, without any
+ #   warranty.
+ 
+-#serial 4
++#serial 3
+ 
+ AU_ALIAS([AC_PROG_CXX_FOR_BUILD], [AX_PROG_CXX_FOR_BUILD])
+ AC_DEFUN([AX_PROG_CXX_FOR_BUILD], [dnl
+@@ -49,7 +49,6 @@ pushdef([ac_cv_prog_cxx_cross], ac_cv_build_prog_cxx_cross)dnl
+ pushdef([ac_cv_prog_cxx_g], ac_cv_build_prog_cxx_g)dnl
+ pushdef([CXX], CXX_FOR_BUILD)dnl
+ pushdef([CXXCPP], CXXCPP_FOR_BUILD)dnl
+-pushdef([GXX], GXX_FOR_BUILD)dnl
+ pushdef([CXXFLAGS], CXXFLAGS_FOR_BUILD)dnl
+ pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl
+ pushdef([CXXCPPFLAGS], CXXCPPFLAGS_FOR_BUILD)dnl
+@@ -63,25 +62,26 @@ pushdef([ac_cv_host_alias], ac_cv_build_alias)dnl
+ pushdef([ac_cv_host_cpu], ac_cv_build_cpu)dnl
+ pushdef([ac_cv_host_vendor], ac_cv_build_vendor)dnl
+ pushdef([ac_cv_host_os], ac_cv_build_os)dnl
+-pushdef([ac_tool_prefix], ac_build_tool_prefix)dnl
+-pushdef([am_cv_CXX_dependencies_compiler_type], am_cv_build_CXX_dependencies_compiler_type)dnl
+-pushdef([cross_compiling], cross_compiling_build)dnl
++pushdef([ac_cxxcpp], ac_build_cxxcpp)dnl
++pushdef([ac_compile], ac_build_compile)dnl
++pushdef([ac_link], ac_build_link)dnl
+ 
+-cross_compiling_build=no
++save_cross_compiling=$cross_compiling
++save_ac_tool_prefix=$ac_tool_prefix
++cross_compiling=no
++ac_tool_prefix=
+ 
+-ac_build_tool_prefix=
+-AS_IF([test -n "$build"],      [ac_build_tool_prefix="$build-"],
+-      [test -n "$build_alias"],[ac_build_tool_prefix="$build_alias-"])
+-
+-AC_LANG_PUSH([C++])
+ AC_PROG_CXX
+ AC_PROG_CXXCPP
+ 
++ac_tool_prefix=$save_ac_tool_prefix
++cross_compiling=$save_cross_compiling
++
+ dnl Restore the old definitions
+ dnl
+-popdef([cross_compiling])dnl
+-popdef([am_cv_CXX_dependencies_compiler_type])dnl
+-popdef([ac_tool_prefix])dnl
++popdef([ac_link])dnl
++popdef([ac_compile])dnl
++popdef([ac_cxxcpp])dnl
+ popdef([ac_cv_host_os])dnl
+ popdef([ac_cv_host_vendor])dnl
+ popdef([ac_cv_host_cpu])dnl
+@@ -103,10 +103,6 @@ popdef([ac_cv_prog_cxx_works])dnl
+ popdef([ac_cv_prog_gxx])dnl
+ popdef([ac_cv_prog_CXXCPP])dnl
+ 
+-dnl restore global variables (dependant on the current
+-dnl language after popping):
+-AC_LANG_POP([C++])
+-
+ dnl Finally, set Makefile variables
+ dnl
+ AC_SUBST([CXXFLAGS_FOR_BUILD])dnl