Allow compilation of c++ files (extension .cpp)

This commit is contained in:
Ralf Schlatterbeck 2014-06-26 08:37:19 +02:00
parent 5991c3e3db
commit 87903b2e89
2 changed files with 37 additions and 12 deletions

View file

@ -65,7 +65,7 @@ CONTIKI_SOURCEFILES += $(CONTIKIFILES)
CONTIKIDIRS += ${addprefix $(CONTIKI)/core/,dev lib net net/mac net/rime \
net/rpl sys cfs ctk lib/ctk loader . }
oname = ${patsubst %.c,%.o,${patsubst %.S,%.o,$(1)}}
oname = ${patsubst %.cpp,%.o,${patsubst %.c,%.o,${patsubst %.S,%.o,$(1)}}}
CONTIKI_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CONTIKI_SOURCEFILES)}}
@ -118,12 +118,14 @@ endif
ifeq ($(V),1)
TRACE_CC =
TRACE_CXX =
TRACE_LD =
TRACE_AR =
TRACE_AS =
Q=
else
TRACE_CC = @echo " CC " $<
TRACE_CXX = @echo " CXX " $<
TRACE_LD = @echo " LD " $@
TRACE_AR = @echo " AR " $@
TRACE_AS = @echo " AS " $<
@ -146,6 +148,7 @@ SOURCEDIRS = . $(PROJECTDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) \
$(CONTIKI_CPU_DIRS_CONCAT) $(CONTIKIDIRS) $(APPDS) ${dir $(target_makefile)}
vpath %.c $(SOURCEDIRS)
vpath %.cpp $(SOURCEDIRS)
vpath %.S $(SOURCEDIRS)
CFLAGS += ${addprefix -I,$(SOURCEDIRS) $(CONTIKI)}
@ -162,7 +165,7 @@ endif
ifneq ($(MAKECMDGOALS),clean)
-include ${addprefix $(OBJECTDIR)/,$(CONTIKI_SOURCEFILES:.c=.d) \
$(PROJECT_SOURCEFILES:.c=.d)}
$(PROJECT_OBJECTFILES:.o=.d)}
endif
### See http://make.paulandlesley.org/autodep.html#advanced
@ -201,6 +204,13 @@ $(OBJECTDIR)/%.o: %.c | $(OBJECTDIR)
@$(FINALIZE_DEPENDENCY)
endif
ifndef CUSTOM_RULE_CPP_TO_OBJECTDIR_O
$(OBJECTDIR)/%.o: %.cpp | $(OBJECTDIR)
$(TRACE_CXX)
$(Q)$(CXX) $(CFLAGS) -MMD -c $< -o $@
@$(FINALIZE_DEPENDENCY)
endif
ifndef CUSTOM_RULE_S_TO_OBJECTDIR_O
$(OBJECTDIR)/%.o: %.S | $(OBJECTDIR)
$(TRACE_AS)
@ -213,6 +223,12 @@ ifndef CUSTOM_RULE_C_TO_O
$(Q)$(CC) $(CFLAGS) -c $< -o $@
endif
ifndef CUSTOM_RULE_CPP_TO_O
%.o: %.cpp
$(TRACE_CXX)
$(Q)$(CXX) $(CFLAGS) -c $< -o $@
endif
ifndef CUSTOM_RULE_C_TO_CO
%.co: %.c
@ -256,6 +272,8 @@ endif
# the match-anything rule below instead.
%: %.c
%: %.cpp
# Match-anything pattern rule to allow the project makefiles to
# abstract from the actual binary name. It needs to contain some
# command in order to be a rule, not just a prerequisite.

View file

@ -90,6 +90,7 @@ CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
### Compiler definitions
CC = avr-gcc
CXX = avr-g++
LD = avr-gcc
AS = avr-as
AR = avr-ar
@ -130,6 +131,12 @@ $(OBJECTDIR)/%.o: %.c | $(OBJECTDIR)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJECTDIR)/%.o: %.cpp | $(OBJECTDIR)
$(CXX) $(CFLAGS) -c $< -o $@
%.o: %.cpp
$(CXX) $(CFLAGS) -c $< -o $@
%.ko: %.o
$(STRIP) -K _init -K _fini --strip-unneeded -g -x $< -o $@