From abb2336c34b94abc0508a00f07afdf85d7c78951 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 15 Jul 2012 20:18:15 +0300 Subject: [PATCH] Move library mode into BuildInfo --- source/binary.cpp | 6 +++--- source/buildinfo.cpp | 19 +++++++++++++++++++ source/buildinfo.h | 9 +++++++++ source/component.cpp | 2 +- source/gnulinker.cpp | 2 +- source/misc.h | 8 -------- source/sourcepackage.cpp | 16 ---------------- source/sourcepackage.h | 1 - source/virtualfilesystem.cpp | 14 +++++++------- source/virtualfilesystem.h | 3 ++- 10 files changed, 42 insertions(+), 38 deletions(-) diff --git a/source/binary.cpp b/source/binary.cpp index 6c915de..ed73169 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -29,9 +29,9 @@ void Binary::find_depends() return; const SourcePackage &spkg = component->get_package(); - LibMode libmode = spkg.get_library_mode(); - if(dynamic_cast(this) && libmodeget_build_info().libmode; + if(dynamic_cast(this) && libmode queue; list dep_libs; diff --git a/source/buildinfo.cpp b/source/buildinfo.cpp index a93c29d..4c4029e 100644 --- a/source/buildinfo.cpp +++ b/source/buildinfo.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "buildinfo.h" using namespace std; @@ -26,6 +27,7 @@ void unique(list &l) BuildInfo::BuildInfo(): + libmode(DYNAMIC), threads(false), debug(false), optimize(0), @@ -46,6 +48,7 @@ void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level) threads = bi.threads; if(level==LOCAL) { + libmode = bi.libmode; debug = bi.debug; optimize = bi.optimize; strip = bi.strip; @@ -91,6 +94,7 @@ BuildInfo::Loader::Loader(BuildInfo &bi): add("incpath", &Loader::incpath); add("libpath", &Loader::libpath); add("library", &Loader::library); + add("libmode", &BuildInfo::libmode); add("optimize", &BuildInfo::optimize); add("strip", &BuildInfo::strip); add("threads", &BuildInfo::threads); @@ -121,3 +125,18 @@ void BuildInfo::Loader::warning(const string &s) { obj.warnings.push_back(s); } + + +void operator>>(LexicalConverter &conv, BuildInfo::LibraryMode &libmode) +{ + if(conv.get()=="FORCE_STATIC") + libmode = BuildInfo::FORCE_STATIC; + else if(conv.get()=="STATIC") + libmode = BuildInfo::STATIC; + else if(conv.get()=="DYNAMIC") + libmode = BuildInfo::DYNAMIC; + else if(conv.get()=="FORCE_DYNAMIC") + libmode = BuildInfo::FORCE_DYNAMIC; + else + throw lexical_error(format("Conversion of '%s' to LibraryMode", conv.get())); +} diff --git a/source/buildinfo.h b/source/buildinfo.h index 144a16d..9805e0a 100644 --- a/source/buildinfo.h +++ b/source/buildinfo.h @@ -13,6 +13,14 @@ form. Allows combining with other BuildInfos to support package dependencies. class BuildInfo { public: + enum LibraryMode + { + FORCE_STATIC, //< Only accept static libraries + STATIC, //< Prefer static libraries but accept dynamic as well + DYNAMIC, //< Prefer dynamic libraries but accept static as well + FORCE_DYNAMIC //< Only accept dynamic libraries + }; + class Loader: public Msp::DataFile::ObjectLoader { public: @@ -40,6 +48,7 @@ public: PathList incpath; PathList libpath; WordList libs; + LibraryMode libmode; WordList warnings; bool threads; bool debug; diff --git a/source/component.cpp b/source/component.cpp index 88fe714..72cdf78 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() #include -enum LibMode -{ - FORCE_STATIC, - STATIC, - DYNAMIC, - FORCE_DYNAMIC -}; - typedef std::list StringList; typedef std::list PathList; typedef std::map StringMap; diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 7c91380..85f64a6 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -56,21 +56,6 @@ FS::Path SourcePackage::get_out_dir() const return source/arch.get_name()/detail; } -LibMode SourcePackage::get_library_mode() const -{ - const string &mode = config.get_option("staticlibs").value; - 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"); -} - string SourcePackage::expand_string(const string &str) const { string result = str; @@ -151,7 +136,6 @@ void SourcePackage::do_configure(const StringMap &opts, unsigned flag) void SourcePackage::init_config() { config.add_option("tempdir", "temp", "Directory for storing temporary files"); - config.add_option("staticlibs", "local", "Use static libraries"); for(FeatureList::iterator i=features.begin(); i!=features.end(); ++i) config.add_option("with_"+i->name, i->def_value, i->descr); diff --git a/source/sourcepackage.h b/source/sourcepackage.h index e5f6d9d..755bdfc 100644 --- a/source/sourcepackage.h +++ b/source/sourcepackage.h @@ -72,7 +72,6 @@ public: const BuildInfo &get_build_info() const { return build_info; } Builder &get_builder() const { return builder; } - LibMode get_library_mode() const; DependencyCache &get_deps_cache() const { return deps_cache; } std::string expand_string(const std::string &) const; private: diff --git a/source/virtualfilesystem.cpp b/source/virtualfilesystem.cpp index 1de6630..60867cf 100644 --- a/source/virtualfilesystem.cpp +++ b/source/virtualfilesystem.cpp @@ -66,7 +66,7 @@ FileTarget *VirtualFileSystem::find_header(const string &name, const SearchPath return 0; } -FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath &path, LibMode mode) +FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath &path, BuildInfo::LibraryMode mode) { const Tool &linker = builder.get_toolchain().get_tool("LINK"); const Tool::SearchPath &syspath = linker.get_system_path(); @@ -77,7 +77,7 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath const Architecture &arch = builder.get_current_arch(); list shared_names; - if(mode!=FORCE_STATIC) + if(mode!=BuildInfo::FORCE_STATIC) { const list &shared_patterns = arch.get_shared_library_patterns(); for(list::const_iterator i=shared_patterns.begin(); i!=shared_patterns.end(); ++i) @@ -85,7 +85,7 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath } list static_names; - if(mode!=FORCE_DYNAMIC) + if(mode!=BuildInfo::FORCE_DYNAMIC) { const list &static_patterns = arch.get_static_library_patterns(); for(list::const_iterator i=static_patterns.begin(); i!=static_patterns.end(); ++i) @@ -94,13 +94,13 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath for(list::const_iterator i=combined_path.begin(); i!=combined_path.end(); ++i) { - const list *cur_names = (mode>=DYNAMIC ? &shared_names : &static_names); + const list *cur_names = (mode>=BuildInfo::DYNAMIC ? &shared_names : &static_names); for(list::const_iterator j=cur_names->begin(); j!=cur_names->end(); ) { FS::Path filename = *i / *j; if(FileTarget *tgt = get_target(filename)) { - if(cur_names!=&shared_names || mode==DYNAMIC || !tgt->get_package()) + if(cur_names!=&shared_names || mode==BuildInfo::DYNAMIC) { builder.get_logger().log("vfs", format("Library %s (%s) found in %s as existing %s", lib, *j, i->str(), tgt->get_type())); return tgt; @@ -117,9 +117,9 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath if(++j==cur_names->end()) { - if(mode==DYNAMIC && cur_names==&shared_names) + if(mode==BuildInfo::DYNAMIC && cur_names==&shared_names) cur_names = &static_names; - else if(mode==STATIC && cur_names==&static_names) + else if(mode==BuildInfo::STATIC && cur_names==&static_names) cur_names = &shared_names; else break; diff --git a/source/virtualfilesystem.h b/source/virtualfilesystem.h index a2ce05c..045f9b5 100644 --- a/source/virtualfilesystem.h +++ b/source/virtualfilesystem.h @@ -4,6 +4,7 @@ #include #include #include +#include "buildinfo.h" class Builder; class FileTarget; @@ -45,7 +46,7 @@ public: used in linking with the library. If a file is found but no target is associated with it, a new package-less target of appropriate type is created. */ - FileTarget *find_library(const std::string &, const SearchPath &, LibMode); + FileTarget *find_library(const std::string &, const SearchPath &, BuildInfo::LibraryMode); /** Locates a binary. The normal search path for binaries is used (usually this means the PATH environment variable). If a file is found but no target -- 2.45.2