From c3c1717813808563b9a5f3cd6072d93eb7ba401e Mon Sep 17 00:00:00 2001 From: MicroDev <70126934+MicroDev1@users.noreply.github.com> Date: Fri, 18 Nov 2022 23:00:28 +0530 Subject: [PATCH] refactor common port specific Makefile code --- ports/atmel-samd/Makefile | 40 +--------------------- ports/broadcom/Makefile | 62 +++++++++++++-------------------- ports/cxd56/Makefile | 43 +---------------------- ports/espressif/Makefile | 46 +------------------------ ports/litex/Makefile | 41 +--------------------- ports/mimxrt10xx/Makefile | 40 +--------------------- ports/nrf/Makefile | 45 +++--------------------- ports/raspberrypi/Makefile | 40 +--------------------- ports/stm/Makefile | 41 +--------------------- py/circuitpy_mkenv.mk | 70 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 106 insertions(+), 362 deletions(-) create mode 100644 py/circuitpy_mkenv.mk diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index d27a048399..fdfb6c81b8 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -22,45 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -define show_board_error -boardlist = -$(info Valid boards:) -$(shell printf '%s\n' $(patsubst boards/%/mpconfigboard.mk,%,$(wildcard boards/*/mpconfigboard.mk)) | column -xc $$(tput cols || echo 80) 1>&2) -$(error Rerun with $(MAKE) BOARD=) -endef - -ifeq ($(BOARD),) - $(info No BOARD specified) - $(call show_board_error) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(info Invalid BOARD specified) - $(call show_board_error) - endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk CROSS_COMPILE = arm-none-eabi- diff --git a/ports/broadcom/Makefile b/ports/broadcom/Makefile index ca516958e0..cbd072e833 100644 --- a/ports/broadcom/Makefile +++ b/ports/broadcom/Makefile @@ -1,42 +1,28 @@ -# Select the board to build for. -define show_board_error -boardlist = -$(info Valid boards:) -$(shell printf '%s\n' $(patsubst boards/%/mpconfigboard.mk,%,$(wildcard boards/*/mpconfigboard.mk)) | column -xc $$(tput cols || echo 80) 1>&2) -$(error Rerun with $(MAKE) BOARD=) -endef +# This file is part of the MicroPython project, http://micropython.org/ +# +# The MIT License (MIT) +# +# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. -ifeq ($(BOARD),) - $(info No BOARD specified) - $(call show_board_error) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(info Invalid BOARD specified) - $(call show_board_error) - endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk ifeq ($(CHIP_VARIANT), "bcm2711") CFLAGS += -mcpu=cortex-a72 -DBCM_VERSION=2711 diff --git a/ports/cxd56/Makefile b/ports/cxd56/Makefile index 208d3222b0..389b8a7fe6 100644 --- a/ports/cxd56/Makefile +++ b/ports/cxd56/Makefile @@ -22,48 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -define show_board_error -boardlist = -$(info Valid boards:) -$(shell printf '%s\n' $(patsubst boards/%/mpconfigboard.mk,%,$(wildcard boards/*/mpconfigboard.mk)) | column -xc $$(tput cols || echo 80) 1>&2) -$(error Rerun with $(MAKE) BOARD=) -endef - -ifeq ($(BOARD),) - $(info No BOARD specified) - $(call show_board_error) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(info Invalid BOARD specified) - $(call show_board_error) - endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk - -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk - -# Port-specific -include mpconfigport.mk - -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk CROSS_COMPILE = arm-none-eabi- diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index 331e443561..b197195aa2 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -22,51 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -define show_board_error -boardlist = -$(info Valid boards:) -$(shell printf '%s\n' $(patsubst boards/%/mpconfigboard.mk,%,$(wildcard boards/*/mpconfigboard.mk)) | column -xc $$(tput cols || echo 80) 1>&2) -$(error Rerun with $(MAKE) BOARD=) -endef - -ifeq ($(BOARD),) - $(info No BOARD specified) - $(call show_board_error) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(info Invalid BOARD specified) - $(call show_board_error) - endif -endif - -# If the flash PORT is not given, use the default /dev/tty.SLAB_USBtoUART. -PORT ?= /dev/tty.SLAB_USBtoUART - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk - -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk - -# Port-specific -include mpconfigport.mk - -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk ifeq ($(IDF_TARGET),esp32c3) IDF_TARGET_ARCH = riscv diff --git a/ports/litex/Makefile b/ports/litex/Makefile index 3281977657..1c5c0a014e 100644 --- a/ports/litex/Makefile +++ b/ports/litex/Makefile @@ -22,46 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -define show_board_error -boardlist = -$(info Valid boards:) -$(shell printf '%s\n' $(patsubst boards/%/mpconfigboard.mk,%,$(wildcard boards/*/mpconfigboard.mk)) | column -xc $$(tput cols || echo 80) 1>&2) -$(error Rerun with $(MAKE) BOARD=) -endef - -ifeq ($(BOARD),) - $(info No BOARD specified) - $(call show_board_error) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(info Invalid BOARD specified) - $(call show_board_error) - endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk - -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk CROSS_COMPILE = riscv64-unknown-elf- diff --git a/ports/mimxrt10xx/Makefile b/ports/mimxrt10xx/Makefile index 2dda646882..1c5c62bb85 100644 --- a/ports/mimxrt10xx/Makefile +++ b/ports/mimxrt10xx/Makefile @@ -23,45 +23,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -define show_board_error -boardlist = -$(info Valid boards:) -$(shell printf '%s\n' $(patsubst boards/%/mpconfigboard.mk,%,$(wildcard boards/*/mpconfigboard.mk)) | column -xc $$(tput cols || echo 80) 1>&2) -$(error Rerun with $(MAKE) BOARD=) -endef - -ifeq ($(BOARD),) - $(info No BOARD specified) - $(call show_board_error) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(info Invalid BOARD specified) - $(call show_board_error) - endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk CROSS_COMPILE = arm-none-eabi- diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 2dbc582022..22cfd474ce 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -22,51 +22,16 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -define show_board_error -boardlist = -$(info Valid boards:) -$(shell printf '%s\n' $(patsubst boards/%/mpconfigboard.mk,%,$(wildcard boards/*/mpconfigboard.mk)) | column -xc $$(tput cols || echo 80) 1>&2) -$(error Rerun with $(MAKE) BOARD=) -endef +include ../../py/circuitpy_mkenv.mk -ifeq ($(BOARD),) - $(info No BOARD specified) - $(call show_board_error) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(info Invalid BOARD specified) - $(call show_board_error) - endif -endif - -CLI_SD := $(SD) SD_LOWER = $(shell echo $(SD) | tr '[:upper:]' '[:lower:]') -# Build directory with SD if it's different from the default. -BUILD ?= $(if $(CLI_SD),build-$(BOARD)-$(SD_LOWER),build-$(BOARD)) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk - ifneq ($(SD), ) include bluetooth/bluetooth_common.mk + ifeq ($(BUILD), build-$(BOARD)) + # Build directory with SD if it's different from the default. + BUILD = build-$(BOARD)-$(SD_LOWER) + endif endif CROSS_COMPILE = arm-none-eabi- diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index 151c60ba1b..06408e25c6 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -22,45 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -define show_board_error -boardlist = -$(info Valid boards:) -$(shell printf '%s\n' $(patsubst boards/%/mpconfigboard.mk,%,$(wildcard boards/*/mpconfigboard.mk)) | column -xc $$(tput cols || echo 80) 1>&2) -$(error Rerun with $(MAKE) BOARD=) -endef - -ifeq ($(BOARD),) - $(info No BOARD specified) - $(call show_board_error) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(info Invalid BOARD specified) - $(call show_board_error) - endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk CROSS_COMPILE = arm-none-eabi- diff --git a/ports/stm/Makefile b/ports/stm/Makefile index ac373cbbfa..726123a0ba 100755 --- a/ports/stm/Makefile +++ b/ports/stm/Makefile @@ -23,46 +23,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -define show_board_error -boardlist = -$(info Valid boards:) -$(shell printf '%s\n' $(patsubst boards/%/mpconfigboard.mk,%,$(wildcard boards/*/mpconfigboard.mk)) | column -xc $$(tput cols || echo 80) 1>&2) -$(error Rerun with $(MAKE) BOARD=) -endef - -ifeq ($(BOARD),) - $(info No BOARD specified) - $(call show_board_error) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(info Invalid BOARD specified) - $(call show_board_error) - endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk - -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk CROSS_COMPILE = arm-none-eabi- diff --git a/py/circuitpy_mkenv.mk b/py/circuitpy_mkenv.mk new file mode 100644 index 0000000000..d776cc2fef --- /dev/null +++ b/py/circuitpy_mkenv.mk @@ -0,0 +1,70 @@ +# This file is part of the MicroPython project, http://micropython.org/ +# +# The MIT License (MIT) +# +# SPDX-FileCopyrightText: Copyright (c) 2022 MicroDev +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# Common Makefile items that can be shared across CircuitPython ports. + +# Select the board to build for. +define show_board_error +$(info Valid boards:) +$(shell printf '%s\n' $(patsubst boards/%/mpconfigboard.mk,%,$(wildcard boards/*/mpconfigboard.mk)) | column -xc $$(tput cols || echo 80) 1>&2) +$(error Rerun with $(MAKE) BOARD=) +endef + +ifeq ($(BOARD),) + $(info No BOARD specified) + $(call show_board_error) +else + ifeq ($(wildcard boards/$(BOARD)/.),) + $(info Invalid BOARD specified) + $(call show_board_error) + endif +endif + +# If the flash PORT is not given, use the default /dev/tty.SLAB_USBtoUART. +PORT ?= /dev/tty.SLAB_USBtoUART + +# If the build directory is not given, make it reflect the board name. +BUILD ?= build-$(BOARD) + +include ../../py/mkenv.mk + +# Board-specific +include boards/$(BOARD)/mpconfigboard.mk + +# Port-specific +include mpconfigport.mk + +# CircuitPython-specific +include $(TOP)/py/circuitpy_mpconfig.mk + +# qstr definitions (must come before including py.mk) +QSTR_DEFS = qstrdefsport.h + +# include py core make definitions +include $(TOP)/py/py.mk + +include $(TOP)/supervisor/supervisor.mk + +# Include make rules and variables common across CircuitPython builds. +include $(TOP)/py/circuitpy_defns.mk