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

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

View file

@ -72,7 +72,7 @@ CONTIKI_SOURCEFILES += $(CONTIKIFILES)
CONTIKIDIRS += ${addprefix $(CONTIKI)/core/,dev lib net net/llsec net/mac net/rime \ CONTIKIDIRS += ${addprefix $(CONTIKI)/core/,dev lib net net/llsec net/mac net/rime \
net/rpl sys cfs ctk lib/ctk loader . } 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)}} CONTIKI_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CONTIKI_SOURCEFILES)}}
@ -124,16 +124,18 @@ endif
### Verbosity control. Use make V=1 to get verbose builds. ### Verbosity control. Use make V=1 to get verbose builds.
ifeq ($(V),1) ifeq ($(V),1)
TRACE_CC = TRACE_CC =
TRACE_LD = TRACE_CXX =
TRACE_AR = TRACE_LD =
TRACE_AS = TRACE_AR =
TRACE_AS =
Q= Q=
else else
TRACE_CC = @echo " CC " $< TRACE_CC = @echo " CC " $<
TRACE_LD = @echo " LD " $@ TRACE_CXX = @echo " CXX " $<
TRACE_AR = @echo " AR " $@ TRACE_LD = @echo " LD " $@
TRACE_AS = @echo " AS " $< TRACE_AR = @echo " AR " $@
TRACE_AS = @echo " AS " $<
Q=@ Q=@
endif endif
@ -152,8 +154,9 @@ CONTIKI_CPU_DIRS_CONCAT = ${addprefix $(CONTIKI_CPU)/, \
SOURCEDIRS = . $(PROJECTDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) \ SOURCEDIRS = . $(PROJECTDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) \
$(CONTIKI_CPU_DIRS_CONCAT) $(CONTIKIDIRS) $(APPDS) ${dir $(target_makefile)} $(CONTIKI_CPU_DIRS_CONCAT) $(CONTIKIDIRS) $(APPDS) ${dir $(target_makefile)}
vpath %.c $(SOURCEDIRS) vpath %.c $(SOURCEDIRS)
vpath %.S $(SOURCEDIRS) vpath %.cpp $(SOURCEDIRS)
vpath %.S $(SOURCEDIRS)
CFLAGS += ${addprefix -I,$(SOURCEDIRS) $(CONTIKI)} CFLAGS += ${addprefix -I,$(SOURCEDIRS) $(CONTIKI)}
@ -171,7 +174,7 @@ endif
ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),clean)
-include ${addprefix $(OBJECTDIR)/,$(CONTIKI_SOURCEFILES:.c=.d) \ -include ${addprefix $(OBJECTDIR)/,$(CONTIKI_SOURCEFILES:.c=.d) \
$(PROJECT_SOURCEFILES:.c=.d)} $(PROJECT_OBJECTFILES:.o=.d)}
endif endif
### See http://make.paulandlesley.org/autodep.html#advanced ### See http://make.paulandlesley.org/autodep.html#advanced
@ -210,6 +213,13 @@ $(OBJECTDIR)/%.o: %.c | $(OBJECTDIR)
@$(FINALIZE_DEPENDENCY) @$(FINALIZE_DEPENDENCY)
endif 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 ifndef CUSTOM_RULE_S_TO_OBJECTDIR_O
$(OBJECTDIR)/%.o: %.S | $(OBJECTDIR) $(OBJECTDIR)/%.o: %.S | $(OBJECTDIR)
$(TRACE_AS) $(TRACE_AS)
@ -222,6 +232,12 @@ ifndef CUSTOM_RULE_C_TO_O
$(Q)$(CC) $(CFLAGS) -c $< -o $@ $(Q)$(CC) $(CFLAGS) -c $< -o $@
endif endif
ifndef CUSTOM_RULE_CPP_TO_O
%.o: %.cpp
$(TRACE_CXX)
$(Q)$(CXX) $(CFLAGS) -c $< -o $@
endif
ifndef CUSTOM_RULE_C_TO_CO ifndef CUSTOM_RULE_C_TO_CO
%.co: %.c %.co: %.c
@ -265,6 +281,8 @@ endif
# the match-anything rule below instead. # the match-anything rule below instead.
%: %.c %: %.c
%: %.cpp
# Match-anything pattern rule to allow the project makefiles to # Match-anything pattern rule to allow the project makefiles to
# abstract from the actual binary name. It needs to contain some # abstract from the actual binary name. It needs to contain some
# command in order to be a rule, not just a prerequisite. # command in order to be a rule, not just a prerequisite.

View file

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