]> git.tdb.fi Git - builder.git/commitdiff
Move library mode into BuildInfo
authorMikko Rasa <tdb@tdb.fi>
Sun, 15 Jul 2012 17:18:15 +0000 (20:18 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 15 Jul 2012 17:31:43 +0000 (20:31 +0300)
source/binary.cpp
source/buildinfo.cpp
source/buildinfo.h
source/component.cpp
source/gnulinker.cpp
source/misc.h
source/sourcepackage.cpp
source/sourcepackage.h
source/virtualfilesystem.cpp
source/virtualfilesystem.h

index 6c915de9749de661620696e07904ab8193371b39..ed7316950f00b84dabae08845bdeb758bd03fd03 100644 (file)
@@ -29,9 +29,9 @@ void Binary::find_depends()
                return;
 
        const SourcePackage &spkg = component->get_package();
-       LibMode libmode = spkg.get_library_mode();
-       if(dynamic_cast<SharedLibrary *>(this) && libmode<DYNAMIC)
-               libmode = DYNAMIC;
+       BuildInfo::LibraryMode libmode = component->get_build_info().libmode;
+       if(dynamic_cast<SharedLibrary *>(this) && libmode<BuildInfo::DYNAMIC)
+               libmode = BuildInfo::DYNAMIC;
 
        list<const Component *> queue;
        list<Target *> dep_libs;
index a93c29df632202b878ede76dd1f2d9ba4c1b36f5..4c4029ea24f757d97ccc897c4ee73dc124f9349b 100644 (file)
@@ -1,5 +1,6 @@
 #include <algorithm>
 #include <set>
+#include <msp/strings/format.h>
 #include "buildinfo.h"
 
 using namespace std;
@@ -26,6 +27,7 @@ void unique(list<T> &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()));
+}
index 144a16dabb0e1e3215290745566b827bb63b220e..9805e0a2ec0aa5d1c6f140d775e1c68019758225 100644 (file)
@@ -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<BuildInfo>
        {
        public:
@@ -40,6 +48,7 @@ public:
        PathList incpath;
        PathList libpath;
        WordList libs;
+       LibraryMode libmode;
        WordList warnings;
        bool threads;
        bool debug;
index 88fe71443bc2b4497c51a590a2a262b0fcbe6223..72cdf7833facb134303aa90a2e25352e8b8dc7f5 100644 (file)
@@ -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(build_info.libmode<BuildInfo::DYNAMIC)
        {
                for(PackageList::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
                {
index 070bdcef745581b333947408248c6dfd184c5610..4276397b23c863b5ead37a90e5ca1b64af7cce84 100644 (file)
@@ -139,7 +139,7 @@ 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);
+       bool static_link_ok = (binfo.libmode<=BuildInfo::STATIC);
 
        const Target::Dependencies &depends = target.get_depends();
        for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
index 45cd396cc1b3dc788a578136ffaa4b5c55371cc3..45c6636da83c057ef777d6e81333e828017a898f 100644 (file)
@@ -6,14 +6,6 @@
 #include <string>
 #include <msp/fs/path.h>
 
-enum LibMode
-{
-       FORCE_STATIC,
-       STATIC,
-       DYNAMIC,
-       FORCE_DYNAMIC
-};
-
 typedef std::list<std::string> StringList;
 typedef std::list<Msp::FS::Path> PathList;
 typedef std::map<std::string, std::string> StringMap;
index 7c913806cdf21944aa9e17f44a3bdaaa5dbf1d0f..85f64a673ea7bd0864804544abf182a06278ae9a 100644 (file)
@@ -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);
index e5f6d9d460433a718bf2eca654ff11a92b9e244c..755bdfcb024a57aab643eb6687aab43a7ae5e207 100644 (file)
@@ -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:
index 1de66303711481b88c13e392622deb20ad589eec..60867cf7a4feb3dda5638ee35c9b7a2a956e6d88 100644 (file)
@@ -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<string> shared_names;
-       if(mode!=FORCE_STATIC)
+       if(mode!=BuildInfo::FORCE_STATIC)
        {
                const list<Pattern> &shared_patterns = arch.get_shared_library_patterns();
                for(list<Pattern>::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<string> static_names;
-       if(mode!=FORCE_DYNAMIC)
+       if(mode!=BuildInfo::FORCE_DYNAMIC)
        {
                const list<Pattern> &static_patterns = arch.get_static_library_patterns();
                for(list<Pattern>::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<FS::Path>::const_iterator i=combined_path.begin(); i!=combined_path.end(); ++i)
        {
-               const list<string> *cur_names = (mode>=DYNAMIC ? &shared_names : &static_names);
+               const list<string> *cur_names = (mode>=BuildInfo::DYNAMIC ? &shared_names : &static_names);
                for(list<string>::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;
index a2ce05c4dad880c7f1bfea7c790a4d72c67a3256..045f9b5057bcdb2b3514736147f83c015d97afd5 100644 (file)
@@ -4,6 +4,7 @@
 #include <list>
 #include <map>
 #include <msp/fs/path.h>
+#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