From: Mikko Rasa Date: Sun, 15 Jul 2012 16:43:45 +0000 (+0300) Subject: Redesign the library mode system X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=af52dd8fd91fd0ef3dcd0faff524b4508c946aef;p=builder.git Redesign the library mode system --- diff --git a/source/binary.cpp b/source/binary.cpp index aa26608..6c915de 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -30,7 +30,7 @@ void Binary::find_depends() const SourcePackage &spkg = component->get_package(); LibMode libmode = spkg.get_library_mode(); - if(dynamic_cast(this)) + if(dynamic_cast(this) && libmode queue; diff --git a/source/component.cpp b/source/component.cpp index 3c8749e..88fe714 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -66,7 +66,7 @@ void Component::create_build_info() for(BuildInfo::PathList::iterator i=build_info.libpath.begin(); i!=build_info.libpath.end(); ++i) *i = (pkg.get_source() / *i).str(); - if(pkg.get_library_mode()!=DYNAMIC) + if(pkg.get_library_mode()get_soname().empty()) argv.push_back("-Wl,-soname,"+shlib->get_soname()); } - else if(comp.get_package().get_library_mode()==ALL_STATIC) - argv.push_back("-static"); const BuildInfo &binfo = comp.get_build_info(); for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i) @@ -141,6 +139,8 @@ Task *GnuLinker::Linker::run(const Target &target) const argv.push_back("-o"); argv.push_back(relative(bin.get_path(), work_dir).str()); + bool static_link_ok = (comp.get_package().get_library_mode()<=STATIC); + const Target::Dependencies &depends = target.get_depends(); for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i) { @@ -151,9 +151,15 @@ Task *GnuLinker::Linker::run(const Target &target) const else if(StaticLibrary *stlib = dynamic_cast(tgt)) argv.push_back(stlib->get_path().str()); else if(SharedLibrary *shlib = dynamic_cast(tgt)) + { argv.push_back("-l"+shlib->get_libname()); + static_link_ok = false; + } } + if(static_link_ok) + argv.push_back("-static"); + if(!builder.get_dry_run()) FS::mkpath(FS::dirname(bin.get_path()), 0755); diff --git a/source/misc.h b/source/misc.h index e3d4be8..45cd396 100644 --- a/source/misc.h +++ b/source/misc.h @@ -8,9 +8,10 @@ enum LibMode { - ALL_STATIC, - LOCAL_STATIC, - DYNAMIC + FORCE_STATIC, + STATIC, + DYNAMIC, + FORCE_DYNAMIC }; typedef std::list StringList; diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 1de15ef..7c91380 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -59,12 +59,14 @@ FS::Path SourcePackage::get_out_dir() const LibMode SourcePackage::get_library_mode() const { const string &mode = config.get_option("staticlibs").value; - if(mode=="all") - return ALL_STATIC; - else if(mode=="local") - return LOCAL_STATIC; - else if(mode=="none") + if(mode=="force") + return FORCE_STATIC; + else if(mode=="prefer") + return STATIC; + else if(mode=="avoid") return DYNAMIC; + else if(mode=="reject") + return FORCE_DYNAMIC; else throw runtime_error("unknown library mode"); } diff --git a/source/virtualfilesystem.cpp b/source/virtualfilesystem.cpp index cccc169..1de6630 100644 --- a/source/virtualfilesystem.cpp +++ b/source/virtualfilesystem.cpp @@ -76,38 +76,31 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath const Architecture &arch = builder.get_current_arch(); - /* Try dynamic libraries only if library mode permits it */ list shared_names; - if(mode!=ALL_STATIC) + if(mode!=FORCE_STATIC) { const list &shared_patterns = arch.get_shared_library_patterns(); for(list::const_iterator i=shared_patterns.begin(); i!=shared_patterns.end(); ++i) shared_names.push_back(i->apply(lib)); } - /* Static libraries are always considered, since sometimes shared versions - may not be available */ list static_names; - const list &static_patterns = arch.get_static_library_patterns(); - for(list::const_iterator i=static_patterns.begin(); i!=static_patterns.end(); ++i) - static_names.push_back(i->apply(lib)); + if(mode!=FORCE_DYNAMIC) + { + const list &static_patterns = arch.get_static_library_patterns(); + for(list::const_iterator i=static_patterns.begin(); i!=static_patterns.end(); ++i) + static_names.push_back(i->apply(lib)); + } for(list::const_iterator i=combined_path.begin(); i!=combined_path.end(); ++i) { - bool shared = true; - for(list::const_iterator j=shared_names.begin(); j!=static_names.end(); ) + const list *cur_names = (mode>=DYNAMIC ? &shared_names : &static_names); + for(list::const_iterator j=cur_names->begin(); j!=cur_names->end(); ) { - if(j==shared_names.end()) - { - j = static_names.begin(); - shared = false; - continue; - } - FS::Path filename = *i / *j; if(FileTarget *tgt = get_target(filename)) { - if(!shared || mode==DYNAMIC || !tgt->get_package()) + if(cur_names!=&shared_names || mode==DYNAMIC || !tgt->get_package()) { builder.get_logger().log("vfs", format("Library %s (%s) found in %s as existing %s", lib, *j, i->str(), tgt->get_type())); return tgt; @@ -116,13 +109,22 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath else if(file_exists(filename)) { builder.get_logger().log("vfs", format("Library %s (%s) found in %s", lib, *j, i->str())); - if(shared) + if(cur_names==&shared_names) return new SharedLibrary(builder, filename); else return new StaticLibrary(builder, filename); } - ++j; + if(++j==cur_names->end()) + { + if(mode==DYNAMIC && cur_names==&shared_names) + cur_names = &static_names; + else if(mode==STATIC && cur_names==&static_names) + cur_names = &shared_names; + else + break; + j = cur_names->begin(); + } } builder.get_logger().log("vfs", format("Library %s not found in %s", lib, i->str()));