From 8aeae026d112ff9811a424e31621c05682f4a72e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 18 Apr 2023 09:23:24 +0200 Subject: 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. --- libbuild2/c/init.cxx | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'libbuild2/c/init.cxx') 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 ("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 (); + + 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} }; -- cgit v1.1