From cafa730ce5e1b13135ccbdc0befa58d693302999 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 3 Sep 2018 10:18:23 +0200 Subject: Use (native) C and C++ compilers we were built with as defaults --- build/root.build | 5 +++++ build2/buildfile | 12 ++++++++++++ build2/c/init.cxx | 10 +++++++++- build2/cc/module.cxx | 19 ++++++++++++++----- build2/cxx/init.cxx | 10 +++++++++- 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 +#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 (rs["cc.id"]), - cast (rs["cc.pattern"])) - : path (x_default)); + path d; + + if (cc_loaded) + d = guess_default (x_lang, + cast (rs["cc.id"]), + cast (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 +#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, -- cgit v1.1