8000 py/py.mk: Enable makefile for USER_C_MODULES path. · micropython/micropython@4e637e7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e637e7

Browse files
committed
py/py.mk: Enable makefile for USER_C_MODULES path.
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 .mk file with the user modules required. USER_C_MODULES=<path/to/file>/my_user_modules.mk in my_user_modules.mk: USER_C_MODULES=<path/to/user_modules> MODULE_PATHS := module_foo MODULE_PATHS += module_bar MODULE_PATHS += module_bar/submodule Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
1 parent f1018ee commit 4e637e7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

py/py.mk

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,17 @@ 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+
# USER_C_MODULES is a .mk file
44+
$(eval include $(USER_C_MODULES))
45+
$(info USER_C_MODULES found in $(USER_C_MODULES): $(MODULE_PATHS))
46+
endif
47+
endif
3948
# C/C++ files that are included in the QSTR/module build
4049
SRC_USERMOD_C :=
4150
SRC_USERMOD_CXX :=
@@ -52,12 +61,24 @@ LDFLAGS_USERMOD :=
5261
# added to SRC_USERMOD_C below
5362
SRC_USERMOD :=
5463

64+
ifneq ($(MODULE_PATHS),)
65+
66+
$(foreach module, $(MODULE_PATHS), \
67+
$(eval USERMOD_DIR = $(patsubst %/,%,$(USER_C_MODULES))/$(module))\
68+
$(info Including User C Module from $(USERMOD_DIR))\
69+
$(eval include $(USERMOD_DIR)/micropython.mk)\
70+
)
71+
USER_C_MODULES := $(patsubst %/,%,$(USER_C_MODULES))
72+
73+
else
5574
$(foreach module, $(wildcard $(USER_C_MODULES)/*/micropython.mk), \
5675
$(eval USERMOD_DIR = $(patsubst %/,%,$(dir $(module))))\
5776
$(info Including User C Module from $(USERMOD_DIR))\
5877
$(eval include $(module))\
5978
)
6079

80+
endif
81+
6182
SRC_USERMOD_C += $(SRC_USERMOD)
6283

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

0 commit comments

Comments
 (0)
0