From f103f86ec3247ff27e7cc23dfce5e426f385ed8c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 24 Apr 2015 16:55:55 +0200 Subject: Take one on library linking --- build/bin/module | 26 +++++++++++++++++++++++ build/bin/module.cxx | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ build/bin/rule.cxx | 26 ++++++----------------- build/bin/target.cxx | 7 +++++++ 4 files changed, 97 insertions(+), 20 deletions(-) create mode 100644 build/bin/module create mode 100644 build/bin/module.cxx (limited to 'build/bin') diff --git a/build/bin/module b/build/bin/module new file mode 100644 index 0000000..f2d9502 --- /dev/null +++ b/build/bin/module @@ -0,0 +1,26 @@ +// file : build/bin/module -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef BUILD_BIN_MODULE +#define BUILD_BIN_MODULE + +#include +#include + +namespace build +{ + namespace bin + { + void + init (scope&, scope&, const location&); + + // Init the 'lib' part of the module because a lib{} target + // has been created in the specified directory. + // + void + init_lib (const dir_path&); + } +} + +#endif // BUILD_BIN_MODULE diff --git a/build/bin/module.cxx b/build/bin/module.cxx new file mode 100644 index 0000000..89ea9fe --- /dev/null +++ b/build/bin/module.cxx @@ -0,0 +1,58 @@ +// file : build/bin/module.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include + +#include +#include +#include + +#include + +using namespace std; + +namespace build +{ + namespace bin + { + void + init (scope& root, scope& base, const location& l) + { + //@@ TODO: avoid multiple inits (generally, for modules). + // + tracer trace ("bin::init"); + + //@@ Should it be this way? + // + if (&root != &base) + fail (l) << "bin module must be initialized in project root scope"; + + //@@ TODO: need to register target types, rules here instead of main(). + + const dir_path& out_root (root.path ()); + level4 ([&]{trace << "for " << out_root;}); + + // Configure. + // + } + + void + init_lib (const dir_path& d) + { + scope* root (scopes.find (d).root_scope ()); + + if (root == nullptr) + return; + + // config.bin.lib + // + { + auto v (root->vars.assign ("bin.lib")); + + if (!v) + v = config::required (*root, "config.bin.lib", "shared").first; + } + } + } +} diff --git a/build/bin/rule.cxx b/build/bin/rule.cxx index 1b887bf..d84af25 100644 --- a/build/bin/rule.cxx +++ b/build/bin/rule.cxx @@ -9,8 +9,6 @@ #include #include -#include - #include using namespace std; @@ -47,28 +45,16 @@ namespace build { lib& t (static_cast (xt)); - // Configure. - // - // The logic is as follows: if this library somehow knowns what - // it wants to be (i.e., the bin.lib is defined), then don't - // bother configuring the project-wide value. + // Get the library type to build. If not set for a target, this + // should be configured at the project scope by init_lib(). // - const string* type (nullptr); - - if (auto v = t["bin.lib"]) - type = &v.as (); - else - { - scope& root (*t.root_scope ()); - type = &config::required (root, "config.bin.lib", "shared").first; - root.assign ("bin.lib") = *type; - } + const string& type (t["bin.lib"].as ()); - bool ar (*type == "static" || *type == "both"); - bool so (*type == "shared" || *type == "both"); + bool ar (type == "static" || type == "both"); + bool so (type == "shared" || type == "both"); if (!ar && !so) - fail << "unknown library type: " << *type << + fail << "unknown library type: " << type << info << "'static', 'shared', or 'both' expected"; if (ar) diff --git a/build/bin/target.cxx b/build/bin/target.cxx index 1849533..ca198d7d 100644 --- a/build/bin/target.cxx +++ b/build/bin/target.cxx @@ -4,6 +4,8 @@ #include +#include + using namespace std; namespace build @@ -131,6 +133,11 @@ namespace build static target* lib_factory (dir_path d, string n, const string* e) { + // If there is a target of type lib{} in this project, then + // initialized the lib part of the module. + // + init_lib (d); + liba* a (targets.find (d, n)); libso* so (targets.find (d, n)); lib* l (new lib (move (d), move (n), e)); -- cgit v1.1