build_wrapper: Remove lots of duplicated code

Mostly code related to RM_COMMAND and CURL_COMMAND

Change-Id: Ifc12ae79fc22d280924b2c2eeb6f2592752dc98a
Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>