Autoconf improvements

Let's merge the non-controversial commits of #3147, at least if it passes the pulltester now.