Skip to content

Commit 8025ada

Browse files
authored
tooling: Replace cd && make with make -C in firmware targets (#364)
* tooling: Replace cd && make with make -C in firmware targets. * fix: Use git -C and ?= for STM32_DIR to avoid cd state leakage.
1 parent b3a903e commit 8025ada

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

Makefile

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,34 +94,37 @@ $(MPY_DIR):
9494
@echo "Cloning micropython-steami into $(CURDIR)/$(MPY_DIR)..."
9595
@mkdir -p $(dir $(CURDIR)/$(MPY_DIR))
9696
git clone --branch $(MICROPYTHON_BRANCH) $(MICROPYTHON_REPO) $(CURDIR)/$(MPY_DIR)
97-
cd $(CURDIR)/$(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD) submodules
97+
$(MAKE) -C $(STM32_DIR) BOARD=$(BOARD) submodules
9898

9999
.PHONY: firmware
100100
firmware: $(MPY_DIR) ## Build MicroPython firmware with current drivers
101101
@set -e
102102
@if [ ! -f "$(MPY_DIR)/lib/micropython-lib/README.md" ]; then \
103103
echo "Initializing submodules for $(BOARD)..."; \
104-
cd $(CURDIR)/$(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD) submodules; \
104+
$(MAKE) -C $(STM32_DIR) BOARD=$(BOARD) submodules; \
105105
fi
106106
@echo "Linking local drivers..."
107107
rm -rf $(CURDIR)/$(MPY_DIR)/lib/micropython-steami-lib
108108
ln -s $(CURDIR) $(CURDIR)/$(MPY_DIR)/lib/micropython-steami-lib
109109
@echo "Building firmware for $(BOARD)..."
110-
cd $(CURDIR)/$(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD)
111-
@echo "Firmware ready: $(CURDIR)/$(MPY_DIR)/ports/stm32/build-$(BOARD)/firmware.hex"
110+
$(MAKE) -C $(STM32_DIR) BOARD=$(BOARD)
111+
@echo "Firmware ready: $(STM32_DIR)/build-$(BOARD)/firmware.hex"
112112

113113
.PHONY: firmware-update
114114
firmware-update: $(MPY_DIR) ## Update the MicroPython clone and board-specific submodules
115115
@set -e
116116
@echo "Updating micropython-steami..."
117117
rm -rf $(CURDIR)/$(MPY_DIR)/lib/micropython-steami-lib
118-
cd $(CURDIR)/$(MPY_DIR) && git fetch origin && git checkout $(MICROPYTHON_BRANCH) && git checkout -- lib/micropython-steami-lib && git pull --ff-only
118+
git -C $(CURDIR)/$(MPY_DIR) fetch origin
119+
git -C $(CURDIR)/$(MPY_DIR) checkout $(MICROPYTHON_BRANCH)
120+
git -C $(CURDIR)/$(MPY_DIR) checkout -- lib/micropython-steami-lib
121+
git -C $(CURDIR)/$(MPY_DIR) pull --ff-only
119122
@echo "Updating required submodules for $(BOARD)..."
120-
cd $(CURDIR)/$(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD) submodules
123+
$(MAKE) -C $(STM32_DIR) BOARD=$(BOARD) submodules
121124

122125
.PHONY: deploy
123126
deploy: $(MPY_DIR) ## Flash firmware to the board via OpenOCD
124-
cd $(CURDIR)/$(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD) deploy-openocd
127+
$(MAKE) -C $(STM32_DIR) BOARD=$(BOARD) deploy-openocd
125128

126129
.PHONY: run
127130
run: ## Run a script on the board with live output (SCRIPT=path/to/file.py)
@@ -145,8 +148,8 @@ run-main: ## Re-execute main.py on the board and capture output
145148

146149
.PHONY: firmware-clean
147150
firmware-clean: ## Clean firmware build artifacts
148-
@if [ -d "$(MPY_DIR)/ports/stm32" ]; then \
149-
cd $(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD) clean; \
151+
@if [ -d "$(STM32_DIR)" ]; then \
152+
$(MAKE) -C $(STM32_DIR) BOARD=$(BOARD) clean; \
150153
fi
151154

152155
# --- Hardware ---

env.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ MICROPYTHON_BRANCH ?= stm32-steami-rev1d-final
77
BOARD ?= STEAM32_WB55RG
88
BUILD_DIR ?= .build
99
MPY_DIR ?= $(BUILD_DIR)/micropython-steami
10+
STM32_DIR ?= $(MPY_DIR)/ports/stm32

0 commit comments

Comments
 (0)