aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-09-03 10:18:23 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-09-03 10:18:23 +0200
commitcafa730ce5e1b13135ccbdc0befa58d693302999 (patch)
treed6d63760881b6813a3dee9434cdc1b1c42ae4d92
parent1bf439f7918f2c6f8fa07db3abb53722156945c7 (diff)
Use (native) C and C++ compilers we were built with as defaults
-rw-r--r--build/root.build5
-rw-r--r--build2/buildfile12
-rw-r--r--build2/c/init.cxx10
-rw-r--r--build2/cc/module.cxx19
-rw-r--r--build2/cxx/init.cxx10
5 files changed, 49 insertions, 7 deletions
diff --git a/build/root.build b/build/root.build
index f5ce7cb..f6be793 100644
--- a/build/root.build
+++ b/build/root.build
@@ -13,6 +13,11 @@ cxx{*}: extension = cxx
cxx.poptions =+ "-I$out_root" "-I$src_root"
+# While we don't have any C sources to compile, we need to get the C compiler
+# path to use as native/default.
+#
+using c
+
# 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 we need to explicitly spell out individual
diff --git a/build2/buildfile b/build2/buildfile
index 396fcf4..1e3b447 100644
--- a/build2/buildfile
+++ b/build2/buildfile
@@ -17,6 +17,18 @@ hxx{version}: in{version} $src_root/manifest
#
obj{b context}: cxx.poptions += -DBUILD2_HOST_TRIPLET=\"$cxx.target\"
+# Pass native C and C++ compiler paths (not forgetting to escape backslashes
+# on Windows). These are used as defaults for BUILD2_DEFAULT_*.
+#
+if ($cxx.target == $build.host)
+{
+ c/obj{init}: cxx.poptions += \
+ -DBUILD2_NATIVE_C=\"$regex.replace($recall($c.path), '\\', '\\\\')\"
+
+ cxx/obj{init}: cxx.poptions += \
+ -DBUILD2_NATIVE_CXX=\"$regex.replace($recall($cxx.path), '\\', '\\\\')\"
+}
+
if ($cxx.target.class != "windows")
cxx.libs += -lpthread
else
diff --git a/build2/c/init.cxx b/build2/c/init.cxx
index 63043d7..56b3f02 100644
--- a/build2/c/init.cxx
+++ b/build2/c/init.cxx
@@ -13,6 +13,14 @@
#include <build2/c/target.hxx>
+#ifndef BUILD2_DEFAULT_C
+# ifdef BUILD2_NATIVE_C
+# define BUILD2_DEFAULT_C BUILD2_NATIVE_C
+# else
+# define BUILD2_DEFAULT_C ""
+# endif
+#endif
+
using namespace std;
using namespace butl;
@@ -145,7 +153,7 @@ namespace build2
"c",
"c",
- "gcc",
+ BUILD2_DEFAULT_C,
".i",
hinters,
diff --git a/build2/cc/module.cxx b/build2/cc/module.cxx
index 858a2fd..e9d5c09 100644
--- a/build2/cc/module.cxx
+++ b/build2/cc/module.cxx
@@ -87,11 +87,20 @@ namespace build2
// (optional) pattern to guess an appropriate default (e.g., for {gcc,
// *-4.9} we will get g++-4.9).
//
- path d (cc_loaded
- ? guess_default (x_lang,
- cast<string> (rs["cc.id"]),
- cast<string> (rs["cc.pattern"]))
- : path (x_default));
+ path d;
+
+ if (cc_loaded)
+ d = guess_default (x_lang,
+ cast<string> (rs["cc.id"]),
+ cast<string> (rs["cc.pattern"]));
+ else
+ {
+ d = path (x_default);
+
+ if (d.empty ())
+ fail << "not built with default " << x_lang << " compiler" <<
+ info << "use config." << x << " to specify";
+ }
// If this value was hinted, save it as commented out so that if the
// user changes the source of the pattern, this one will get updated
diff --git a/build2/cxx/init.cxx b/build2/cxx/init.cxx
index 1f5eba3..2fa5dac 100644
--- a/build2/cxx/init.cxx
+++ b/build2/cxx/init.cxx
@@ -13,6 +13,14 @@
#include <build2/cxx/target.hxx>
+#ifndef BUILD2_DEFAULT_CXX
+# ifdef BUILD2_NATIVE_CXX
+# define BUILD2_DEFAULT_CXX BUILD2_NATIVE_CXX
+# else
+# define BUILD2_DEFAULT_CXX ""
+# endif
+#endif
+
using namespace std;
using namespace butl;
@@ -351,7 +359,7 @@ namespace build2
"cxx",
"c++",
- "g++",
+ BUILD2_DEFAULT_CXX,
".ii",
hinters,