Fix up build script to be more robust.