diff options
Diffstat (limited to 'libbuild2/bin/utility.cxx')
-rw-r--r-- | libbuild2/bin/utility.cxx | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/libbuild2/bin/utility.cxx b/libbuild2/bin/utility.cxx index 6b0c4de..a03ea50 100644 --- a/libbuild2/bin/utility.cxx +++ b/libbuild2/bin/utility.cxx @@ -14,9 +14,6 @@ namespace build2 lorder link_order (const scope& bs, otype ot) { - // Initialize to suppress 'may be used uninitialized' warning produced - // by MinGW GCC 5.4.0. - // const char* var (nullptr); switch (ot) @@ -47,9 +44,11 @@ namespace build2 return lmembers {a, s}; } - const target* + const file* link_member (const libx& x, action a, linfo li, bool exist) { + const target* r; + if (x.is_a<libul> ()) { // For libul{} that is linked to an executable the member choice @@ -58,6 +57,11 @@ namespace build2 // prefer static over shared since it could be faster (but I am sure // someone will probably want this configurable). // + // Maybe we should use the bin.exe.lib order as a heuristics (i.e., + // the most likely utility library to be built is the one most likely + // to be linked)? Will need the variables rs-only, similar to + // bin.lib, which probably is a good thing. See also libul_rule. + // if (li.type == otype::e) { // Utility libraries are project-local which means the primarily @@ -72,7 +76,7 @@ namespace build2 // Called by the compile rule during execute. // - return x.ctx.phase == run_phase::match && !exist + r = x.ctx.phase == run_phase::match && !exist ? &search (x, tt, x.dir, x.out, x.name) : search_existing (x.ctx, tt, x.dir, x.out, x.name); } @@ -85,17 +89,21 @@ namespace build2 // Make sure group members are resolved. // group_view gv (resolve_members (a, l)); - assert (gv.members != nullptr); - pair<otype, bool> r ( + if (gv.members == nullptr) + fail << "group " << l << " has no members"; + + pair<otype, bool> p ( link_member (lmembers {l.a != nullptr, l.s != nullptr}, li.order)); - if (!r.second) - fail << (r.first == otype::s ? "shared" : "static") + if (!p.second) + fail << (p.first == otype::s ? "shared" : "static") << " variant of " << l << " is not available"; - return r.first == otype::s ? static_cast<const target*> (l.s) : l.a; + r = p.first == otype::s ? static_cast<const target*> (l.s) : l.a; } + + return static_cast<const file*> (r); } pattern_paths |