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,51 +60,62 @@ set(MICROPY_SOURCE_EXTMOD
if(MICROPY_PY_BTREE) if(MICROPY_PY_BTREE)
set(MICROPY_LIB_BERKELEY_DIR "${MICROPY_DIR}/lib/berkeley-db-1.xx") set(MICROPY_LIB_BERKELEY_DIR "${MICROPY_DIR}/lib/berkeley-db-1.xx")
string(CONCAT GIT_SUBMODULES "${GIT_SUBMODULES} " lib/berkeley-db-1.xx)
add_library(micropy_extmod_btree OBJECT if(ECHO_SUBMODULES OR ECHO_QUERY_VARIANTS)
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_close.c # No-op, we're just doing submodule/variant discovery.
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_conv.c # Cannot run the add_library/target_include_directories rules (even though
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_debug.c # the build won't run) because IDF will attempt verify the files exist.
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_delete.c elseif(NOT EXISTS ${MICROPY_LIB_BERKELEY_DIR}/README)
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_get.c # Regular build, submodule not initialised -- fail with a clear error.
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_open.c message(FATAL_ERROR " MICROPY_PY_BTREE is enabled but the berkeley-db submodule is not initialised.\n Run 'make BOARD=${MICROPY_BOARD} submodules'")
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_overflow.c else()
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_page.c # Regular build, we have the submodule.
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_put.c add_library(micropy_extmod_btree OBJECT
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_search.c ${MICROPY_LIB_BERKELEY_DIR}/btree/bt_close.c
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_seq.c ${MICROPY_LIB_BERKELEY_DIR}/btree/bt_conv.c
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_split.c ${MICROPY_LIB_BERKELEY_DIR}/btree/bt_debug.c
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_utils.c ${MICROPY_LIB_BERKELEY_DIR}/btree/bt_delete.c
${MICROPY_LIB_BERKELEY_DIR}/mpool/mpool.c ${MICROPY_LIB_BERKELEY_DIR}/btree/bt_get.c
) ${MICROPY_LIB_BERKELEY_DIR}/btree/bt_open.c
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_overflow.c
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_page.c
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_put.c
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_search.c
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_seq.c
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_split.c
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_utils.c
${MICROPY_LIB_BERKELEY_DIR}/mpool/mpool.c
)
target_include_directories(micropy_extmod_btree PRIVATE target_include_directories(micropy_extmod_btree PRIVATE
${MICROPY_LIB_BERKELEY_DIR}/PORT/include ${MICROPY_LIB_BERKELEY_DIR}/PORT/include
) )
target_compile_definitions(micropy_extmod_btree PRIVATE target_compile_definitions(micropy_extmod_btree PRIVATE
__DBINTERFACE_PRIVATE=1 __DBINTERFACE_PRIVATE=1
mpool_error=printf mpool_error=printf
abort=abort_ abort=abort_
"virt_fd_t=void*" "virt_fd_t=void*"
) )
# The include directories and compile definitions below are needed to build # The include directories and compile definitions below are needed to build
# modbtree.c and should be added to the main MicroPython target. # modbtree.c and should be added to the main MicroPython target.
list(APPEND MICROPY_INC_CORE list(APPEND MICROPY_INC_CORE
"${MICROPY_LIB_BERKELEY_DIR}/PORT/include" "${MICROPY_LIB_BERKELEY_DIR}/PORT/include"
) )
list(APPEND MICROPY_DEF_CORE list(APPEND MICROPY_DEF_CORE
MICROPY_PY_BTREE=1 MICROPY_PY_BTREE=1
__DBINTERFACE_PRIVATE=1 __DBINTERFACE_PRIVATE=1
"virt_fd_t=void*" "virt_fd_t=void*"
) )
list(APPEND MICROPY_SOURCE_EXTMOD list(APPEND MICROPY_SOURCE_EXTMOD
${MICROPY_EXTMOD_DIR}/modbtree.c ${MICROPY_EXTMOD_DIR}/modbtree.c
) )
endif()
endif() endif()
# Library for mbedtls # Library for mbedtls

View File

@ -26,12 +26,6 @@ BAUD ?= 460800
PYTHON ?= python3 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 .PHONY: all clean deploy erase submodules FORCE
CMAKE_ARGS = CMAKE_ARGS =
@ -40,20 +34,24 @@ ifdef USER_C_MODULES
CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES} CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES}
endif 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 ifdef FROZEN_MANIFEST
IDFPY_FLAGS += -D MICROPY_FROZEN_MANIFEST=$(FROZEN_MANIFEST) IDFPY_FLAGS += -D MICROPY_FROZEN_MANIFEST=$(FROZEN_MANIFEST)
endif 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" HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"
define RUN_IDF_PY 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 endef
all: 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 \ @$(PYTHON) makeimg.py \
$(BUILD)/sdkconfig \ $(BUILD)/sdkconfig \
$(BUILD)/bootloader/bootloader.bin \ $(BUILD)/bootloader/bootloader.bin \
@ -85,5 +83,12 @@ size-components:
size-files: size-files:
$(call RUN_IDF_PY,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: 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 core source components.
include(${MICROPY_DIR}/py/py.cmake) 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) if(NOT CMAKE_BUILD_EARLY_EXPANSION)
# Enable extmod components that will be configured by extmod.cmake. # Enable extmod components that will be configured by extmod.cmake.
# A board may also have enabled additional components. # 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 # First ensure that pico-sdk is initialised, then use cmake to pick everything
# else (including board-specific dependencies). # 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: submodules:
$(MAKE) -f ../../py/mkrules.mk GIT_SUBMODULES="lib/pico-sdk" 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); \ grep '^GIT_SUBMODULES=' | cut -d= -f2); \
$(MAKE) -f ../../py/mkrules.mk GIT_SUBMODULES="$${GIT_SUBMODULES}" submodules $(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) set(MICROPY_LIB_DIR ${MICROPY_DIR}/lib/micropython-lib)
endif() 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'") message(FATAL_ERROR " micropython-lib not initialized.\n Run 'make BOARD=${MICROPY_BOARD} submodules'")
endif() endif()