diff --git a/libbuild2-autoconf-tests/basics/testscript b/libbuild2-autoconf-tests/basics/testscript index 6c0c471..0e7612d 100644 --- a/libbuild2-autoconf-tests/basics/testscript +++ b/libbuild2-autoconf-tests/basics/testscript @@ -92,7 +92,7 @@ cat config.h >>EOO : mkdir build; ln -s ../../bootstrap.build ../../root.build build/; -cat <=config.h.in; +cat <=config.h.cmake; #define VERSION "@version@" #cmakedefine TRUE @@ -115,10 +115,8 @@ cat <=config.h.in; #cmakedefine zzz_TEST_DUMMY2_H EOI $* < #include +#include + #include using namespace std; @@ -34,22 +36,44 @@ namespace build2 recipe rule:: apply (action a, target& t) const { + recipe r (in::rule::apply (a, t)); + // Determine and cache the configuration file flavor. // flavor f (flavor::autoconf); + if (const string* s = cast_null (t["autoconf.flavor"])) { - if (*s == "cmake") - f = flavor::cmake; - else if (*s == "meson") - f = flavor::meson; + if (*s == "cmake") f = flavor::cmake; + else if (*s == "meson") f = flavor::meson; else if (*s != "autoconf") fail << "invalid configuration file flavor '" << *s << "'"; } + else + { + // If the in{} file extension is either .cmake or .meson, then + // use that as the flavor. + // + for (const target* pt: t.prerequisite_targets[a]) + { + if (pt != nullptr) + { + if (const auto* it = pt->is_a ()) + { + string e (it->path ().extension ()); + + if (e == "cmake") f = flavor::cmake; + else if (e == "meson") f = flavor::meson; + + break; + } + } + } + } t.data (match_data {f}); - return in::rule::apply (a, t); + return r; } void rule:: diff --git a/libbuild2-autoconf/libbuild2/autoconf/rule.hxx b/libbuild2-autoconf/libbuild2/autoconf/rule.hxx index 1318224..626e991 100644 --- a/libbuild2-autoconf/libbuild2/autoconf/rule.hxx +++ b/libbuild2-autoconf/libbuild2/autoconf/rule.hxx @@ -9,7 +9,7 @@ namespace build2 { namespace autoconf { - // Process a config.h.in file. + // Process a config.h.{in,cmake,meson} file. // // Note that to be usable as a drop-in replacement we make the default // substitution symbol '@' and the mode -- lax. The user, however, is