Some build related changes.
Thanks to Thorsten Glaser for a few ideas.