Fix autoconf bugs and improve determination of various memory numbers