Thread View: gmane.linux.kernel
2 messages
2 total messages
Started by "Budde, Marco"
Thu, 15 Sep 2005 14:35
RE: kbuild & C++
Author: "Budde, Marco"
Date: Thu, 15 Sep 2005 14:35
Date: Thu, 15 Sep 2005 14:35
59 lines
1433 bytes
1433 bytes
Hi Sam, >> How can I compile this code with kbuild? The C++ support >> (I have tested with 2.6.11) of kbuild seems to be incomplete / >> not working. > Since you did not send any sample code shall I assume this was not a > serious request? it is of course a serious request. At the moment we are using some additional rules for kbuild. They have worked for a previous project of our customer and I hope they will work for this project, too. ------------------------------------------------------------------- include $(SRC_ROOT)comps/Kbuild.includes EXTRA_CPPFLAGS += -fno-exceptions -fno-rtti \ $(INCLUDE_DIRS) EXTRA_CFLAGS += $(INCLUDE_DIRS) %.o: %.cpp FORCE $(call cmd,force_checksrc) $(call if_changed_rule,cc_o_cpp) quiet_cmd_cc_o_cpp = C++ $(quiet_modtag) $@ ifndef CONFIG_MODVERSIONS cmd_cc_o_cpp = $(CXX) $(cpp_flags) -c -o $@ $< else cmd_cc_o_cpp = $(CXX) $(cpp_flags) -c -o $(@D)/.tmp_$(@F) $< endif 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); \ $(cmd_modversions) \ scripts/basic/fixdep $(depfile) $@ '$(cmd_cc_o_cpp)' > $(@D)/.$(@F).tmp; \ rm -f $(depfile); \ mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd endef -------------------------------------------------------------------
Re: kbuild & C++
Author: Sam Ravnborg
Date: Sun, 18 Sep 2005 20:41
Date: Sun, 18 Sep 2005 20:41
137 lines
4831 bytes
4831 bytes
Hi Marco. > At the moment we are using some additional rules for kbuild. > They have worked for a previous project of our customer and I > hope they will work for this project, too. Following adds proper C++ support to kbuild. Only composite objects are supported, but for your project thats not an issue. Sample Kbuild file: obj-m := sam.o EXTRA_CXXFLAGS := -DDEBUG CXXFLAGS_file2.o := -DDEBUG2 sam-y := file1.o file2.o I hope this is useful for your project, but do not count on having this added to mainstream kernel. sparse is not used - I do not assume you want to add C++ support to sparse for now. Also module versioning is excluded. Mainly because I did not bother test it - it should be trivial to add. Sam diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -322,6 +322,7 @@ AS = $(CROSS_COMPILE)as LD = $(CROSS_COMPILE)ld CC = $(CROSS_COMPILE)gcc CPP = $(CC) -E +CXX = $(CROSS_COMPILE)g++ AR = $(CROSS_COMPILE)ar NM = $(CROSS_COMPILE)nm STRIP = $(CROSS_COMPILE)strip @@ -354,15 +355,18 @@ CFLAGS := -Wall -Wundef -Wstrict-proto -fno-strict-aliasing -fno-common \ -ffreestanding AFLAGS := -D__ASSEMBLY__ +CXXFLAGS := -Wall -Wundef -fno-strict-aliasing -fno-common \ + -fno-exceptions -fno-rtti export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION LOCALVERSION KERNELRELEASE \ - ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \ + ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC CXX\ CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \ HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS export CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE +export CXXFLAGS # When compiling out-of-tree modules, put MODVERDIR in the module # tree rather than in the kernel tree. The kernel tree might diff --git a/scripts/Makefile.build b/scripts/Makefile.build --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -187,13 +187,36 @@ define rule_cc_o_c mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd endef -# Built-in and composite module parts - %.o: %.c FORCE $(call cmd,force_checksrc) $(call if_changed_rule,cc_o_c) + +# C++ (.cpp) files +# The C++ file is compiled and updated dependency information is generated. +# (See cmd_cc_o_cxx + relevant part of rule_cc_o_cxx) + +# No support for module versioning for c++ (for now) +quiet_cmd_cc_o_cxx = C++ $(quiet_modtag) $@ + cmd_cc_o_cxx = $(CXX) $(cxx_flags) -c -o $@ $< + +define rule_cc_o_cxx + $(if $($(quiet)cmd_checksrc),echo ' $($(quiet)cmd_checksrc)';) \ + $(if $($(quiet)cmd_cc_o_cxx),\ + echo ' $(subst ','\'',$($(quiet)cmd_cc_o_cxx))';) \ + $(cmd_cc_o_cxx); \ + scripts/basic/fixdep $(depfile) $@ '$(subst ','\'',$(cmd_cc_o_cxx))' \ + > $(@D)/.$(@F).tmp; \ + rm -f $(depfile); \ + mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd +endef + +%.o: %.cpp FORCE + $(call if_changed_rule,cc_o_cxx) + +# Built-in and composite module parts # Single-part modules are special since we need to mark them in $(MODVERDIR) +# Also we do not support C++ single-file modules $(single-used-m): %.o: %.c FORCE $(call cmd,force_checksrc) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -87,7 +87,7 @@ modname_flags = $(if $(filter 1,$(words _c_flags = $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) _a_flags = $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o) _cpp_flags = $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS_$(@F)) - +_cxx_flags = $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(CXXFLAGS_$(@F)) # If building the kernel in a separate objtree expand all occurrences # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). @@ -95,6 +95,7 @@ ifeq ($(KBUILD_SRC),) __c_flags = $(_c_flags) __a_flags = $(_a_flags) __cpp_flags = $(_cpp_flags) +__cxx_flags = $(_cxx_flags) else # Prefix -I with $(srctree) if it is not an absolute path @@ -109,6 +110,7 @@ flags = $(foreach o,$($(1)),$(if $(filte __c_flags = $(call addtree,-I$(obj)) $(call flags,_c_flags) __a_flags = $(call flags,_a_flags) __cpp_flags = $(call flags,_cpp_flags) +__cxx_flags = $(call flags,_cpp_flags) endif c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \ @@ -120,6 +122,10 @@ a_flags = -Wp,-MD,$(depfile) $(NO cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(__cpp_flags) +cxx_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \ + $(__cxx_flags) $(modkern_cflags) \ + $(basename_flags) $(modname_flags) + ld_flags = $(LDFLAGS) $(EXTRA_LDFLAGS) # Finds the multi-part object the current object will be linked into
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads