Cleaning fixes, and other build system tweaks; part of #7941