]> git.tdb.fi Git - builder.git/commitdiff
Locate and check the existence of the libraries of binary packages
authorMikko Rasa <tdb@tdb.fi>
Mon, 23 Jul 2012 18:43:13 +0000 (21:43 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 23 Jul 2012 18:43:13 +0000 (21:43 +0300)
source/binarypackage.cpp
source/binarypackage.h

index a167269290dcd24d69a3f37b2879584a53ccdd85..7e2435a4a6fce6b138d3f319f40069ecf4bafb40 100644 (file)
@@ -14,13 +14,68 @@ BinaryPackage::BinaryPackage(Builder &b, const string &n):
 
 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)
index 088c3e1eac2264dc94cf3a96de0a3e11b4947e30..5b47d645c149710b71eaed051a577c4fa5fc4b03 100644 (file)
@@ -18,6 +18,10 @@ public:
                void build_info();
        };
 
+private:
+       Msp::FS::Path base_path;
+
+public:
        BinaryPackage(Builder &, const std::string &);
 
        static BinaryPackage *from_flags(Builder &, const std::string &, const std::vector<std::string> &);