aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/c
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/c')
-rw-r--r--libbuild2/c/init.cxx59
-rw-r--r--libbuild2/c/init.hxx16
2 files changed, 57 insertions, 18 deletions
diff --git a/libbuild2/c/init.cxx b/libbuild2/c/init.cxx
index ebf0631..cb0469c 100644
--- a/libbuild2/c/init.cxx
+++ b/libbuild2/c/init.cxx
@@ -479,11 +479,11 @@ namespace build2
bool
as_cpp_init (scope& rs,
- scope& bs,
- const location& loc,
- bool,
- bool,
- module_init_extra&)
+ scope& bs,
+ const location& loc,
+ bool,
+ bool,
+ module_init_extra&)
{
tracer trace ("c::as_cpp_init");
l5 ([&]{trace << "for " << bs;});
@@ -513,17 +513,54 @@ namespace build2
return true;
}
+ bool
+ predefs_init (scope& rs,
+ scope& bs,
+ const location& loc,
+ bool,
+ bool,
+ module_init_extra&)
+ {
+ tracer trace ("c::predefs_init");
+ l5 ([&]{trace << "for " << bs;});
+
+ // We only support root loading (which means there can only be one).
+ //
+ if (rs != bs)
+ fail (loc) << "c.predefs module must be loaded in project root";
+
+ module* mod (rs.find_module<module> ("c"));
+
+ if (mod == nullptr)
+ fail (loc) << "c.predefs module must be loaded after c module";
+
+ // Register the c.predefs rule.
+ //
+ // Why invent a separate module instead of just always registering it in
+ // the c module? The reason is performance: this rule will be called for
+ // every C header.
+ //
+ cc::predefs_rule& r (*mod);
+
+ rs.insert_rule<h> (perform_update_id, r.rule_name, r);
+ rs.insert_rule<h> (perform_clean_id, r.rule_name, r);
+ rs.insert_rule<h> (configure_update_id, r.rule_name, r);
+
+ return true;
+ }
+
static const module_functions mod_functions[] =
{
// NOTE: don't forget to also update the documentation in init.hxx if
// changing anything here.
- {"c.guess", nullptr, guess_init},
- {"c.config", nullptr, config_init},
- {"c.objc", nullptr, objc_init},
- {"c.as-cpp", nullptr, as_cpp_init},
- {"c", nullptr, init},
- {nullptr, nullptr, nullptr}
+ {"c.guess", nullptr, guess_init},
+ {"c.config", nullptr, config_init},
+ {"c.objc", nullptr, objc_init},
+ {"c.as-cpp", nullptr, as_cpp_init},
+ {"c.predefs", nullptr, predefs_init},
+ {"c", nullptr, init},
+ {nullptr, nullptr, nullptr}
};
const module_functions*
diff --git a/libbuild2/c/init.hxx b/libbuild2/c/init.hxx
index c3126ea..713a78a 100644
--- a/libbuild2/c/init.hxx
+++ b/libbuild2/c/init.hxx
@@ -19,13 +19,15 @@ namespace build2
//
// Submodules:
//
- // `c.guess` -- registers and sets some variables.
- // `c.config` -- loads c.guess and sets more variables.
- // `c` -- loads c.config and registers target types and rules.
- // `c.objc` -- registers m{} target type and enables Objective-C
- // compilation. Must be loaded after c.
- // `c.as-cpp` -- registers S{} target type and enables Assembler with
- // C preprocessor compilation. Must be loaded after c.
+ // `c.guess` -- registers and sets some variables.
+ // `c.config` -- loads c.guess and sets more variables.
+ // `c` -- loads c.config and registers target types and rules.
+ // `c.objc` -- registers m{} target type and enables Objective-C
+ // compilation. Must be loaded after c.
+ // `c.as-cpp` -- registers S{} target type and enables Assembler with
+ // C preprocessor compilation. Must be loaded after c.
+ // `c.predefs` -- registers rule for generating a C header with
+ // predefined compiler macros. Must be loaded after c.
//
extern "C" LIBBUILD2_C_SYMEXPORT const module_functions*
build2_c_load ();