8000 esp32/Makefile: Implement `make submodules` to match other ports. · jimmo/micropython@ad123ed · GitHub
[go: up one dir, main page]

Skip to content

Commit ad123ed

Browse files
committed
esp32/Makefile: Implement make submodules to match other ports.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent fa1ea21 commit ad123ed

File tree

5 files changed

+79
-50
lines changed

5 files changed

+79
-50
lines changed

extmod/extmod.cmake

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -60,51 +60,62 @@ set(MICROPY_SOURCE_EXTMOD
6060

6161
if(MICROPY_PY_BTREE)
6262
set(MICROPY_LIB_BERKELEY_DIR "${MICROPY_DIR}/lib/berkeley-db-1.xx")
63+
string(CONCAT GIT_SUBMODULES "${GIT_SUBMODULES} " lib/berkeley-db-1.xx)
6364

64-
add_library(micropy_extmod_btree OBJECT
65-
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_close.c
66-
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_conv.c
67-
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_debug.c
68-
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_delete.c
69-
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_get.c
70-
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_open.c
71-
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_overflow.c
72-
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_page.c
73-
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_put.c
74-
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_search.c
75-
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_seq.c
76-
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_split.c
77-
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_utils.c
78-
${MICROPY_LIB_BERKELEY_DIR}/mpool/mpool.c
79-
)
65+
if(ECHO_SUBMODULES OR ECHO_QUERY_VARIANTS)
66+
# No-op, we're just doing submodule/variant discovery.
67+
# Cannot run the add_library/target_include_directories rules (even though
68+
# the build won't run) because IDF will attempt verify the files exist.
69+
elseif(NOT EXISTS ${MICROPY_LIB_BERKELEY_DIR}/README)
70+
# Regular build, submodule not initialised -- fail with a clear error.
71+
message(FATAL_ERROR " MICROPY_PY_BTREE is enabled but the berkeley-db submodule is not initialised.\n Run 'make BOARD=${MICROPY_BOARD} submodules'")
72+
else()
73+
# Regular build, we have the submodule.
74+
add_library(micropy_extmod_btree OBJECT
75+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_close.c
76+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_conv.c
77+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_debug.c
78+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_delete.c
79+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_get.c
80+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_open.c
81+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_overflow.c
82+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_page.c
83+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_put.c
84+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_search.c
85+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_seq.c
86+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_split.c
87+
${MICROPY_LIB_BERKELEY_DIR}/btree/bt_utils.c
88+
${MICROPY_LIB_BERKELEY_DIR}/mpool/mpool.c
89+
)
8090

81-
target_include_directories(micropy_extmod_btree PRIVATE
82-
${MICROPY_LIB_BERKELEY_DIR}/PORT/include
83-
)
91+
target_include_directories(micropy_extmod_btree PRIVATE
92+
${MICROPY_LIB_BERKELEY_DIR}/PORT/include
93+
)
8494

85-
target_compile_definitions(micropy_extmod_btree PRIVATE
86-
__DBINTERFACE_PRIVATE=1
87-
mpool_error=printf
88-
abort=abort_
89-
"virt_fd_t=void*"
90-
)
95+
target_compile_definitions(micropy_extmod_btree PRIVATE
96+
__DBINTERFACE_PRIVATE=1
97+
mpool_error=printf
98+
abort=abort_
99+
"virt_fd_t=void*"
100+
)
91101

92-
# The include directories and compile definitions below are needed to build
93-
# modbtree.c and should be added to the main MicroPython target.
102+
# The include directories and compile definitions below are needed to build
103+
# modbtree.c and should be added to the main MicroPython target.
94104

95-
list(APPEND MICROPY_INC_CORE
96-
"${MICROPY_LIB_BERKELEY_DIR}/PORT/include"
97-
)
105+
list(APPEND MICROPY_INC_CORE
106+
"${MICROPY_LIB_BERKELEY_DIR}/PORT/include"
107+
)
98108

99-
list(APPEND MICROPY_DEF_CORE
100-
MICROPY_PY_BTREE=1
101-
__DBINTERFACE_PRIVATE=1
102-
"virt_fd_t=void*"
103-
)
109+
list(APPEND MICROPY_DEF_CORE
110+
MICROPY_PY_BTREE=1
111+
__DBINTERFACE_PRIVATE=1
112+
"virt_fd_t=void*"
113+
)
104114

105-
list(APPEND MICROPY_SOURCE_EXTMOD
106-
${MICROPY_EXTMOD_DIR}/modbtree.c
107-
)
115+
list(APPEND MICROPY_SOURCE_EXTMOD
116+
${MICROPY_EXTMOD_DIR}/modbtree.c
117+
)
118+
endif()
108119
endif()
109120

110121
# Library for mbedtls

ports/esp32/Makefile

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ BAUD ?= 460800
2626

2727
PYTHON ?= python3
2828

29-
# Would be good to use cmake to discover submodules (see how rp2/Makefile does
30-
# it), but on ESP32 the same trick doesn't work because "idf.py build" fails
31-
# on berkeley-db dependency before printing out the submodule list.
32-
# For now just force the submodule dependencies here.
33-
GIT_SUBMODULES += lib/berkeley-db-1.xx lib/micropython-lib
34-
3529
.PHONY: all clean deploy erase submodules FORCE
3630

3731
CMAKE_ARGS =
@@ -40,20 +34,24 @@ ifdef USER_C_MODULES
4034
CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES}
4135
endif
4236

43-
IDFPY_FLAGS += -D MICROPY_BOARD=$(BOARD) -D MICROPY_BOARD_DIR=$(abspath $(BOARD_DIR)) -B $(BUILD) $(CMAKE_ARGS)
37+
IDFPY_FLAGS += -D MICROPY_BOARD=$(BOARD) -D MICROPY_BOARD_DIR=$(abspath $(BOARD_DIR)) $(CMAKE_ARGS)
4438

4539
ifdef FROZEN_MANIFEST
4640
IDFPY_FLAGS += -D MICROPY_FROZEN_MANIFEST=$(FROZEN_MANIFEST)
4741
endif
4842

43+
ifdef BOARD_VARIANT
44+
IDFPY_FLAGS += -D MICROPY_BOARD_VARIANT=$(BOARD_VARIANT)
45+
endif
46+
4947
HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"
5048

5149
define RUN_IDF_PY
52-
idf.py $(IDFPY_FLAGS) -p $(PORT) -b $(BAUD) $(1)
50+
idf.py $(IDFPY_FLAGS) -B $(BUILD) -p $(PORT) -b $(BAUD) $(1)
5351
endef
5452

5553
all:
56-
idf.py $(IDFPY_FLAGS) build || (echo -e $(HELP_BUILD_ERROR); false)
54+
idf.py $(IDFPY_FLAGS) -B $(BUILD) build || (echo -e $(HELP_BUILD_ERROR); false)
5755
@$(PYTHON) makeimg.py \
5856
$(BUILD)/sdkconfig \
5957
$(BUILD)/bootloader/bootloader.bin \
@@ -85,5 +83,12 @@ size-components:
8583
size-files:
8684
$(call RUN_IDF_PY,size-files)
8785

86+
# Running the build with ECHO_SUBMODULES set will trigger py/mkrules.cmake to
87+
# print out the value of the GIT_SUBMODULES variable, prefixed with
88+
# "GIT_SUBMODULES", and then abort. This extracts out that line from the idf.py
89+
# output and passes the list of submodules to py/mkrules.mk which does the
90+
# `git submodule init` on each.
8891
submodules:
89-
$(MAKE) -f ../../py/mkrules.mk GIT_SUBMODULES="$(GIT_SUBMODULES)" submodules
92+
@GIT_SUBMODULES=$$(idf.py $(IDFPY_FLAGS) -B $(BUILD)/submodules -D ECHO_SUBMODULES=1 build 2>&1 | \
93+
grep '^GIT_SUBMODULES=' | cut -d= -f2); \
94+
$(MAKE) -f ../../py/mkrules.mk GIT_SUBMODULES="$${GIT_SUBMODULES}" submodules

ports/esp32/esp32_common.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ endif()
1111
# Include core source components.
1212
include(${MICROPY_DIR}/py/py.cmake)
1313

14+
# CMAKE_BUILD_EARLY_EXPANSION is set during the component-discovery phase of
15+
# `idf.py build`, so none of the extmod/usermod (and in reality, most of the
16+
# micropython) rules need to happen. Specifically, you cannot invoke add_library.
1417
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
1518
# Enable extmod components that will be configured by extmod.cmake.
1619
# A board may also have enabled additional components.

ports/rp2/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ clean:
5050

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

py/mkrules.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,12 @@ if(MICROPY_FROZEN_MANIFEST)
178178
set(MICROPY_LIB_DIR ${MICROPY_DIR}/lib/micropython-lib)
179179
endif()
180180

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

0 commit comments

Comments
 (0)
0