aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-03-10 15:26:01 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-03-10 15:26:01 +0200
commita5592d2ddbce898766dd103ae9a4fe6887ab5209 (patch)
tree32859b84154cf6afc60deb6c5774361e10bc7205
parentd4baa98d4e4c290a5afbda4228e12b2bc7b3866e (diff)
Set build.host.* variables
-rw-r--r--build2/buildfile4
-rw-r--r--build2/context.cxx53
-rw-r--r--build2/cxx/module.cxx2
3 files changed, 51 insertions, 8 deletions
diff --git a/build2/buildfile b/build2/buildfile
index 9f2f19e..6c5f773 100644
--- a/build2/buildfile
+++ b/build2/buildfile
@@ -60,6 +60,10 @@ install/{hxx }{ utility } \
test/{hxx cxx}{ rule } \
$libs
+# Pass our compiler target to be used as build2 host.
+#
+obj{context}: cxx.poptions += -DBUILD2_HOST_TRIPLET=\"$cxx.target\"
+
# Load the cli module but only if it's available. This way a distribution
# that includes pre-generated files can be built without installing cli.
# This is also the reason why above we explicitly spelled out individual
diff --git a/build2/context.cxx b/build2/context.cxx
index 2abe2f0..5b2b761 100644
--- a/build2/context.cxx
+++ b/build2/context.cxx
@@ -4,6 +4,8 @@
#include <build2/context>
+#include <butl/triplet>
+
#include <build2/scope>
#include <build2/target>
#include <build2/rule>
@@ -29,6 +31,8 @@ namespace build2
void
reset ()
{
+ tracer trace ("reset");
+
extension_pool.clear ();
project_name_pool.clear ();
@@ -57,9 +61,6 @@ namespace build2
{
auto& v (var_pool);
- v.find ("build.work", dir_path_type);
- v.find ("build.home", dir_path_type);
-
v.find ("src_root", dir_path_type);
v.find ("out_root", dir_path_type);
v.find ("src_base", dir_path_type);
@@ -82,13 +83,51 @@ namespace build2
global_scope = scopes.insert (
dir_path ("/"), nullptr, true, false)->second;
- global_scope->assign ("build.work") = work;
- global_scope->assign ("build.home") = home;
+ scope& gs (*global_scope);
+
+ gs.assign ("build.work", dir_path_type) = work;
+ gs.assign ("build.home", dir_path_type) = home;
+
+ // Enter the host information. Rather than jumping through hoops like
+ // config.guess, for now we are just going to use the compiler target we
+ // were built with. While it is not as precise (for example, a binary
+ // built for i686 might be running on x86_64), it is good enough of an
+ // approximation/fallback since most of the time we are interested in just
+ // the target class (e.g., linux, windows, macosx).
+ //
+#ifndef BUILD2_HOST_TRIPLET
+#error BUILD2_HOST_TRIPLET is not defined
+#endif
+ try
+ {
+ string canon;
+ triplet t (BUILD2_HOST_TRIPLET, canon);
+
+ l5 ([&]{trace << "canonical host: '" << canon << "'; "
+ << "class: " << t.class_;});
+
+ // Enter as build.host.{cpu,vendor,system,version,class}.
+ //
+ gs.assign ("build.host", string_type) = move (canon);
+ gs.assign ("build.host.cpu", string_type) = move (t.cpu);
+ gs.assign ("build.host.vendor", string_type) = move (t.vendor);
+ gs.assign ("build.host.system", string_type) = move (t.system);
+ gs.assign ("build.host.version", string_type) = move (t.version);
+ gs.assign ("build.host.class", string_type) = move (t.class_);
+ }
+ catch (const invalid_argument& e)
+ {
+ // This is where we could suggest that the user specifies --config-guess
+ // to help us out.
+ //
+ fail << "unable to parse build host '" << BUILD2_HOST_TRIPLET << "': "
+ << e.what ();
+ }
// Register builtin target types.
//
{
- target_type_map& t (global_scope->target_types);
+ target_type_map& t (gs.target_types);
t.insert<file> ();
t.insert<alias> ();
@@ -102,7 +141,7 @@ namespace build2
// Register builtin rules.
//
{
- rule_map& r (global_scope->rules);
+ rule_map& r (gs.rules);
r.insert<alias> (perform_id, 0, "alias", alias_rule::instance);
diff --git a/build2/cxx/module.cxx b/build2/cxx/module.cxx
index 364b801..9ebcc52 100644
--- a/build2/cxx/module.cxx
+++ b/build2/cxx/module.cxx
@@ -221,7 +221,7 @@ namespace build2
l5 ([&]{trace << "canonical target: '" << canon << "'; "
<< "class: " << t.class_;});
- // Enter as cxx.target.{cpu,vendor,system,version}.
+ // Enter as cxx.target.{cpu,vendor,system,version,class}.
//
r.assign ("cxx.target", string_type) = move (canon);
r.assign ("cxx.target.cpu", string_type) = move (t.cpu);