Split the build script's internal functions off into modules in lib/