From af73b1603d851dcb2ce7ae84bd57df0c2f9a716d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 16 Jun 2020 09:43:59 +0200 Subject: Add $bin.link_member() function Given a linker output target type ("exe", "lib[as]", or "libu[eas]") return the target type of lib{} group member ("liba" or "libs") that will be picked when linking a lib{} group to this target type. --- libbuild2/bin/functions.cxx | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 libbuild2/bin/functions.cxx (limited to 'libbuild2/bin/functions.cxx') diff --git a/libbuild2/bin/functions.cxx b/libbuild2/bin/functions.cxx new file mode 100644 index 0000000..59fcdf2 --- /dev/null +++ b/libbuild2/bin/functions.cxx @@ -0,0 +1,68 @@ +// file : libbuild2/bin/functions.cxx -*- C++ -*- +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include + +namespace build2 +{ + namespace bin + { + void + functions (function_map& m) + { + function_family f (m, "bin"); + + // Given a linker output target type ("exe", "lib[as]", or "libu[eas]") + // and a lib{} target group, return the type of library member ("liba" + // or "libs") that will be picked when linking this library group to + // this target type. + // + // The lib{} target is only used to resolve the scope to lookup the + // bin.lib value on. As a result, it can be omitted in which case the + // function call scope is used (covers project-local lib{} targets). + // + // @@ TODO: support for target (note that if it's out of project, then + // it's imported, which means it might still be qualified.) + // + // @@ TODO: support utility libraries (see link_member()). + // + f[".link_member"] = [] (const scope* bs, names ns) + { + string t (convert (move (ns))); + + if (bs == nullptr) + fail << "bin.link_member() called out of scope"; + + const scope* rs (bs->root_scope ()); + + if (rs == nullptr) + fail << "bin.link_member() called out of root scope"; + + const target_type* tt (bs->find_target_type (t)); + + if (tt == nullptr) + fail << "unknown target type '" << t << "'"; + + otype ot (link_type (*tt).type); + + switch (ot) + { + case otype::e: + case otype::a: + case otype::s: + break; + default: + fail << "target type " << t << " is not linker output"; + } + + lorder lo (link_order (*bs, ot)); + lmembers lm (link_members (*rs)); + + return link_member (lm, lo).first == otype::s ? "libs" : "liba"; + }; + } + } +} -- cgit v1.1