X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbinarypackage.cpp;h=5415f257ef180cf17953e525123a9119e5168a03;hb=HEAD;hp=22a415457e75844e52e3c8675953e3e351c8338c;hpb=08015c0f27f377fcd4aa186fca5bd8cf70723a5a;p=builder.git diff --git a/source/binarypackage.cpp b/source/binarypackage.cpp deleted file mode 100644 index 22a4154..0000000 --- a/source/binarypackage.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include -#include -#include "binarypackage.h" -#include "builder.h" - -using namespace std; -using namespace Msp; - -BinaryPackage::BinaryPackage(Builder &b, const string &n): - Package(b, n) -{ - use_pkgconfig = false; -} - -void BinaryPackage::do_prepare() -{ - 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(); - for(BuildInfo::PathList::const_iterator i=export_binfo.incpath.begin(); (!has_relative_paths && i!=export_binfo.incpath.end()); ++i) - has_relative_paths = !i->is_absolute(); - - list 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() && export_binfo.incpath.empty())) - bases.push_back(builder.get_prefix()); - - // Always look in system locations - bases.push_back(FS::Path()); - - bool system = false; - for(list::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); - - BuildInfo::PathList incpath = export_binfo.incpath; - if(!system && incpath.empty()) - incpath.push_back("include"); - for(BuildInfo::PathList::iterator j=incpath.begin(); j!=incpath.end(); ++j) - *j = prefix/ *j; - - for(HeaderList::const_iterator j=headers.begin(); j!=headers.end(); ++j) - all_found &= (builder.get_vfs().find_header(*j, incpath, 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"); - - if(has_relative_paths) - { - 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) - *i = base_path/ *i; - } -} - -BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, const vector &flags) -{ - BinaryPackage *pkg = new BinaryPackage(builder, name); - pkg->use_pkgconfig = true; - BuildInfo &binfo = pkg->export_binfo; - - for(vector::const_iterator i=flags.begin(); i!=flags.end(); ++i) - { - if(!i->compare(0, 2, "-I")) - binfo.incpath.push_back(i->substr(2)); - else if(!i->compare(0, 2, "-D")) - { - string::size_type equals = i->find('='); - if(equals!=string::npos) - binfo.defines[i->substr(2, equals-2)] = i->substr(equals+1); - else - binfo.defines[i->substr(2)] = string(); - } - else if(!i->compare(0, 2, "-L")) - binfo.libpath.push_back(i->substr(2)); - else if(!i->compare(0, 2, "-l")) - binfo.libs.push_back(i->substr(2)); - else if(*i=="-pthread") - binfo.threads = true; - } - - return pkg; -} - - -BinaryPackage::Loader::Loader(BinaryPackage &p): - DataFile::DerivedObjectLoader(p) -{ - add("build_info", &Loader::build_info); - add("header", &Loader::header); -} - -void BinaryPackage::Loader::build_info() -{ - load_sub(obj.export_binfo); -} - -void BinaryPackage::Loader::header(const string &h) -{ - obj.headers.push_back(h); -}