esp32/Makefile: Implement `make submodules` to match other ports.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2023-07-31 17:24:38 +10:00
parent fa1ea21f75
commit ad123ed013
5 changed files with 79 additions and 50 deletions

View File

@ -60,7 +60,17 @@ set(MICROPY_SOURCE_EXTMOD
if(MICROPY_PY_BTREE)
set(MICROPY_LIB_BERKELEY_DIR "${MICROPY_DIR}/lib/berkeley-db-1.xx")
string(CONCAT GIT_SUBMODULES "${GIT_SUBMODULES} " lib/berkeley-db-1.xx)
if(ECHO_SUBMODULES OR ECHO_QUERY_VARIANTS)
# No-op, we're just doing submodule/variant discovery.
# Cannot run the add_library/target_include_directories rules (even though
# the build won't run) because IDF will attempt verify the files exist.
elseif(NOT EXISTS ${MICROPY_LIB_BERKELEY_DIR}/README)
# Regular build, submodule not initialised -- fail with a clear error.
message(FATAL_ERROR " MICROPY_PY_BTREE is enabled but the berkeley-db submodule is not initialised.\n Run 'make BOARD=${MICROPY_BOARD} submodules'")
else()
# Regular build, we have the submodule.
add_library(micropy_extmod_btree OBJECT
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_close.c
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_conv.c
@ -105,6 +115,7 @@ if(MICROPY_PY_BTREE)
list(APPEND MICROPY_SOURCE_EXTMOD
${MICROPY_EXTMOD_DIR}/modbtree.c
)
endif()
endif()
# Library for mbedtls

View File

@ -26,12 +26,6 @@ BAUD ?= 460800
PYTHON ?= python3
# Would be good to use cmake to discover submodules (see how rp2/Makefile does
# it), but on ESP32 the same trick doesn't work because "idf.py build" fails
# on berkeley-db dependency before printing out the submodule list.
# For now just force the submodule dependencies here.
GIT_SUBMODULES += lib/berkeley-db-1.xx lib/micropython-lib
.PHONY: all clean deploy erase submodules FORCE
CMAKE_ARGS =
@ -40,20 +34,24 @@ ifdef USER_C_MODULES
CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES}
endif
IDFPY_FLAGS += -D MICROPY_BOARD=$(BOARD) -D MICROPY_BOARD_DIR=$(abspath $(BOARD_DIR)) -B $(BUILD) $(CMAKE_ARGS)
IDFPY_FLAGS += -D MICROPY_BOARD=$(BOARD) -D MICROPY_BOARD_DIR=$(abspath $(BOARD_DIR)) $(CMAKE_ARGS)
ifdef FROZEN_MANIFEST
IDFPY_FLAGS += -D MICROPY_FROZEN_MANIFEST=$(FROZEN_MANIFEST)
endif
ifdef BOARD_VARIANT
IDFPY_FLAGS += -D MICROPY_BOARD_VARIANT=$(BOARD_VARIANT)
endif
HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"
define RUN_IDF_PY
idf.py $(IDFPY_FLAGS) -p $(PORT) -b $(BAUD) $(1)
idf.py $(IDFPY_FLAGS) -B $(BUILD) -p $(PORT) -b $(BAUD) $(1)
endef
all:
idf.py $(IDFPY_FLAGS) build || (echo -e $(HELP_BUILD_ERROR); false)
idf.py $(IDFPY_FLAGS) -B $(BUILD) build || (echo -e $(HELP_BUILD_ERROR); false)
@$(PYTHON) makeimg.py \
$(BUILD)/sdkconfig \
$(BUILD)/bootloader/bootloader.bin \
@ -85,5 +83,12 @@ size-components:
size-files:
$(call RUN_IDF_PY,size-files)
# Running the build with ECHO_SUBMODULES set will trigger py/mkrules.cmake to
# print out the value of the GIT_SUBMODULES variable, prefixed with
# "GIT_SUBMODULES", and then abort. This extracts out that line from the idf.py
# output and passes the list of submodules to py/mkrules.mk which does the
# `git submodule init` on each.
submodules:
$(MAKE) -f ../../py/mkrules.mk GIT_SUBMODULES="$(GIT_SUBMODULES)" submodules
@GIT_SUBMODULES=$$(idf.py $(IDFPY_FLAGS) -B $(BUILD)/submodules -D ECHO_SUBMODULES=1 build 2>&1 | \
grep '^GIT_SUBMODULES=' | cut -d= -f2); \
$(MAKE) -f ../../py/mkrules.mk GIT_SUBMODULES="$${GIT_SUBMODULES}" submodules

View File

@ -11,6 +11,9 @@ endif()
# Include core source components.
include(${MICROPY_DIR}/py/py.cmake)
# CMAKE_BUILD_EARLY_EXPANSION is set during the component-discovery phase of
# `idf.py build`, so none of the extmod/usermod (and in reality, most of the
# micropython) rules need to happen. Specifically, you cannot invoke add_library.
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
# Enable extmod components that will be configured by extmod.cmake.
# A board may also have enabled additional components.

View File

@ -50,9 +50,14 @@ clean:
# First ensure that pico-sdk is initialised, then use cmake to pick everything
# else (including board-specific dependencies).
# Running the build with ECHO_SUBMODULES set will trigger py/mkrules.cmake to
# print out the value of the GIT_SUBMODULES variable, prefixed with
# "GIT_SUBMODULES", and then abort. This extracts out that line from the cmake
# output and passes the list of submodules to py/mkrules.mk which does the
# `git submodule init` on each.
submodules:
$(MAKE) -f ../../py/mkrules.mk GIT_SUBMODULES="lib/pico-sdk" submodules
GIT_SUBMODULES=$$(cmake -B $(BUILD)/submodules -DECHO_SUBMODULES=1 ${CMAKE_ARGS} -S . 2>&1 | \
@GIT_SUBMODULES=$$(cmake -B $(BUILD)/submodules -DECHO_SUBMODULES=1 ${CMAKE_ARGS} -S . 2>&1 | \
grep '^GIT_SUBMODULES=' | cut -d= -f2); \
$(MAKE) -f ../../py/mkrules.mk GIT_SUBMODULES="$${GIT_SUBMODULES}" submodules

View File

@ -178,7 +178,12 @@ if(MICROPY_FROZEN_MANIFEST)
set(MICROPY_LIB_DIR ${MICROPY_DIR}/lib/micropython-lib)
endif()
if(NOT (${ECHO_SUBMODULES}) AND NOT EXISTS ${MICROPY_LIB_DIR}/README.md)
if(ECHO_SUBMODULES OR ECHO_QUERY_VARIANTS)
# No-op, we're just doing submodule/variant discovery.
# Note: All the following rules are safe to run in discovery mode even
# though the submodule might not be available as they do not directly depend
# on anything from the submodule.
elseif(NOT EXISTS ${MICROPY_LIB_DIR}/README.md)
message(FATAL_ERROR " micropython-lib not initialized.\n Run 'make BOARD=${MICROPY_BOARD} submodules'")
endif()