+BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, const Flags &flags, const Flags &static_flags)
+{
+ BinaryPackage *pkg = new BinaryPackage(builder, name);
+ pkg->use_pkgconfig = true;
+
+ process_flags(flags, pkg->export_binfo);
+
+ Flags exclusive_static_flags;
+ for(const string &f: static_flags)
+ if(!any_equals(flags, f))
+ exclusive_static_flags.push_back(f);
+ process_flags(exclusive_static_flags, pkg->static_binfo);
+
+ return pkg;
+}
+
+void BinaryPackage::process_flags(const Flags &flags, BuildInfo &binfo)
+{
+ for(const string &f: flags)
+ {
+ if(!f.compare(0, 2, "-I"))
+ binfo.incpath.push_back(f.substr(2));
+ else if(!f.compare(0, 2, "-D"))
+ {
+ string::size_type equals = f.find('=');
+ if(equals!=string::npos)
+ binfo.defines[f.substr(2, equals-2)] = f.substr(equals+1);
+ else
+ binfo.defines[f.substr(2)] = string();
+ }
+ else if(!f.compare(0, 2, "-L"))
+ binfo.libpath.push_back(f.substr(2));
+ else if(!f.compare(0, 2, "-l"))
+ binfo.libs.push_back(f.substr(2));
+ else if(f=="-pthread")
+ binfo.threads = true;
+ }
+}
+