]> git.tdb.fi Git - builder.git/commitdiff
Redesign the library mode system
authorMikko Rasa <tdb@tdb.fi>
Sun, 15 Jul 2012 16:43:45 +0000 (19:43 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 15 Jul 2012 17:31:06 +0000 (20:31 +0300)
source/binary.cpp
source/component.cpp
source/gnulinker.cpp
source/misc.h
source/sourcepackage.cpp
source/virtualfilesystem.cpp

index aa26608d695e46620ecfc57ae8a8383c83c70134..6c915de9749de661620696e07904ab8193371b39 100644 (file)
@@ -30,7 +30,7 @@ void Binary::find_depends()
 
        const SourcePackage &spkg = component->get_package();
        LibMode libmode = spkg.get_library_mode();
-       if(dynamic_cast<SharedLibrary *>(this))
+       if(dynamic_cast<SharedLibrary *>(this) && libmode<DYNAMIC)
                libmode = DYNAMIC;
 
        list<const Component *> queue;
index 3c8749ecb3459defeff2e7fa734d5a8f3e8faebd..88fe71443bc2b4497c51a590a2a262b0fcbe6223 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(pkg.get_library_mode()<DYNAMIC)
        {
                for(PackageList::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
                {
index 13352870299778b8ba205092e3e742ed008be813..070bdcef745581b333947408248c6dfd184c5610 100644 (file)
@@ -121,8 +121,6 @@ Task *GnuLinker::Linker::run(const Target &target) const
                if(!shlib->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<StaticLibrary *>(tgt))
                        argv.push_back(stlib->get_path().str());
                else if(SharedLibrary *shlib = dynamic_cast<SharedLibrary *>(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);
 
index e3d4be849e12c139d18d90e909859d5fc51b5cd5..45cd396cc1b3dc788a578136ffaa4b5c55371cc3 100644 (file)
@@ -8,9 +8,10 @@
 
 enum LibMode
 {
-       ALL_STATIC,
-       LOCAL_STATIC,
-       DYNAMIC
+       FORCE_STATIC,
+       STATIC,
+       DYNAMIC,
+       FORCE_DYNAMIC
 };
 
 typedef std::list<std::string> StringList;
index 1de15ef86781ae2696fa114eb7b3c8c0d6e344ef..7c913806cdf21944aa9e17f44a3bdaaa5dbf1d0f 100644 (file)
@@ -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");
 }
index cccc16945f6c74db42750a0c80e4eaac32000bf7..1de66303711481b88c13e392622deb20ad589eec 100644 (file)
@@ -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<string> shared_names;
-       if(mode!=ALL_STATIC)
+       if(mode!=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)
                        shared_names.push_back(i->apply(lib));
        }
 
-       /* Static libraries are always considered, since sometimes shared versions
-       may not be available */
        list<string> static_names;
-       const list<Pattern> &static_patterns = arch.get_static_library_patterns();
-       for(list<Pattern>::const_iterator i=static_patterns.begin(); i!=static_patterns.end(); ++i)
-               static_names.push_back(i->apply(lib));
+       if(mode!=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)
+                       static_names.push_back(i->apply(lib));
+       }
 
        for(list<FS::Path>::const_iterator i=combined_path.begin(); i!=combined_path.end(); ++i)
        {
-               bool shared = true;
-               for(list<string>::const_iterator j=shared_names.begin(); j!=static_names.end(); )
+               const list<string> *cur_names = (mode>=DYNAMIC ? &shared_names : &static_names);
+               for(list<string>::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()));