Add the ability to save and restore environment variables.

This fixes bugs where CFLAGS/CXXFLAGS/CC/CXX aren't the same when automatic reconfigures take place. The mechanism in this patch just saves the variables in the cache, and restores them when building. This should be pretty flexible, for example we could let the user choose which env vars they want set on each build. (Though, it would not allow for per-command/builder variables.)