11# Build Project
22DOCKER ?= 1
3- WSL ?= $(if $(findstring Windows_NT,$(OS ) ) ,1,0)
3+
4+ # Detect whether the OS is Windows Subsystem for Linux (WSL)
5+ ifeq ($(OS ) ,Windows_NT)
6+ WSL ?= 0
7+ else
8+ WSL ?= $(shell uname -r | grep -i microsoft > /dev/null && echo 1 || echo 0)
9+ endif
10+
11+ # Set the ESP IDF version
412ESP_IDF_PATH ?= ~/esp/esp-idf-v{{esp_idf_version}}
13+
14+ # Set the build base folders
515BUILD_BASE_FOLDER ?= build
616BUILD_CONFIG_BASE_DIR = systypes
17+ BUILD_RAFT_ARTEFACTS_DIR ?= build_raft_artefacts
18+
19+ # Set the SysType
720SYSTYPE ?= $(notdir $(firstword $(filter-out $(BUILD_CONFIG_BASE_DIR ) /Common, $(wildcard $(BUILD_CONFIG_BASE_DIR ) /* ) ) ) )
21+
22+ # Set the build configuration folders based on the SysType
823BUILD_CONFIG_DIR = $(BUILD_CONFIG_BASE_DIR ) /$(SYSTYPE )
924COMMON_CONFIG_DIR = $(BUILD_CONFIG_BASE_DIR ) /Common
10- BUILD_RAFT_ARTEFACTS_DIR ?= build_raft_artefacts
25+
26+ # Set the build directory
1127BUILD_DIR = $(BUILD_BASE_FOLDER ) /$(SYSTYPE )
1228ROOTDIR = $(realpath $(CURDIR ) )
29+
30+ # Set the sdkconfig files
1331SDKCONFIG_DEFAULTS_FILE ?= $(BUILD_CONFIG_DIR ) /sdkconfig.defaults
1432SDKCONFIG_FILE ?= $(BUILD_RAFT_ARTEFACTS_DIR ) /sdkconfig
33+
34+ # Set the target binary
1535TARGET_BINARY = $(BUILD_DIR ) /$(SYSTYPE ) .bin
16- # DOCKER_EXEC ?= docker run --rm -v $(ROOTDIR):/project -w /project espressif/idf:v5.1.2
36+
37+ # Set the build commands
1738DOCKER_EXEC = docker build -t raftbuilder . && docker run --rm -v $(ROOTDIR ) :/project -w /project raftbuilder
1839LOCAL_EXEC = . $(ESP_IDF_PATH ) /export.sh
1940CMD ?= idf.py -B $(BUILD_DIR ) build
2041
42+ # Prepare build commands depending on the OS
2143ifeq ($(WSL ) ,1)
2244 SERIAL_MONITOR ?= raft.exe monitor
2345 PYTHON_FOR_FLASH ?= python.exe
@@ -45,18 +67,22 @@ BUILD_TARGET=\
4567 $(LOCAL_EXEC ) && $(CMD )
4668endif
4769
70+ # Default target
4871all : build
4972
5073# Dependencies of target binary
5174$(TARGET_BINARY ) : $(wildcard $(BUILD_CONFIG_DIR ) /* ) $(wildcard $(COMMON_CONFIG_DIR ) /* ) $(wildcard $(COMMON_CONFIG_DIR ) /FSImage/* ) $(wildcard $(COMMON_CONFIG_DIR ) /WebUI* )
5275 @$(DELETE_BUILD_FOLDERS )
5376
77+ # Clean the build
5478clean :
5579 @$(DELETE_BUILD_FOLDERS )
5680
81+ # Build the project
5782build : $(TARGET_BINARY )
5883 @$(BUILD_TARGET )
5984
85+ # Flash the project
6086ifneq ($(SERIAL_MONITOR ) ,)
6187flash : build
6288 @$(PYTHON_FOR_FLASH ) $(BUILD_DIR ) /_deps/raftcore-src/scripts/flashUsingPartitionCSV.py $(BUILD_RAFT_ARTEFACTS_DIR ) /partitions.csv $(BUILD_DIR ) $(SYSTYPE ) .bin $(PORT ) -s $(SDKCONFIG_FILE ) -f fs.bin
@@ -66,4 +92,5 @@ flash: build
6692 @$(PYTHON_FOR_FLASH ) $(BUILD_DIR ) /_deps/raftcore-src/scripts/flashUsingPartitionCSV.py $(BUILD_RAFT_ARTEFACTS_DIR ) /partitions.csv $(BUILD_DIR ) $(SYSTYPE ) .bin $(PORT ) -s $(SDKCONFIG_FILE ) -f fs.bin
6793endif
6894
69- .PHONY : build clean flash test
95+ # Phony targets to avoid name clashes with files
96+ .PHONY : build clean flash test
0 commit comments