Continuation of #29038.
Upstreaming a generalized version of
https://salsa.debian.org/science-team/sagemath/-/blob/master/debian/patches/d0-maxima.patch
CC: @tobihan @orlitzky @kiwifb
Component: build: configure
Author: François Bissey
Branch: 3da851f
Reviewer: Matthias Koeppe
Issue created by migration from https://trac.sagemath.org/ticket/30563