From 404ebeeb33cd1990379699c36fd1db93baf1415e Mon Sep 17 00:00:00 2001 From: blckmn Date: Fri, 23 May 2025 19:19:15 +1000 Subject: [PATCH] Suggestions from coderabbitai --- Makefile | 7 +++++-- mk/tools.mk | 25 +++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 081b4303df..572f5c9b98 100644 --- a/Makefile +++ b/Makefile @@ -57,8 +57,11 @@ CFLAGS_DISABLED := FORKNAME = betaflight # Working directories +# ROOT_DIR is the full path to the directory containing this Makefile ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) +# ROOT is the relative path to the directory containing this Makefile ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) + PLATFORM_DIR := $(ROOT)/src/platform SRC_DIR := $(ROOT)/src/main LIB_MAIN_DIR := $(ROOT)/lib/main @@ -432,7 +435,7 @@ $(TARGET_HEX): $(TARGET_ELF) $(TARGET_UF2): $(TARGET_ELF) @echo "Creating UF2 $(TARGET_UF2)" "$(STDOUT)" - $(V1) $(PICOTOOL) uf2 convert $< $@ + $(V1) $(PICOTOOL) uf2 convert $< $@ || { echo "Failed to convert ELF to UF2 format"; exit 1; } $(TARGET_DFU): $(TARGET_HEX) @echo "Creating DFU $(TARGET_DFU)" "$(STDOUT)" @@ -693,7 +696,7 @@ version: submodules: @echo "Updating submodules" - $(V1) git submodule update --init --recursive + $(V1) git submodule update --init --recursive || { echo "Failed to update submodules"; exit 1; } @echo "Submodules updated" ## help : print this help message and exit diff --git a/mk/tools.mk b/mk/tools.mk index 664f48c6c4..5ecf7c79ab 100644 --- a/mk/tools.mk +++ b/mk/tools.mk @@ -337,16 +337,21 @@ PICOTOOL_REPO := https://github.com/raspberrypi/picotool.git PICOTOOL_DL_DIR := $(DL_DIR)/picotool PICOTOOL_BUILD_DIR := $(PICOTOOL_DL_DIR)/build PICOTOOL_DIR := $(TOOLS_DIR)/picotool -PICO_SDK_PATH := $(ROOT_DIR)/lib/main/pico-sdk -PICOTOOL := $(PICOTOOL_DIR)/picotool +PICO_SDK_PATH ?= $(ROOT_DIR)/lib/main/pico-sdk +PICOTOOL ?= $(PICOTOOL_DIR)/picotool + +ifeq ($(filter picotool_install,$(MAKECMDGOALS)), picotool_install) + ifneq ($(wildcard $(PICO_SDK_PATH)/CMakeLists.txt),$(PICO_SDK_PATH)/CMakeLists.txt) + $(error "PICO_SDK_PATH ($(PICO_SDK_PATH)) does not point to a valid Pico SDK. Please 'make submodules' to hydrate the Pico SDK.") + endif +endif ifeq ($(filter uf2,$(MAKECMDGOALS)), uf2) ifeq (,$(wildcard $(PICOTOOL))) - PICOTOOL_VERSION := $(shell picotool version) - ifneq ($(PICOTOOL_VERSION),) - PICOTOOL := picotool + ifeq (,$(shell which picotool 2>/dev/null)) + $(error "picotool not in the PATH or setup in tools. Run 'make picotool_install' to install in the tools folder.") else - $(error **ERROR** picotool not in the PATH or setup in tools. Run 'make picotool_install' to install automatically in the tools folder) + PICOTOOL := picotool endif endif endif @@ -355,13 +360,13 @@ endif picotool_install: | $(DL_DIR) $(TOOLS_DIR) picotool_install: picotool_clean @echo "\n CLONE $(PICOTOOL_REPO)" - $(V1) git clone --depth 1 $(PICOTOOL_REPO) "$(PICOTOOL_DL_DIR)" + $(V1) git clone --depth 1 $(PICOTOOL_REPO) "$(PICOTOOL_DL_DIR)" || { echo "Failed to clone picotool repository"; exit 1; } @echo "\n BUILD $(PICOTOOL_BUILD_DIR)" $(V1) [ -d "$(PICOTOOL_DIR)" ] || mkdir -p $(PICOTOOL_DIR) $(V1) [ -d "$(PICOTOOL_BUILD_DIR)" ] || mkdir -p $(PICOTOOL_BUILD_DIR) - $(V1) cmake -S $(PICOTOOL_DL_DIR) -B $(PICOTOOL_BUILD_DIR) -D PICO_SDK_PATH=$(PICO_SDK_PATH) - $(V1) $(MAKE) -C $(PICOTOOL_BUILD_DIR) - $(V1) cp $(PICOTOOL_BUILD_DIR)/picotool $(PICOTOOL_DIR)/picotool + $(V1) cmake -S $(PICOTOOL_DL_DIR) -B $(PICOTOOL_BUILD_DIR) -D PICO_SDK_PATH=$(PICO_SDK_PATH) || { echo "CMake configuration failed"; exit 1; } + $(V1) $(MAKE) -C $(PICOTOOL_BUILD_DIR) || { echo "picotool build failed"; exit 1; } + $(V1) cp $(PICOTOOL_BUILD_DIR)/picotool $(PICOTOOL_DIR)/picotool || { echo "Failed to install picotool binary"; exit 1; } @echo "\n VERSION:" $(V1) $(PICOTOOL_DIR)/picotool version