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)
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)
{
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);
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;
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()));