Skip to content

Commit 28f1878

Browse files
committed
py/py.mk: Enable file for USER_C_MODULES build.
This enables setting a file path to select user C modules in a USER_C_MODULES directory, the same way CMake works. The file is a simple .txt with the user modules required, e.g. USER_C_MODULES=<path/to/user_modules>/my_user_modules.txt in my_user_modules.txt: module_foo module_bar Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
1 parent f1018ee commit 28f1878

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

py/py.mk

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,16 @@ ifneq ($(USER_C_MODULES),)
3434
# expanded as they're added to them
3535

3636
# Confirm the provided path exists, show abspath if not to make it clearer to fix.
37-
$(if $(wildcard $(USER_C_MODULES)/.),,$(error USER_C_MODULES doesn't exist: $(abspath $(USER_C_MODULES))))
37+
ifeq ($(wildcard $(USER_C_MODULES)/.),)
3838

39+
# Check if the provided path is a file
40+
ifeq ($(wildcard $(USER_C_MODULES)),)
41+
$(error USER_C_MODULES doesn't exist: $(abspath $(USER_C_MODULES)))
42+
else
43+
MODULE_PATHS := $(strip $(shell cat $(USER_C_MODULES) | grep .))
44+
$(info USER_C_MODULES found in $(USER_C_MODULES): $(MODULE_PATHS))
45+
endif
46+
endif
3947
# C/C++ files that are included in the QSTR/module build
4048
SRC_USERMOD_C :=
4149
SRC_USERMOD_CXX :=
@@ -52,12 +60,24 @@ LDFLAGS_USERMOD :=
5260
# added to SRC_USERMOD_C below
5361
SRC_USERMOD :=
5462

63+
ifneq ($(MODULE_PATHS),)
64+
65+
$(foreach module, $(MODULE_PATHS), \
66+
$(eval USERMOD_DIR = $(patsubst %/,%,$(dir $(USER_C_MODULES))$(module)))\
67+
$(info Including User C Module from $(USERMOD_DIR))\
68+
$(eval include $(USERMOD_DIR)/micropython.mk)\
69+
)
70+
USER_C_MODULES := $(patsubst %/,%,$(dir $(USER_C_MODULES)))
71+
72+
else
5573
$(foreach module, $(wildcard $(USER_C_MODULES)/*/micropython.mk), \
5674
$(eval USERMOD_DIR = $(patsubst %/,%,$(dir $(module))))\
5775
$(info Including User C Module from $(USERMOD_DIR))\
5876
$(eval include $(module))\
5977
)
6078

79+
endif
80+
6181
SRC_USERMOD_C += $(SRC_USERMOD)
6282

6383
SRC_USERMOD_PATHFIX_C += $(patsubst $(USER_C_MODULES)/%.c,%.c,$(SRC_USERMOD_C))

0 commit comments

Comments
 (0)