1ifndef COMPONENT 2COMPONENT := spiffs 3endif 4 5COMPONENT_LIB := lib$(COMPONENT).a 6TEST_PROGRAM := test_$(COMPONENT) 7 8STUBS_LIB_DIR := ../../../components/spi_flash/sim/stubs 9STUBS_LIB_BUILD_DIR := $(STUBS_LIB_DIR)/build 10STUBS_LIB := libstubs.a 11 12SPI_FLASH_SIM_DIR := ../../../components/spi_flash/sim 13SPI_FLASH_SIM_BUILD_DIR := $(SPI_FLASH_SIM_DIR)/build 14SPI_FLASH_SIM_LIB := libspi_flash.a 15 16include Makefile.files 17 18all: test 19 20ifndef SDKCONFIG 21SDKCONFIG_DIR := $(dir $(realpath sdkconfig/sdkconfig.h)) 22SDKCONFIG := $(SDKCONFIG_DIR)sdkconfig.h 23else 24SDKCONFIG_DIR := $(dir $(realpath $(SDKCONFIG))) 25endif 26 27INCLUDE_FLAGS := $(addprefix -I, $(INCLUDE_DIRS) $(SDKCONFIG_DIR) ../../../tools/catch) 28 29CPPFLAGS += $(INCLUDE_FLAGS) -g -m32 30CXXFLAGS += $(INCLUDE_FLAGS) -std=c++11 -g -m32 31 32# Build libraries that this component is dependent on 33$(STUBS_LIB_BUILD_DIR)/$(STUBS_LIB): force 34 $(MAKE) -C $(STUBS_LIB_DIR) lib SDKCONFIG=$(SDKCONFIG) 35 36$(SPI_FLASH_SIM_BUILD_DIR)/$(SPI_FLASH_SIM_LIB): force 37 $(MAKE) -C $(SPI_FLASH_SIM_DIR) lib SDKCONFIG=$(SDKCONFIG) 38 39# Create target for building this component as a library 40CFILES := $(filter %.c, $(SOURCE_FILES)) 41CPPFILES := $(filter %.cpp, $(SOURCE_FILES)) 42 43CTARGET = ${2}/$(patsubst %.c,%.o,$(notdir ${1})) 44CPPTARGET = ${2}/$(patsubst %.cpp,%.o,$(notdir ${1})) 45 46ifndef BUILD_DIR 47BUILD_DIR := build 48endif 49 50OBJ_FILES := $(addprefix $(BUILD_DIR)/, $(filter %.o, $(notdir $(SOURCE_FILES:.cpp=.o) $(SOURCE_FILES:.c=.o)))) 51 52define COMPILE_C 53$(call CTARGET, ${1}, $(BUILD_DIR)) : ${1} $(SDKCONFIG) 54 mkdir -p $(BUILD_DIR) 55 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(call CTARGET, ${1}, $(BUILD_DIR)) ${1} 56endef 57 58define COMPILE_CPP 59$(call CPPTARGET, ${1}, $(BUILD_DIR)) : ${1} $(SDKCONFIG) 60 mkdir -p $(BUILD_DIR) 61 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $(call CPPTARGET, ${1}, $(BUILD_DIR)) ${1} 62endef 63 64$(BUILD_DIR)/$(COMPONENT_LIB): $(OBJ_FILES) $(SDKCONFIG) 65 mkdir -p $(BUILD_DIR) 66 $(AR) rcs $@ $^ 67 68clean: 69 $(MAKE) -C $(STUBS_LIB_DIR) clean 70 $(MAKE) -C $(SPI_FLASH_SIM_DIR) clean 71 rm -f $(OBJ_FILES) $(TEST_OBJ_FILES) $(TEST_PROGRAM) $(COMPONENT_LIB) partition_table.bin image.bin 72 73lib: $(BUILD_DIR)/$(COMPONENT_LIB) 74 75$(foreach cfile, $(CFILES), $(eval $(call COMPILE_C, $(cfile)))) 76$(foreach cxxfile, $(CPPFILES), $(eval $(call COMPILE_CPP, $(cxxfile)))) 77 78# Create target for building this component as a test 79TEST_SOURCE_FILES = \ 80 test_spiffs.cpp \ 81 main.cpp \ 82 83TEST_OBJ_FILES = $(filter %.o, $(TEST_SOURCE_FILES:.cpp=.o) $(TEST_SOURCE_FILES:.c=.o)) 84 85$(TEST_PROGRAM): lib $(TEST_OBJ_FILES) $(SPI_FLASH_SIM_BUILD_DIR)/$(SPI_FLASH_SIM_LIB) $(STUBS_LIB_BUILD_DIR)/$(STUBS_LIB) partition_table.bin $(SDKCONFIG) 86 g++ $(LDFLAGS) $(CXXFLAGS) -o $@ $(TEST_OBJ_FILES) -L$(BUILD_DIR) -l:$(COMPONENT_LIB) -L$(SPI_FLASH_SIM_BUILD_DIR) -l:$(SPI_FLASH_SIM_LIB) -L$(STUBS_LIB_BUILD_DIR) -l:$(STUBS_LIB) 87 88# Use spiffs source directory as the test image 89spiffs_image: ../spiffs $(shell find ../spiffs -type d) $(shell find ../spiffs -type -f -name '*') 90 # Creation of test symlinks unfortunately causes rerun of spiffsgen.py every make invoke 91 rm -f ../spiffs/include ../spiffs/CMakeLists.txt 92 ln -s ../include ../spiffs/include 93 ln -s ../CMakeLists.txt ../spiffs/CMakeLists.txt 94 ../spiffsgen.py --follow-symlinks 2097152 ../spiffs image.bin 95 96test: $(TEST_PROGRAM) spiffs_image 97 ./$(TEST_PROGRAM) 98 99# Create other necessary targets 100partition_table.bin: partition_table.csv 101 python ../../../components/partition_table/gen_esp32part.py --verify $< $@ 102 103force: 104 105.PHONY: all lib test clean force 106