Refactored build script to play better with external harnesses.