[dpdk-dev] Changes to makefiles to allow building apps using g++

Dan Kan dan at nyansa.com
Mon Jan 13 23:45:38 CET 2014


I made changes to makefiles to at least allow app development to be in done
C++. I'm wondering if the community is interested in getting these changes
as a patch. The dpdk library must still be compiled using gcc. However, the
applications can be compiled using g++ by setting CC=g++, e.g. "make
CC=g++". With g++, non-trivial designated initializers will no longer be
allowed among others. As a result, most sample apps cannot be compiled
using g++ without modifications; hello world app works with g++. You will
also need to specify your c++ file extension if it's not named cpp, e.g.
make CC=g++ CXX-suffix=cc. The behavior for gcc or icc compilation remains
unmodified. Anyway, let me know if it's worthwhile to submit a patch.
Thanks.

Here is the preview of the patch.

+++ mk/internal/rte.compile-pre.mk    2014-01-13 14:14:34.278816220 -0800

@@ -33,11 +33,14 @@
 # Common to rte.lib.mk, rte.app.mk, rte.obj.mk
 #

+CXX-suffix = cpp
+
 SRCS-all := $(SRCS-y) $(SRCS-n) $(SRCS-)

 # convert source to obj file
 src2obj = $(strip $(patsubst %.c,%.o,\
-    $(patsubst %.S,%_s.o,$(1))))
+    $(patsubst %.$(CXX-suffix),%.o,\
+    $(patsubst %.S,%_s.o,$(1)))))

 # add a dot in front of the file name
 dotfile = $(strip $(foreach f,$(1),\
@@ -46,12 +49,14 @@
 # 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 %.$(CXX-suffix),%.o.d, \
+        $(patsubst %.S,,$(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 %.$(CXX-suffix),%.o.cmd, \
+        $(patsubst %.S,%_s.o.cmd,$(1))))))
 obj2cmd = $(strip $(call dotfile,$(patsubst %.o,%.o.cmd,$(1))))

 OBJS-y := $(call src2obj,$(SRCS-y))
@@ -137,6 +142,22 @@
         $(depfile_newer)),\
         $(C_TO_O_DO))

+%.o: %.$(CXX-suffix) $$(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,$(C_TO_O))) " ; \
+        echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
+        echo "depfile_newer=$(call boolean,$(depfile_newer))")
+    $(if $(or \
+        $(file_missing),\
+        $(call cmdline_changed,$(C_TO_O)),\
+        $(depfile_missing),\
+        $(depfile_newer)),\
+        $(C_TO_O_DO))
+
+
 # command to assemble a .S file to generate an object
 ifeq ($(USE_HOST),1)
 S_TO_O = $(CPP) $(HOST_CPPFLAGS) $($(@)_CPPFLAGS) $(HOST_EXTRA_CPPFLAGS)
$< $(@).tmp && \
diff -ur ../temp/dpdk-1.5.1r2/mk/toolchain/gcc/rte.vars.mk mk/toolchain/gcc/
rte.vars.mk
--- ../temp/dpdk-1.5.1r2/mk/toolchain/gcc/rte.vars.mk    2014-01-02
07:03:19.000000000 -0800
+++ mk/toolchain/gcc/rte.vars.mk    2014-01-13 14:07:33.148292590 -0800
@@ -68,9 +68,16 @@
 endif
 endif

+ifeq ($(CC), $(CROSS)g++)
+TOOLCHAIN_CFLAGS += -D__STDC_LIMIT_MACROS
+WERROR_FLAGS := -W -Wall -Werror
+WERROR_FLAGS += -Wmissing-declarations -Wpointer-arith
+WERROR_FLAGS += -Wcast-align -Wcast-qual
+else
 WERROR_FLAGS := -W -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes
 WERROR_FLAGS += -Wmissing-declarations -Wold-style-definition
-Wpointer-arith
 WERROR_FLAGS += -Wcast-align -Wnested-externs -Wcast-qual
+endif
 WERROR_FLAGS += -Wformat-nonliteral -Wformat-security

 ifeq ($(CONFIG_RTE_EXEC_ENV),"linuxapp")


More information about the dev mailing list