1ifndef COMPONENT 2COMPONENT := spi_flash 3endif 4 5COMPONENT_LIB := lib$(COMPONENT).a 6 7include Makefile.files 8 9all: lib 10 11ifndef SDKCONFIG 12SDKCONFIG_DIR := $(dir $(realpath sdkconfig/sdkconfig.h)) 13SDKCONFIG := $(SDKCONFIG_DIR)sdkconfig.h 14else 15SDKCONFIG_DIR := $(dir $(realpath $(SDKCONFIG))) 16endif 17 18INCLUDE_FLAGS := $(addprefix -I, $(INCLUDE_DIRS) $(SDKCONFIG_DIR)) 19 20CPPFLAGS += $(INCLUDE_FLAGS) -g -m32 21CXXFLAGS += $(INCLUDE_FLAGS) -std=c++11 -g -m32 22 23CFILES := $(filter %.c, $(SOURCE_FILES)) 24CPPFILES := $(filter %.cpp, $(SOURCE_FILES)) 25 26CTARGET = ${2}/$(patsubst %.c,%.o,$(notdir ${1})) 27CPPTARGET = ${2}/$(patsubst %.cpp,%.o,$(notdir ${1})) 28 29ifndef BUILD_DIR 30BUILD_DIR := build 31endif 32 33OBJ_FILES := $(addprefix $(BUILD_DIR)/, $(filter %.o, $(notdir $(SOURCE_FILES:.cpp=.o) $(SOURCE_FILES:.c=.o)))) 34 35%.o : %.c $(SDKCONFIG) 36 $(CC) $(CPPFLAGS) $(CFLAGS) $< - o $@ 37 38%.o : %.cpp $(SDKCONFIG) 39 $(CC) $(CPPFLAGS) $(CFLAGS) $< - o $@ 40 41define COMPILE_C 42$(call CTARGET, ${1}, $(BUILD_DIR)) : ${1} 43 mkdir -p $(BUILD_DIR) 44 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(call CTARGET, ${1}, $(BUILD_DIR)) ${1} 45endef 46 47define COMPILE_CPP 48$(call CPPTARGET, ${1}, $(BUILD_DIR)) : ${1} 49 mkdir -p $(BUILD_DIR) 50 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $(call CPPTARGET, ${1}, $(BUILD_DIR)) ${1} 51endef 52 53$(BUILD_DIR)/$(COMPONENT_LIB): $(OBJ_FILES) $(SDKCONFIG) 54 mkdir -p $(BUILD_DIR) 55 $(AR) rcs $@ $^ 56 57clean: 58 rm -f $(OBJ_FILES) $(BUILD_DIR)/$(COMPONENT_LIB) 59 60lib: $(BUILD_DIR)/$(COMPONENT_LIB) 61 62$(foreach cfile, $(CFILES), $(eval $(call COMPILE_C, $(cfile)))) 63$(foreach cxxfile, $(CPPFILES), $(eval $(call COMPILE_CPP, $(cxxfile)))) 64 65.PHONY: all lib clean 66