Build system improvements

See the commit messages