From 69b93527d555c45185e7bd933ed0725f4b7230c9 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Tue, 21 Feb 2023 16:01:58 +1100 Subject: [PATCH] ports: Make BOARD default from BOARD_DIR in Makefile's. This allows: $ make BOARD_DIR=path/to/board to infer BOARD=board, rather than the previous behavior that required additionally setting BOARD explicitly. Also makes the same change for VARIANT_DIR -> VARIANT on Unix. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared Signed-off-by: Damien George --- ports/esp8266/Makefile | 18 ++++++++++++------ ports/mimxrt/Makefile | 16 +++++++++++++--- ports/nrf/Makefile | 14 ++++++++++---- ports/renesas-ra/Makefile | 18 ++++++++++++------ ports/samd/Makefile | 17 +++++++++++++---- ports/stm32/Makefile | 18 ++++++++++++------ ports/stm32/mboot/Makefile | 14 +++++++++----- ports/unix/Makefile | 17 ++++++++++++----- ports/windows/Makefile | 17 ++++++++++++----- 9 files changed, 105 insertions(+), 44 deletions(-) diff --git a/ports/esp8266/Makefile b/ports/esp8266/Makefile index 168d1d9f6a..c5eb63fad6 100644 --- a/ports/esp8266/Makefile +++ b/ports/esp8266/Makefile @@ -1,15 +1,21 @@ -# Select the board to build for: if not given on the command line, -# then default to GENERIC. +# Select the board to build for: +ifdef BOARD_DIR +# Custom board path - remove trailing slash and get the final component of +# the path as the board name. +BOARD ?= $(notdir $(BOARD_DIR:/=)) +else +# If not given on the command line, then default to GENERIC. BOARD ?= GENERIC - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - BOARD_DIR ?= boards/$(BOARD) +endif + ifeq ($(wildcard $(BOARD_DIR)/.),) $(error Invalid BOARD specified: $(BOARD_DIR)) endif +# If the build directory is not given, make it reflect the board name. +BUILD ?= build-$(BOARD) + include ../../py/mkenv.mk # Optional diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index bcddeb2d8b..e5a14d010c 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -2,8 +2,21 @@ # Parameter Configuration # ============================================================================= +# Select the board to build for: +ifdef BOARD_DIR +# Custom board path - remove trailing slash and get the final component of +# the path as the board name. +BOARD ?= $(notdir $(BOARD_DIR:/=)) +else +# If not given on the command line, then default to TEENSY40. BOARD ?= TEENSY40 BOARD_DIR ?= boards/$(BOARD) +endif + +ifeq ($(wildcard $(BOARD_DIR)/.),) + $(error Invalid BOARD specified: $(BOARD_DIR)) +endif + BUILD ?= build-$(BOARD) PORT ?= /dev/ttyACM0 CROSS_COMPILE ?= arm-none-eabi- @@ -25,9 +38,6 @@ MAKE_FLEXRAM_LD = boards/make-flexram-config.py include ../../py/mkenv.mk # Include micropython configuration board makefile -ifeq ($(wildcard $(BOARD_DIR)/.),) - $(error Invalid BOARD specified: $(BOARD_DIR)) -endif include $(BOARD_DIR)/mpconfigboard.mk # File containing description of content to be frozen into firmware. diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 5cb2fc0311..9ba6267577 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -1,12 +1,18 @@ -# Select the board to build for: if not given on the command line, -# then default to pca10040. +# Select the board to build for: +ifdef BOARD_DIR +# Custom board path - remove trailing slash and get the final component of +# the path as the board name. +BOARD ?= $(notdir $(BOARD_DIR:/=)) +else +# If not given on the command line, then default to pca10040. BOARD ?= pca10040 +BOARD_DIR ?= boards/$(BOARD) +endif + ifeq ($(wildcard boards/$(BOARD)/.),) $(error Invalid BOARD specified) endif -BOARD_DIR ?= boards/$(BOARD) - # If SoftDevice is selected, try to use that one. SD ?= SD_LOWER = $(shell echo $(SD) | tr '[:upper:]' '[:lower:]') diff --git a/ports/renesas-ra/Makefile b/ports/renesas-ra/Makefile index 17ec58ae0b..dc4b158483 100644 --- a/ports/renesas-ra/Makefile +++ b/ports/renesas-ra/Makefile @@ -1,15 +1,21 @@ -# Select the board to build for: if not given on the command line, -# then default to RA6M2_EK. +# Select the board to build for: +ifdef BOARD_DIR +# Custom board path - remove trailing slash and get the final component of +# the path as the board name. +BOARD ?= $(notdir $(BOARD_DIR:/=)) +else +# If not given on the command line, then default to RA6M2_EK. BOARD ?= RA6M2_EK - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - BOARD_DIR ?= boards/$(BOARD) +endif + ifeq ($(wildcard $(BOARD_DIR)/.),) $(error Invalid BOARD specified: $(BOARD_DIR)) endif +# If the build directory is not given, make it reflect the board name. +BUILD ?= build-$(BOARD) + ifeq ($(BOARD),RA4M1_CLICKER) BOARD_LOW = ra4m1_ek CMSIS_MCU_LOW = ra4m1 diff --git a/ports/samd/Makefile b/ports/samd/Makefile index fc5fa9e437..465a70a617 100644 --- a/ports/samd/Makefile +++ b/ports/samd/Makefile @@ -1,14 +1,23 @@ +# Select the board to build for: +ifdef BOARD_DIR +# Custom board path - remove trailing slash and get the final component of +# the path as the board name. +BOARD ?= $(notdir $(BOARD_DIR:/=)) +else +# If not given on the command line, then default to ADAFRUIT_ITSYBITSY_M4_EXPRESS. BOARD ?= ADAFRUIT_ITSYBITSY_M4_EXPRESS BOARD_DIR ?= boards/$(BOARD) -BUILD ?= build-$(BOARD) - -CROSS_COMPILE ?= arm-none-eabi- -UF2CONV ?= $(TOP)/tools/uf2conv.py +endif ifeq ($(wildcard $(BOARD_DIR)/.),) $(error Invalid BOARD specified: $(BOARD_DIR)) endif +BUILD ?= build-$(BOARD) + +CROSS_COMPILE ?= arm-none-eabi- +UF2CONV ?= $(TOP)/tools/uf2conv.py + MCU_SERIES_LOWER = $(shell echo $(MCU_SERIES) | tr '[:upper:]' '[:lower:]') include ../../py/mkenv.mk diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index d57e72a6c5..5774f9de5b 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -1,15 +1,21 @@ -# Select the board to build for: if not given on the command line, -# then default to PYBV10. +# Select the board to build for: +ifdef BOARD_DIR +# Custom board path - remove trailing slash and get the final component of +# the path as the board name. +BOARD ?= $(notdir $(BOARD_DIR:/=)) +else +# If not given on the command line, then default to PYBV10. BOARD ?= PYBV10 - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - BOARD_DIR ?= boards/$(BOARD) +endif + ifeq ($(wildcard $(BOARD_DIR)/.),) $(error Invalid BOARD specified: $(BOARD_DIR)) endif +# If the build directory is not given, make it reflect the board name. +BUILD ?= build-$(BOARD) + include ../../py/mkenv.mk -include mpconfigport.mk include $(BOARD_DIR)/mpconfigboard.mk diff --git a/ports/stm32/mboot/Makefile b/ports/stm32/mboot/Makefile index 12ffdbc7e4..053b317e17 100755 --- a/ports/stm32/mboot/Makefile +++ b/ports/stm32/mboot/Makefile @@ -1,13 +1,17 @@ -# Select the board to build for: if not given on the command line, -# then default to PYBV10. +# Select the board to build for: +ifdef BOARD_DIR +# Custom board path - remove trailing slash and get the final component of +# the path as the board name. +BOARD ?= $(notdir $(BOARD_DIR:/=)) +else +# If not given on the command line, then default to PYBV10. BOARD ?= PYBV10 +BOARD_DIR ?= $(abspath ../boards/$(BOARD)) +endif # If the build directory is not given, make it reflect the board name. BUILD ?= build-$(BOARD) -# Allow the directory containing the board configuration to be specified -BOARD_DIR ?= $(abspath ../boards/$(BOARD)) - # Set USE_MBOOT to 1 so that TEXT0_ADDR gets set properly for those boards # that can be built with or without mboot. USE_MBOOT ?= 1 diff --git a/ports/unix/Makefile b/ports/unix/Makefile index 8e9094b40c..403405dcc2 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -1,14 +1,21 @@ -# Select the variant to build for. +# Select the variant to build for: +ifdef VARIANT_DIR +# Custom variant path - remove trailing slash and get the final component of +# the path as the variant name. +VARIANT ?= $(notdir $(VARIANT_DIR:/=)) +else +# If not given on the command line, then default to standard. VARIANT ?= standard - -# If the build directory is not given, make it reflect the variant name. -BUILD ?= build-$(VARIANT) - VARIANT_DIR ?= variants/$(VARIANT) +endif + ifeq ($(wildcard $(VARIANT_DIR)/.),) $(error Invalid VARIANT specified: $(VARIANT_DIR)) endif +# If the build directory is not given, make it reflect the variant name. +BUILD ?= build-$(VARIANT) + include ../../py/mkenv.mk -include mpconfigport.mk include $(VARIANT_DIR)/mpconfigvariant.mk diff --git a/ports/windows/Makefile b/ports/windows/Makefile index e7f0f2ff61..b366e03bf9 100644 --- a/ports/windows/Makefile +++ b/ports/windows/Makefile @@ -1,14 +1,21 @@ -# Select the variant to build for. +# Select the variant to build for: +ifdef VARIANT_DIR +# Custom variant path - remove trailing slash and get the final component of +# the path as the variant name. +VARIANT ?= $(notdir $(VARIANT_DIR:/=)) +else +# If not given on the command line, then default to standard. VARIANT ?= standard - -# If the build directory is not given, make it reflect the variant name. -BUILD ?= build-$(VARIANT) - VARIANT_DIR ?= variants/$(VARIANT) +endif + ifeq ($(wildcard $(VARIANT_DIR)/.),) $(error Invalid VARIANT specified: $(VARIANT_DIR)) endif +# If the build directory is not given, make it reflect the variant name. +BUILD ?= build-$(VARIANT) + include ../../py/mkenv.mk -include mpconfigport.mk include $(VARIANT_DIR)/mpconfigvariant.mk