Fix build script

BUGS:
* Fetch remote when "git rev-parse" failed, in case the revision is newly added.
* Correctly detect git command failure.
* Fix protobuf tag name.

OTHER:
* Add --clean-build switch to cleanup only built artifacts of dependencies.