Added support to control build type with env vars

Fixes #689 and #699.