From 9fa5f73d00905568e8979d0c93ec4a8f645c81d5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 9 Aug 2016 11:31:53 +0200 Subject: Implement support for C compilation We now have two new modules: cc (c-common) and c. --- build2/cc/utility.cxx | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 build2/cc/utility.cxx (limited to 'build2/cc/utility.cxx') diff --git a/build2/cc/utility.cxx b/build2/cc/utility.cxx new file mode 100644 index 0000000..773ba8f --- /dev/null +++ b/build2/cc/utility.cxx @@ -0,0 +1,115 @@ +// file : build2/cc/utility.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include +#include // search() + +#include + +using namespace std; + +namespace build2 +{ + namespace cc + { + using namespace bin; + + lorder + link_order (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) + { + case otype::e: var = "bin.exe.lib"; break; + case otype::a: var = "bin.liba.lib"; break; + case otype::s: var = "bin.libs.lib"; break; + } + + const auto& v (cast (bs[var])); + return v[0] == "shared" + ? v.size () > 1 && v[1] == "static" ? lorder::s_a : lorder::s + : v.size () > 1 && v[1] == "shared" ? lorder::a_s : lorder::a; + } + + target& + link_member (bin::lib& l, lorder lo) + { + bool ls (true); + const string& at (cast (l["bin.lib"])); // Available members. + + switch (lo) + { + case lorder::a: + case lorder::a_s: + ls = false; // Fall through. + case lorder::s: + case lorder::s_a: + { + if (ls ? at == "static" : at == "shared") + { + if (lo == lorder::a_s || lo == lorder::s_a) + ls = !ls; + else + fail << (ls ? "shared" : "static") << " variant of " << l + << " is not available"; + } + } + } + + target* r (ls ? static_cast (l.s) : l.a); + + if (r == nullptr) + r = &search (ls ? libs::static_type : liba::static_type, + prerequisite_key {nullptr, l.key (), nullptr}); + + return *r; + } + + void + append_lib_options (cstrings& args, target& l, lorder lo, + const variable& cv, + const variable& xv) + { + using namespace bin; + + for (target* t: l.prerequisite_targets) + { + if (lib* l = t->is_a ()) + t = &link_member (*l, lo); // Pick one of the members. + + if (t->is_a () || t->is_a ()) + append_lib_options (args, *t, lo, cv, xv); + } + + append_options (args, l, cv); + append_options (args, l, xv); + } + + void + hash_lib_options (sha256& csum, target& l, lorder lo, + const variable& cv, + const variable& xv) + { + using namespace bin; + + for (target* t: l.prerequisite_targets) + { + if (lib* l = t->is_a ()) + t = &link_member (*l, lo); // Pick one of the members. + + if (t->is_a () || t->is_a ()) + hash_lib_options (csum, *t, lo, cv, xv); + } + + hash_options (csum, l, cv); + hash_options (csum, l, xv); + } + } +} -- cgit v1.1