X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbinarypackage.cpp;h=adfca1a273bd4ae86b1296e23225918000f0c6cd;hb=5e00719d0c63e306786ff36df61797cdbc86f3e9;hp=4c5382191661b7c627c0ef0e94db63fa34ab8ec9;hpb=0d95fee118a3fcd78f153dca5721d9fe19b6f6bf;p=builder.git diff --git a/source/binarypackage.cpp b/source/binarypackage.cpp index 4c53821..adfca1a 100644 --- a/source/binarypackage.cpp +++ b/source/binarypackage.cpp @@ -1,7 +1,10 @@ +#include #include #include #include "binarypackage.h" #include "builder.h" +#include "filetarget.h" +#include "staticlibrary.h" using namespace std; using namespace Msp; @@ -12,15 +15,52 @@ BinaryPackage::BinaryPackage(Builder &b, const string &n): use_pkgconfig = false; } +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; + } +} + 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(); + auto is_relative = [](const FS::Path &p){ return !p.is_absolute(); }; + bool has_relative_paths = any_of(export_binfo.libpath.begin(), export_binfo.libpath.end(), is_relative) || + any_of(export_binfo.incpath.begin(), export_binfo.incpath.end(), is_relative); - list bases; + vector 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 */ @@ -31,9 +71,9 @@ void BinaryPackage::do_prepare() bases.push_back(FS::Path()); bool system = false; - for(list::const_iterator i=bases.begin(); i!=bases.end(); ++i) + for(const FS::Path &b: bases) { - FS::Path prefix = *i; + FS::Path prefix = b; system = prefix.empty(); if(system) { @@ -43,29 +83,29 @@ void BinaryPackage::do_prepare() prefix /= arch.get_cross_prefix(); } - BuildInfo::PathList libpath = export_binfo.libpath; + VirtualFileSystem::SearchPath 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; + for(FS::Path &p: libpath) + p = prefix/p; 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); + for(const string &l: export_binfo.libs) + all_found &= (builder.get_vfs().find_library(l, libpath, export_binfo.libmode, system)!=0); - BuildInfo::PathList incpath = export_binfo.incpath; + VirtualFileSystem::SearchPath 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(FS::Path &p: incpath) + p = prefix/p; - for(HeaderList::const_iterator j=headers.begin(); j!=headers.end(); ++j) - all_found &= (builder.get_vfs().find_header(*j, incpath, system)!=0); + for(const string &h: headers) + all_found &= (builder.get_vfs().find_header(h, 0, 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()))); + builder.get_logger().log("configure", "%s found in %s", name, ((system && use_pkgconfig) ? "system" : base_path.str())); break; } } @@ -73,6 +113,7 @@ void BinaryPackage::do_prepare() if(base_path.empty()) { // TODO report which files were not found + builder.get_logger().log("problems", "Cannot locate files for %s", name); problems.push_back("Cannot locate files"); return; } @@ -86,40 +127,27 @@ void BinaryPackage::do_prepare() 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; + for(FS::Path &p: export_binfo.incpath) + p = base_path/p; + for(FS::Path &p: export_binfo.libpath) + p = base_path/p; } -} - -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(!static_binfo.libs.empty()) { - 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; + VirtualFileSystem::SearchPath combined_libpath = static_binfo.libpath; + combined_libpath.insert(combined_libpath.end(), export_binfo.libpath.begin(), export_binfo.libpath.end()); + + for(const string &l: export_binfo.libs) + if(Target *lib = builder.get_vfs().find_library(l, export_binfo.libpath, BuildInfo::FORCE_STATIC, system)) + if(StaticLibrary *stlib = dynamic_cast(lib)) + { + for(const string &s: static_binfo.libs) + stlib->add_required_library(s); + for(const FS::Path &p: combined_libpath) + stlib->add_library_path(p); + } } - - return pkg; }