aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/c/init.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-04-18 09:23:24 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-04-18 09:23:24 +0200
commit8aeae026d112ff9811a424e31621c05682f4a72e (patch)
tree9dc5c736fb07fb6cafe3a08a7e999b9c084edc18 /libbuild2/c/init.cxx
parenta1a01cbce316c5da7aa94e6b6a71eae98bffed1c (diff)
Add support for Assembler with C Preprocessor (.S) compilation
Specifically, the c module now provides the c.as-cpp submodules which can be loaded in order to register the S{} target type and enable Assembler with C Preprocessor compilation in the c compile rule. For details, refer to "Assembler with C Preprocessor Compilation" in the manual.
Diffstat (limited to 'libbuild2/c/init.cxx')
-rw-r--r--libbuild2/c/init.cxx41
1 files changed, 41 insertions, 0 deletions
diff --git a/libbuild2/c/init.cxx b/libbuild2/c/init.cxx
index 2dbd534..0092b81 100644
--- a/libbuild2/c/init.cxx
+++ b/libbuild2/c/init.cxx
@@ -324,11 +324,15 @@ namespace build2
nullptr
};
+ // Note that we include S{} here because .S files can include each other.
+ // (And maybe from inline assember instrcutions?)
+ //
static const target_type* const inc[] =
{
&h::static_type,
&c::static_type,
&m::static_type,
+ &S::static_type,
nullptr
};
@@ -446,6 +450,42 @@ namespace build2
return true;
}
+ bool
+ as_cpp_init (scope& rs,
+ scope& bs,
+ const location& loc,
+ bool,
+ bool,
+ module_init_extra&)
+ {
+ tracer trace ("c::as_cpp_init");
+ l5 ([&]{trace << "for " << bs;});
+
+ // We only support root loading (which means there can only be one).
+ //
+ if (rs != bs)
+ fail (loc) << "c.as-cpp module must be loaded in project root";
+
+ module* mod (rs.find_module<module> ("c"));
+
+ if (mod == nullptr)
+ fail (loc) << "c.as-cpp module must be loaded after c module";
+
+ // Register the target type and "enable" it in the module.
+ //
+ // Note that we must register the target type regardless of whether the
+ // C compiler is capable of compiling Assember with C preprocessor. But
+ // we enable only if it is.
+ //
+ rs.insert_target_type<S> ();
+
+ if (mod->ctype == compiler_type::gcc ||
+ mod->ctype == compiler_type::clang)
+ mod->x_asp = &S::static_type;
+
+ return true;
+ }
+
static const module_functions mod_functions[] =
{
// NOTE: don't forget to also update the documentation in init.hxx if
@@ -455,6 +495,7 @@ namespace build2
{"c.config", nullptr, config_init},
{"c", nullptr, init},
{"c.objc", nullptr, objc_init},
+ {"c.as-cpp", nullptr, as_cpp_init},
{nullptr, nullptr, nullptr}
};