Build system cleanup and improvements

This includes a much more state-of-the-art autotools build system.