From: Sam Ravnborg <sam@ravnborg.org>
To: "Budde, Marco" <budde@telos.de>
Cc: linux-kernel@vger.kernel.org
Subject: Re: kbuild & C++
Date: Sun, 18 Sep 2005 20:41:07 +0200 [thread overview]
Message-ID: <20050918184107.GA7771@mars.ravnborg.org> (raw)
In-Reply-To: <809C13DD6142E74ABE20C65B11A2439802094E@www.telos.de>
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
next prev parent reply other threads:[~2005-09-18 18:40 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-15 12:35 Budde, Marco
2005-09-18 18:41 ` Sam Ravnborg [this message]
-- strict thread matches above, loose matches on Subject: below --
2005-09-07 12:04 Budde, Marco
2005-09-07 12:58 ` Bernd Petrovitsch
2005-09-07 13:15 ` Nick Piggin
[not found] <4JJOt-77X-9@gated-at.bofh.it>
2005-09-07 12:02 ` Bodo Eggert
2005-09-07 10:17 Budde, Marco
2005-09-07 18:52 ` Lee Revell
2005-09-07 9:13 Budde, Marco
2005-09-07 9:57 ` Valdis.Kletnieks
2005-09-07 10:45 ` Esben Nielsen
2005-09-07 10:00 ` Bernd Petrovitsch
2005-09-06 11:23 Budde, Marco
2005-09-06 11:30 ` Bernd Petrovitsch
2005-09-06 21:08 ` Chris Frey
2005-09-07 6:39 ` Bernd Petrovitsch
2005-09-06 11:38 ` linux-os (Dick Johnson)
2005-09-06 21:20 ` Jesper Juhl
2005-09-06 22:20 ` Esben Nielsen
2005-09-06 22:22 ` Randy.Dunlap
2005-09-06 22:32 ` Jesper Juhl
2005-09-07 2:33 ` Valdis.Kletnieks
2005-09-07 9:21 ` Esben Nielsen
2005-09-07 10:11 ` Valdis.Kletnieks
2005-09-07 10:58 ` Esben Nielsen
2005-09-07 11:44 ` Bernd Petrovitsch
2005-09-06 21:41 ` Sam Ravnborg
2005-09-10 12:29 ` Sam Ravnborg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050918184107.GA7771@mars.ravnborg.org \
--to=sam@ravnborg.org \
--cc=budde@telos.de \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome