From f7398f61ffb239e61accf5c7b2df2ffeb3ee8214 Mon Sep 17 00:00:00 2001 From: Pham Huu Dang Nhat <51002279@hcmut.edu.vn> Date: Wed, 25 Jun 2014 08:17:20 +0700 Subject: [PATCH] Changed RIOT/Makefile.include, Makefile.base, Makefile.cflags, and native/Makefile.include to compile C and C++ files. --- Makefile.base | 17 ++++++++++++++++- Makefile.cflags | 3 +++ Makefile.include | 9 +++++++-- boards/native/Makefile.include | 5 +++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Makefile.base b/Makefile.base index 446ef1609c..f9cf7bbf30 100644 --- a/Makefile.base +++ b/Makefile.base @@ -30,8 +30,19 @@ ASMOBJ += $(ASSMSRC:%.S=$(BINDIR)$(MODULE)/%.o) ifeq ($(strip $(SRC)),) SRC = $(wildcard *.c) endif -OBJ = $(SRC:%.c=$(BINDIR)$(MODULE)/%.o) + +ifeq ($(strip $(SRCXX)),) + SRCXX = $(wildcard *.cpp) +endif + +OBJC = $(SRC:%.c=$(BINDIR)$(MODULE)/%.o) +OBJCXX = $(SRCXX:%.cpp=$(BINDIR)$(MODULE)/%.o) + +OBJ = $(OBJC) +OBJ += $(OBJCXX) + DEP = $(SRC:%.c=$(BINDIR)$(MODULE)/%.d) +DEP += $(SRCXX:%.cpp=$(BINDIR)$(MODULE)/%.d) $(BINDIR)$(MODULE).a: $(OBJ) $(ASMOBJ) ${DIRS:%=ALL--%} @mkdir -p $(BINDIR)$(MODULE) @@ -46,6 +57,10 @@ $(BINDIR)$(MODULE)/%.o: %.c @mkdir -p $(BINDIR)$(MODULE) $(AD)$(CC) $(CFLAGS) $(INCLUDES) -MD -MP -c -o $(BINDIR)$(MODULE)/$*.o $(abspath $*.c) +$(BINDIR)$(MODULE)/%.o: %.cpp + @mkdir -p $(BINDIR)$(MODULE) + $(AD)$(CXX) $(filter-out $(CXXUWFLAGS), $(CFLAGS)) $(CXXEXFLAGS) $(INCLUDES) -MD -MP -c -o $(BINDIR)$(MODULE)/$*.o $(abspath $*.cpp) + $(BINDIR)$(MODULE)/%.o: %.s @mkdir -p $(BINDIR)$(MODULE) $(AD)$(AS) $(ASFLAGS) $*.s -o $(BINDIR)$(MODULE)/$*.o diff --git a/Makefile.cflags b/Makefile.cflags index d1478e5dc0..6bf285d051 100644 --- a/Makefile.cflags +++ b/Makefile.cflags @@ -29,3 +29,6 @@ ifeq ($(shell $(CC) -Wstrict-prototypes -Werror=strict-prototypes -Wold-style-de # duplicated parameters don't hurt CFLAGS += -Wstrict-prototypes -Werror=strict-prototypes -Wold-style-definition -Werror=old-style-definition endif + +# Unwanted flags for c++ +CXXUWFLAGS += -std=gnu99 -std=c99 -Wstrict-prototypes -Wold-style-definition diff --git a/Makefile.include b/Makefile.include index 78285a6ed8..3bfb9865ad 100644 --- a/Makefile.include +++ b/Makefile.include @@ -90,14 +90,19 @@ BASELIBS += $(USEPKG:%=${BINDIR}%.a) export ELFFILE ?= $(BINDIR)$(APPLICATION).elf export HEXFILE ?= $(ELFFILE:.elf=.hex) +# variables used to complie and link c++ +export CPPMIX ?= $(if $(wildcard *.cpp),1,) +export CXXUWFLAGS +export CXXEXFLAGS + ## make script for your application. Build RIOT-base here! all: ..build-message $(USEPKG:%=${BINDIR}%.a) $(APPDEPS) $(AD)DIRS="$(DIRS)" "$(MAKE)" -C $(CURDIR) -f $(RIOTBASE)/Makefile.application ifeq (,$(RIOTNOLINK)) ifeq ($(BUILDOSXNATIVE),1) - $(AD)$(LINK) $(UNDEF) -o $(ELFFILE) $(BASELIBS) $(LINKFLAGS) -Wl,-no_pie + $(AD)$(if $(CPPMIX),$(CXX),$(LINK)) $(UNDEF) -o $(ELFFILE) $(BASELIBS) $(LINKFLAGS) -Wl,-no_pie else - $(AD)$(LINK) $(UNDEF) -o $(ELFFILE) -Wl,--start-group $(BASELIBS) -lm -Wl,--end-group -Wl,-Map=$(BINDIR)$(APPLICATION).map $(LINKFLAGS) + $(AD)$(if $(CPPMIX),$(CXX),$(LINK)) $(UNDEF) -o $(ELFFILE) -Wl,--start-group $(BASELIBS) -lm -Wl,--end-group -Wl,-Map=$(BINDIR)$(APPLICATION).map $(LINKFLAGS) endif $(AD)$(SIZE) $(ELFFILE) $(AD)$(OBJCOPY) $(OFLAGS) $(ELFFILE) $(HEXFILE) diff --git a/boards/native/Makefile.include b/boards/native/Makefile.include index cd76950f1a..6b5a8ccc77 100644 --- a/boards/native/Makefile.include +++ b/boards/native/Makefile.include @@ -10,6 +10,7 @@ export ELF = $(BINDIR)$(APPLICATION).elf # toolchain: export PREFIX = export CC ?= $(PREFIX)gcc +export CXX ?= $(PREFIX)g++ export AR ?= $(PREFIX)ar export AS ?= $(PREFIX)as export LINK ?= $(PREFIX)gcc @@ -31,6 +32,10 @@ export CFLAGS += -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32 endif endif +# unwanted (CXXUWFLAGS) and extra (CXXEXFLAGS) flags for c++ +export CXXUWFLAGS += +export CXXEXFLAGS += + export LINKFLAGS += -m32 ifeq ($(shell uname -s),FreeBSD) ifeq ($(shell uname -m),amd64)