1ifndef COMPONENT 2COMPONENT := wl 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 20 21ifndef SDKCONFIG 22SDKCONFIG_DIR := $(dir $(realpath sdkconfig/sdkconfig.h)) 23SDKCONFIG := $(SDKCONFIG_DIR)sdkconfig.h 24else 25SDKCONFIG_DIR := $(dir $(realpath $(SDKCONFIG))) 26endif 27 28INCLUDE_FLAGS := $(addprefix -I, $(INCLUDE_DIRS) -I../../../heap/include/soc $(SDKCONFIG_DIR) ../../../tools/catch) 29 30CPPFLAGS += $(INCLUDE_FLAGS) -g -m32 31CXXFLAGS += $(INCLUDE_FLAGS) -std=c++11 -g -m32 32 33# Build libraries that this component is dependent on 34$(STUBS_LIB_BUILD_DIR)/$(STUBS_LIB): force 35 $(MAKE) -C $(STUBS_LIB_DIR) lib SDKCONFIG=$(SDKCONFIG) 36 37$(SPI_FLASH_SIM_BUILD_DIR)/$(SPI_FLASH_SIM_LIB): force 38 $(MAKE) -C $(SPI_FLASH_SIM_DIR) lib SDKCONFIG=$(SDKCONFIG) 39 40# Create target for building this component as a library 41CFILES := $(filter %.c, $(SOURCE_FILES)) 42CPPFILES := $(filter %.cpp, $(SOURCE_FILES)) 43 44CTARGET = ${2}/$(patsubst %.c,%.o,$(notdir ${1})) 45CPPTARGET = ${2}/$(patsubst %.cpp,%.o,$(notdir ${1})) 46 47ifndef BUILD_DIR 48BUILD_DIR := build 49endif 50 51OBJ_FILES := $(addprefix $(BUILD_DIR)/, $(filter %.o, $(notdir $(SOURCE_FILES:.cpp=.o) $(SOURCE_FILES:.c=.o)))) 52 53define COMPILE_C 54$(call CTARGET, ${1}, $(BUILD_DIR)) : ${1} $(SDKCONFIG) 55 mkdir -p $(BUILD_DIR) 56 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(call CTARGET, ${1}, $(BUILD_DIR)) ${1} 57endef 58 59define COMPILE_CPP 60$(call CPPTARGET, ${1}, $(BUILD_DIR)) : ${1} $(SDKCONFIG) 61 mkdir -p $(BUILD_DIR) 62 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $(call CPPTARGET, ${1}, $(BUILD_DIR)) ${1} 63endef 64 65$(BUILD_DIR)/$(COMPONENT_LIB): $(OBJ_FILES) $(SDKCONFIG) 66 mkdir -p $(BUILD_DIR) 67 $(AR) rcs $@ $^ 68 69clean: 70 $(MAKE) -C $(STUBS_LIB_DIR) clean 71 $(MAKE) -C $(SPI_FLASH_SIM_DIR) clean 72 rm -f $(OBJ_FILES) $(TEST_OBJ_FILES) $(TEST_PROGRAM) $(COMPONENT_LIB) partition_table.bin 73 74lib: $(BUILD_DIR)/$(COMPONENT_LIB) 75 76$(foreach cfile, $(CFILES), $(eval $(call COMPILE_C, $(cfile)))) 77$(foreach cxxfile, $(CPPFILES), $(eval $(call COMPILE_CPP, $(cxxfile)))) 78 79# Create target for building this component as a test 80TEST_SOURCE_FILES = \ 81 test_wl.cpp \ 82 main.cpp \ 83 84TEST_OBJ_FILES = $(filter %.o, $(TEST_SOURCE_FILES:.cpp=.o) $(TEST_SOURCE_FILES:.c=.o)) 85 86$(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) 87 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) 88 89test: $(TEST_PROGRAM) 90 ./$(TEST_PROGRAM) 91 92# Create other necessary targets 93partition_table.bin: partition_table.csv 94 python ../../../components/partition_table/gen_esp32part.py --verify $< $@ 95 96force: 97 98.PHONY: all lib test clean force 99