Re: Compiling C++ kernel module + Makefile

From: Sam Ravnborg
Date: Fri Jan 16 2004 - 17:41:07 EST


> Does anyone can ideas about how to change the kernel
> makefile to compile the C++ files the same way as C
> files ?

I assume you know the general opinion on C++ in the kernel - even in a module.
I just did a quick untested hack - try this. It assumes extension .cc for
c++ files.
You also need to define CXX in top level makefile and export it.
This patch will _not_ be pushed into mainline.

Sam

===== scripts/Makefile.build 1.41 vs edited =====
--- 1.41/scripts/Makefile.build Sun Oct 5 08:50:46 2003
+++ edited/scripts/Makefile.build Fri Jan 16 23:39:26 2004
@@ -174,6 +174,23 @@
%.o: %.c FORCE
$(call if_changed_rule,cc_o_c)

+# C++ support
+ cmd_cc_o_cpp = $(CXX) $(c_flags) -c -o $@ $<
+quiet_cmd_cc_o_cpp = C++ $@
+
+define rule_cc_o_cpp
+ $(if $($(quiet)cmd_checksrc),echo ' $($(quiet)cmd_checksrc)';) \
+ $(cmd_checksrc) \
+ $(if $($(quiet)cmd_cc_o_cpp),echo ' $($(quiet)cmd_cc_o_cpp)';) \
+ $(cmd_cc_o_cpp); \
+ scripts/fixdep $(depfile) $@ '$(cmd_cc_o_cpp)' > $(@D)/.$(@F).tmp; \
+ rm -f $(depfile); \
+ mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd
+endef
+
+%.o: %.cc FORCE
+ $(call if_changed_rule,cc_o_cpp)
+
# Single-part modules are special since we need to mark them in $(MODVERDIR)

$(single-used-m): %.o: %.c FORCE
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/