From 9dff5c62fe2b0814ab7fc943c3f527434d637b2f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 11 Jan 2016 10:08:25 +0200 Subject: Add support for cli's --output-{prefix,suffix} options --- build2/cli/rule.cxx | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/build2/cli/rule.cxx b/build2/cli/rule.cxx index 22358c0..5cf9390 100644 --- a/build2/cli/rule.cxx +++ b/build2/cli/rule.cxx @@ -24,6 +24,29 @@ namespace build2 { namespace cli { + // Figure out if name contains stem and, optionally, calculate prefix and + // suffix. + // + static bool + match_stem (const string& name, const string& stem, + string* prefix = nullptr, string* suffix = nullptr) + { + size_t p (name.find (stem)); + + if (p != string::npos) + { + if (prefix != nullptr) + prefix->assign (name, 0, p); + + if (suffix != nullptr) + suffix->assign (name, p + stem.size (), string::npos); + + return true; + } + + return false; + } + match_result compile:: match (action a, target& xt, const std::string&) const { @@ -42,9 +65,9 @@ namespace build2 { if (p.is_a ()) { - // Check that the stems match. + // Check that the stem match. // - if (t.name != p.name ()) + if (!match_stem (t.name, p.name ())) { level4 ([&]{trace << ".cli file stem '" << p.name () << "' " << "doesn't match target " << t;}); @@ -112,7 +135,7 @@ namespace build2 { // Check that the stems match. // - if (t.name == p.name ()) + if (match_stem (t.name, p.name ())) { if (g == nullptr) g = &targets.insert (t.dir, t.name, trace); @@ -230,6 +253,23 @@ namespace build2 cstrings args {cli.c_str ()}; + // See if we need to pass --output-{prefix,suffix} + // + string prefix, suffix; + match_stem (t.name, s->name, &prefix, &suffix); + + if (!prefix.empty ()) + { + args.push_back ("--output-prefix"); + args.push_back (prefix.c_str ()); + } + + if (!suffix.empty ()) + { + args.push_back ("--output-suffix"); + args.push_back (suffix.c_str ()); + } + // See if we need to pass any --?xx-suffix options. // append_extension (args, *t.h, "--hxx-suffix", "hxx"); -- cgit v1.1