From 27b0d98d085454a9f3fbaeb73ac3000e5a965db4 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 30 Jun 2015 21:42:21 +0200 Subject: added support for C++ based projects --- include.mk | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'include.mk') diff --git a/include.mk b/include.mk index d2813a6..28eeaaa 100644 --- a/include.mk +++ b/include.mk @@ -28,6 +28,9 @@ include $(SPREADAVR_PATH)/defines.mk ## project-specific objects SRC := $(OBJ:%.o=%.c) DEP := $(SRC:%.c=%.d) +CXX_SRC := $(CXX_OBJ:%.o=%.cpp) +CXX_DEP := $(CXX_SRC:%.cpp=%.d) + OBJ_LIB := $(LIBS:%=lib-%.o) SRC_LIB := $(LIBS:%=$(LIB_DIR)/%.c) DEP_LIB := $(LIBS:%=lib-%.d) @@ -68,31 +71,41 @@ clean-lufa: ## project-specific objects -lib-%.d: $(LIB_DIR)/%.c Makefile +%.d: %.c Makefile @set -e; rm -f $@; \ $(CC) -MM $(CFLAGS) $< > $@.$$$$; \ - sed 's,\($*\)\.o[ :]*,lib-\1.o $@ : ,g' < $@.$$$$ > $@; \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$; echo '(re)building $@' -%.d: %.c Makefile +%.d: %.cpp Makefile @set -e; rm -f $@; \ - $(CC) -MM $(CFLAGS) $< > $@.$$$$; \ + $(CXX) -MM $(CXXFLAGS) $< > $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$; echo '(re)building $@' +lib-%.d: $(LIB_DIR)/%.c Makefile + @set -e; rm -f $@; \ + $(CC) -MM $(CFLAGS) $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,lib-\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$; echo '(re)building $@' + ifneq ($(MAKECMDGOALS),distclean) -include $(DEP) +-include $(CXX_DEP) -include $(DEP_LIB) endif -lib-%.o: $(LIB_DIR)/%.c Makefile +%.o: %.c Makefile $(CC) $(CFLAGS) -c $< -o $@ -%.o: %.c Makefile +%.o: %.cpp Makefile + $(CXX) $(CXXFLAGS) -c $< -o $@ + +lib-%.o: $(LIB_DIR)/%.c Makefile $(CC) $(CFLAGS) -c $< -o $@ -$(ELFFILE): $(OBJ) $(OBJ_LIB) $(EXTERNAL_LIBS:%=lib%.a) - $(CC) $(LDFLAGS) $(OBJ) $(OBJ_LIB) $(EXTERNAL_LIBS:%=-l%) -o $@ +$(ELFFILE): $(OBJ) $(CXX_OBJ) $(OBJ_LIB) $(EXTERNAL_LIBS:%=lib%.a) + $(CC) $(LDFLAGS) $(OBJ) $(CXX_OBJ) $(OBJ_LIB) $(EXTERNAL_LIBS:%=-l%) -o $@ $(SIZE) $@ @echo "" -- cgit v1.2.3