void BinaryPackage::do_prepare()
{
- for(BuildInfo::PathList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i)
- if((*i)[0]=="@")
- *i = builder.get_prefix()/i->subpath(1);
+ bool has_relative_paths = false;
+ for(BuildInfo::PathList::const_iterator i=export_binfo.libpath.begin(); (!has_relative_paths && i!=export_binfo.libpath.end()); ++i)
+ has_relative_paths = !i->is_absolute();
+
+ list<FS::Path> bases;
+
+ /* If we have any relative paths that need resolving, or we have no paths at
+ all and are not using pkg-config, look for files in prefix */
+ if(has_relative_paths || (!use_pkgconfig && export_binfo.libpath.empty()))
+ bases.push_back(builder.get_prefix());
+
+ // Always look in system locations
+ bases.push_back(FS::Path());
+
+ bool system = false;
+ for(list<FS::Path>::const_iterator i=bases.begin(); i!=bases.end(); ++i)
+ {
+ FS::Path prefix = *i;
+ system = prefix.empty();
+ if(system)
+ {
+ prefix = "/usr";
+ const Architecture &arch = builder.get_current_arch();
+ if(arch.is_cross())
+ prefix /= arch.get_cross_prefix();
+ }
+
+ BuildInfo::PathList libpath = export_binfo.libpath;
+ if(!system && libpath.empty())
+ libpath.push_back("lib");
+ for(BuildInfo::PathList::iterator j=libpath.begin(); j!=libpath.end(); ++j)
+ *j = prefix/ *j;
+
+ bool all_found = true;
+ for(BuildInfo::WordList::const_iterator j=export_binfo.libs.begin(); j!=export_binfo.libs.end(); ++j)
+ all_found &= (builder.get_vfs().find_library(*j, libpath, export_binfo.libmode, system)!=0);
+ if(all_found)
+ {
+ base_path = prefix;
+ builder.get_logger().log("configure", format("%s found in %s", name, ((system && use_pkgconfig) ? "system" : base_path.str())));
+ break;
+ }
+ }
+
+ if(base_path.empty())
+ {
+ builder.problem(name, "Cannot locate files");
+ return;
+ }
+
+ /* Add default entries to paths if they're empty and the package was found
+ in a non-system location */
+ if(!system && export_binfo.incpath.empty())
+ export_binfo.incpath.push_back(base_path/"include");
+ if(!system && export_binfo.libpath.empty())
+ export_binfo.libpath.push_back(base_path/"lib");
+
+ for(BuildInfo::PathList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i)
+ *i = base_path/ *i;
for(BuildInfo::PathList::iterator i=export_binfo.libpath.begin(); i!=export_binfo.libpath.end(); ++i)
- if((*i)[0]=="@")
- *i = builder.get_prefix()/i->subpath(1);
+ *i = base_path/ *i;
}
BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, const vector<string> &flags)