+void Config::finish()
+{
+ for(unsigned n=0; n<20; ++n)
+ {
+ bool changed=false;
+ for(OptionMap::iterator i=options.begin(); i!=options.end(); ++i)
+ {
+ Option &opt=i->second;
+ unsigned dollar=0;
+ while((dollar=opt.value.find('$', dollar))!=string::npos)
+ {
+ unsigned end;
+ string var;
+ if(opt.value[dollar+1]=='{')
+ {
+ end=opt.value.find('}', dollar+2);
+ if(end==string::npos)
+ throw Exception("Unterminated variable reference");
+ var=opt.value.substr(dollar+2, end-dollar-2);
+ ++end;
+ }
+ else
+ {
+ for(end=dollar+1; (isalnum(opt.value[end]) && opt.value[end]!='_'); ++end);
+ var=opt.value.substr(dollar+1, end-dollar-1);
+ }
+
+ string value;
+ if(is_option(var))
+ value=get_option(var).value;
+ else
+ value=getenv(var.c_str());
+
+ opt.value.replace(dollar, end-dollar, value);
+
+ dollar+=value.size();
+ changed=true;
+ }
+ }
+
+ if(!changed)
+ break;
+ }
+}
+
+void Config::save() const
+{
+ Path::Path fn=package.get_source()/".options.cache";
+
+ OptionMap::const_iterator i=options.find("profile");
+ if(i!=options.end())
+ fn=package.get_source()/(".options."+i->second.value+".cache");
+
+ ofstream out(fn.str().c_str());
+ if(!out) return;
+
+ for(i=options.begin(); i!=options.end(); ++i)
+ out<<"option \""<<i->second.name<<"\" \""<<i->second.value<<"\";\n";
+}
+
+bool Config::set_option(const string &opt, const string &val)