+ if(include[0]=='"' && (tgt=get_header(Path::Path(from)/fn)))
+ ;
+ else if((tgt=get_header(Path::Path("/usr/include")/fn)))
+ ;
+ //XXX Determine the C++ header location dynamically
+ else if((tgt=get_header(Path::Path("/usr/include/c++/4.1.2")/fn)))
+ ;
+ else
+ {
+ for(list<string>::const_iterator j=path.begin(); (j!=path.end() && !tgt); ++j)
+ tgt=get_header(cwd/ *j/fn);
+ }
+
+ includes.insert(TargetMap::value_type(id, tgt));
+
+ return tgt;
+}
+
+/**
+Tries to locate a library with the given library path. Considers known targets
+as well as existing files. If a matching target is not found but a file exists,
+a new SystemLibrary target will be created and returned.
+
+@param lib Name of the library to get (without "lib" prefix or extension)
+@param path List of paths to search for the library
+@param mode Shared / static mode
+
+@return Some kind of library target, if a match was found
+*/
+Target *Builder::get_library(const string &lib, const string &arch, const list<string> &path, LibMode mode)
+{
+ string hash(8, 0);
+ for(list<string>::const_iterator i=path.begin(); i!=path.end(); ++i)
+ update_hash(hash, *i);
+
+ //XXX Incorporate mode into id
+ string id=hash+lib;
+ TargetMap::iterator i=libraries.find(id);
+ if(i!=libraries.end())
+ return i->second;
+
+ StringList syspath;
+ if(arch=="native")
+ {
+ syspath.push_back("/lib");
+ syspath.push_back("/usr/lib");
+ }
+ else
+ syspath.push_back("/usr/"+get_arch_prefix(arch)+"/lib");
+
+ Target *tgt=0;
+ for(StringList::iterator j=syspath.begin(); (!tgt && j!=syspath.end()); ++j)
+ tgt=get_library(lib, arch, *j, mode);
+ for(StringList::const_iterator j=path.begin(); (!tgt && j!=path.end()); ++j)
+ tgt=get_library(lib, arch, cwd/ *j, mode);
+
+ libraries.insert(TargetMap::value_type(id, tgt));
+
+ return tgt;
+}
+
+const string &Builder::get_arch_prefix(const string &arch) const
+{
+ StringMap::const_iterator i=archs.find(arch);
+ if(i==archs.end())
+ throw InvalidParameterValue("Unknown architecture");
+
+ return i->second;
+}
+
+string Builder::get_tool(const std::string &tool, const std::string &arch)
+{
+ ToolMap::iterator i=tools.find(arch);
+ if(i!=tools.end())
+ {
+ StringMap::iterator j=i->second.find(tool);
+ if(j!=i->second.end())
+ return j->second;
+ }
+
+ // Either the arch, or the tool within the arch was not found
+ i=tools.find("native");
+ StringMap::iterator j=i->second.find(tool);
+ if(j==i->second.end())
+ throw InvalidParameterValue("Unknown tool");
+
+ return get_arch_prefix(arch)+"-"+j->second;
+}
+
+void Builder::apply_profile_template(Config &config, const string &pt) const
+{
+ vector<string> parts=split(pt, '-');
+
+ for(vector<string>::iterator i=parts.begin(); i!=parts.end(); ++i)
+ {
+ ProfileTemplateMap::const_iterator j=profile_tmpl.find(*i);
+ if(j==profile_tmpl.end())
+ continue;
+
+ config.update(j->second);
+ }