DPDK patches and discussions
 help / color / mirror / Atom feed
From: Takuya ASADA <syuu@cloudius-systems.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [RFC PATCH 1/7] mk: support compiling C++ code
Date: Fri, 13 Mar 2015 06:05:42 +0900	[thread overview]
Message-ID: <1426194348-4406-2-git-send-email-syuu@cloudius-systems.com> (raw)
In-Reply-To: <1426194348-4406-1-git-send-email-syuu@cloudius-systems.com>

Since OSv is written in C++, we need to write OSv EAL in C++.
To do so, we need to compile .cc files by $(CXX).

This patch does not contain diff for clang and icc, but OSv EAL does not supported these toolchain, this is enough for now.

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
---
 mk/internal/rte.compile-pre.mk | 41 ++++++++++++++++++++++++++++++++++++++---
 mk/target/generic/rte.vars.mk  |  4 ++++
 mk/toolchain/gcc/rte.vars.mk   |  5 ++++-
 3 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/mk/internal/rte.compile-pre.mk b/mk/internal/rte.compile-pre.mk
index b9bff4a..142f996 100644
--- a/mk/internal/rte.compile-pre.mk
+++ b/mk/internal/rte.compile-pre.mk
@@ -37,7 +37,7 @@ SRCS-all := $(SRCS-y) $(SRCS-n) $(SRCS-)
 
 # convert source to obj file
 src2obj = $(strip $(patsubst %.c,%.o,\
-	$(patsubst %.S,%_s.o,$(1))))
+	$(patsubst %.S,%_s.o,$(patsubst %.cc,%.o,$(1)))))
 
 # add a dot in front of the file name
 dotfile = $(strip $(foreach f,$(1),\
@@ -46,12 +46,12 @@ dotfile = $(strip $(foreach f,$(1),\
 # convert source/obj files into dot-dep filename (does not
 # include .S files)
 src2dep = $(strip $(call dotfile,$(patsubst %.c,%.o.d, \
-		$(patsubst %.S,,$(1)))))
+		$(patsubst %.S,,$(patsubst %.cc,%.o.d,$(1))))))
 obj2dep = $(strip $(call dotfile,$(patsubst %.o,%.o.d,$(1))))
 
 # convert source/obj files into dot-cmd filename
 src2cmd = $(strip $(call dotfile,$(patsubst %.c,%.o.cmd, \
-		$(patsubst %.S,%_s.o.cmd,$(1)))))
+		$(patsubst %.S,%_s.o.cmd,$(patsubst %.cc,%.o.cmd,$(1))))))
 obj2cmd = $(strip $(call dotfile,$(patsubst %.o,%.o.cmd,$(1))))
 
 OBJS-y := $(call src2obj,$(SRCS-y))
@@ -78,11 +78,19 @@ C_TO_O = $(HOSTCC) -Wp,-MD,$(call obj2dep,$(@)).tmp $(HOST_CFLAGS) \
 	$(CFLAGS_$(@)) $(HOST_EXTRA_CFLAGS) -o $@ -c $<
 C_TO_O_STR = $(subst ','\'',$(C_TO_O)) #'# fix syntax highlight
 C_TO_O_DISP = $(if $(V),"$(C_TO_O_STR)","  HOSTCC $(@)")
+CXX_TO_O = $(HOSTCXX) -Wp,-MD,$(call obj2dep,$(@)).tmp $(HOST_CXXFLAGS) \
+	$(CXXFLAGS_$(@)) $(HOST_EXTRA_CXXFLAGS) -o $@ -c $<
+CXX_TO_O_STR = $(subst ','\'',$(CXX_TO_O)) #'# fix syntax highlight
+CXX_TO_O_DISP = $(if $(V),"$(CXX_TO_O_STR)","  HOSTCXX $(@)")
 else
 C_TO_O = $(CC) -Wp,-MD,$(call obj2dep,$(@)).tmp $(CFLAGS) \
 	$(CFLAGS_$(@)) $(EXTRA_CFLAGS) -o $@ -c $<
 C_TO_O_STR = $(subst ','\'',$(C_TO_O)) #'# fix syntax highlight
 C_TO_O_DISP = $(if $(V),"$(C_TO_O_STR)","  CC $(@)")
+CXX_TO_O = $(CXX) -Wp,-MD,$(call obj2dep,$(@)).tmp $(CXXFLAGS) \
+	$(CXXFLAGS_$(@)) $(EXTRA_CXXFLAGS) -o $@ -c $<
+CXX_TO_O_STR = $(subst ','\'',$(CXX_TO_O)) #'# fix syntax highlight
+CXX_TO_O_DISP = $(if $(V),"$(CXX_TO_O_STR)","  CXX $(@)")
 endif
 C_TO_O_CMD = 'cmd_$@ = $(C_TO_O_STR)'
 C_TO_O_DO = @set -e; \
@@ -91,6 +99,13 @@ C_TO_O_DO = @set -e; \
 	echo $(C_TO_O_CMD) > $(call obj2cmd,$(@)) && \
 	sed 's,'$@':,dep_'$@' =,' $(call obj2dep,$(@)).tmp > $(call obj2dep,$(@)) && \
 	rm -f $(call obj2dep,$(@)).tmp
+CXX_TO_O_CMD = 'cmd_$@ = $(CXX_TO_O_STR)'
+CXX_TO_O_DO = @set -e; \
+	echo $(CXX_TO_O_DISP); \
+	$(CXX_TO_O) && \
+	echo $(CXX_TO_O_CMD) > $(call obj2cmd,$(@)) && \
+	sed 's,'$@':,dep_'$@' =,' $(call obj2dep,$(@)).tmp > $(call obj2dep,$(@)) && \
+	rm -f $(call obj2dep,$(@)).tmp
 
 # return an empty string if string are equal
 compare = $(strip $(subst $(1),,$(2)) $(subst $(2),,$(1)))
@@ -136,6 +151,26 @@ boolean = $(if $1,1,0)
 		$(depfile_missing),\
 		$(depfile_newer)),\
 		$(C_TO_O_DO))
+#
+# Compile .cc file if needed
+# Note: dep_$$@ is from the .d file and DEP_$$@ can be specified by
+# user (by default it is empty)
+#
+.SECONDEXPANSION:
+%.o: %.cc $$(wildcard $$(dep_$$@)) $$(DEP_$$(@)) FORCE
+	@[ -d $(dir $@) ] || mkdir -p $(dir $@)
+	$(if $(D),\
+		@echo -n "$< -> $@ " ; \
+		echo -n "file_missing=$(call boolean,$(file_missing)) " ; \
+		echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(CXX_TO_O))) " ; \
+		echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
+		echo "depfile_newer=$(call boolean,$(depfile_newer))")
+	$(if $(or \
+		$(file_missing),\
+		$(call cmdline_changed,$(CXX_TO_O)),\
+		$(depfile_missing),\
+		$(depfile_newer)),\
+		$(CXX_TO_O_DO))
 
 # command to assemble a .S file to generate an object
 ifeq ($(USE_HOST),1)
diff --git a/mk/target/generic/rte.vars.mk b/mk/target/generic/rte.vars.mk
index 53650c3..47d845b 100644
--- a/mk/target/generic/rte.vars.mk
+++ b/mk/target/generic/rte.vars.mk
@@ -146,7 +146,11 @@ endif
 LDFLAGS += -L$(RTE_SDK_BIN)/lib
 endif
 
+# copy CFLAGS to CXXFLAGS
+CXXFLAGS := $(CFLAGS)
+
 export CFLAGS
 export LDFLAGS
+export CXXFLAGS
 
 endif
diff --git a/mk/toolchain/gcc/rte.vars.mk b/mk/toolchain/gcc/rte.vars.mk
index 88f235c..4bdf2eb 100644
--- a/mk/toolchain/gcc/rte.vars.mk
+++ b/mk/toolchain/gcc/rte.vars.mk
@@ -39,6 +39,7 @@
 #
 
 CC        = $(CROSS)gcc
+CXX       = $(CROSS)g++
 KERNELCC  = $(CROSS)gcc
 CPP       = $(CROSS)cpp
 # for now, we don't use as but nasm.
@@ -54,8 +55,10 @@ GCOV      = $(CROSS)gcov
 
 ifeq ("$(origin CC)", "command line")
 HOSTCC    = $(CC)
+HOSTCXX   = $(CXX)
 else
 HOSTCC    = gcc
+HOSTCXX   = gxx
 endif
 HOSTAS    = as
 
@@ -80,5 +83,5 @@ WERROR_FLAGS += -Wundef -Wwrite-strings
 # process cpu flags
 include $(RTE_SDK)/mk/toolchain/$(RTE_TOOLCHAIN)/rte.toolchain-compat.mk
 
-export CC AS AR LD OBJCOPY OBJDUMP STRIP READELF
+export CC CXX AS AR LD OBJCOPY OBJDUMP STRIP READELF
 export TOOLCHAIN_CFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
-- 
2.1.0

  reply	other threads:[~2015-03-12 21:05 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-12 21:05 [dpdk-dev] [RFC PATCH 0/7] add OSv support Takuya ASADA
2015-03-12 21:05 ` Takuya ASADA [this message]
2015-03-12 21:05 ` [dpdk-dev] [RFC PATCH 2/7] eal: Add extern C on eal_hugepages.h Takuya ASADA
2015-03-12 21:05 ` [dpdk-dev] [RFC PATCH 3/7] eal: Add extern C on eal_thread.h Takuya ASADA
2015-03-12 21:05 ` [dpdk-dev] [RFC PATCH 4/7] eal: Add extern C on eal_private.h Takuya ASADA
2015-03-12 21:05 ` [dpdk-dev] [RFC PATCH 5/7] add OSv support Takuya ASADA
2015-03-15 12:01   ` Neil Horman
2015-03-16 20:21     ` Stephen Hemminger
2015-03-16 22:42       ` Neil Horman
2015-03-21  3:23         ` Takuya ASADA
2015-03-12 21:05 ` [dpdk-dev] [RFC PATCH 6/7] virtio: enable MSI-X on OSv Takuya ASADA
2015-03-12 21:05 ` [dpdk-dev] [RFC PATCH 7/7] app/test: support OSv Takuya ASADA
2015-03-13 10:00 ` [dpdk-dev] [RFC PATCH 0/7] add OSv support Bruce Richardson
2015-03-13 19:00   ` Takuya ASADA
2015-03-21  3:25   ` Takuya ASADA
2015-03-13 13:42 ` Neil Horman
2015-03-13 19:39   ` Takuya ASADA
2015-03-21  3:22 ` [dpdk-dev] [RFC PATCHv2 0/8] " Takuya ASADA
2015-03-21  3:22   ` [dpdk-dev] [RFC PATCHv2 1/8] mk: support compiling C++ code Takuya ASADA
2015-03-21  3:22   ` [dpdk-dev] [RFC PATCHv2 2/8] eal: Add extern C on eal_hugepages.h Takuya ASADA
2015-03-21  3:23   ` [dpdk-dev] [RFC PATCHv2 3/8] eal: Add extern C on eal_thread.h Takuya ASADA
2015-03-21  3:23   ` [dpdk-dev] [RFC PATCHv2 4/8] eal: Add extern C on eal_private.h Takuya ASADA
2015-03-21  3:23   ` [dpdk-dev] [RFC PATCHv2 5/8] add OSv support Takuya ASADA
2015-03-24 13:52     ` Neil Horman
2015-04-06 19:01       ` Takuya ASADA
2015-03-21  3:23   ` [dpdk-dev] [RFC PATCHv2 6/8] virtio: enable MSI-X on OSv Takuya ASADA
2015-03-21  3:23   ` [dpdk-dev] [RFC PATCHv2 7/8] app/test: support OSv Takuya ASADA
2015-03-21  3:23   ` [dpdk-dev] [RFC PATCHv2 8/8] doc: Add Getting Started Guide for OSv Takuya ASADA

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=1426194348-4406-2-git-send-email-syuu@cloudius-systems.com \
    --to=syuu@cloudius-systems.com \
    --cc=dev@dpdk.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;
as well as URLs for NNTP newsgroup(s).