8000 py/py.mk: Enable file for USER_C_MODULES build. · micropython/micropython@a11c637 · GitHub
[go: up one dir, main page]

Skip to content

Commit a11c637

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 .mk file with the user modules required. USER_C_MODULES=<path/to/file>/user_c_modules.mk See examples/usercmodule/user_c_modules.mk for reference Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
1 parent fa393fe commit a11c637

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

docs/develop/cmodules.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ To build such a module, compile MicroPython (see `getting started
127127
applying 2 modifications:
128128

129129
1. Set the build-time flag ``USER_C_MODULES`` to point to the modules
130-
you want to include. For ports that use Make this variable should be a
131-
directory which is searched automatically for modules. For ports that
130+
you want to include. For ports that use Make this variable can be a
131+
directory which is searched automatically for modules or a Makefile that
132+
includes the modules to build. For ports that
132133
use CMake this variable should be a file which includes the modules to
133134
build. See below for details.
134135

@@ -147,6 +148,13 @@ For example, here's how the to build the unix port with the example modules:
147148
cd micropython/ports/unix
148149
make USER_C_MODULES=../../examples/usercmodule
149150
151+
or
152+
153+
.. code-block:: bash
154+
155+
cd micropython/ports/unix
156+
make USER_C_MODULES=../../examples/usercmodule/user_c_modules.mk
157+
150158
You may need to run ``make clean`` once at the start when including new
151159
user modules in the build. The build output will show the modules found::
152160

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
MODULES_PATH := ../../examples/usercmodule
2+
MODULES := cexample
3+
MODULES += cppexample
4+
MODULES += subpackage
5+
6+
$(info USER_C_MODULES found in $(MODULES_PATH): $(MODULES))
7+
$(foreach module, $(MODULES), \
8+
$(eval USERMOD_DIR = $(patsubst %/,%,$(MODULES_PATH))/$(module))\
9+
$(info Including User C Module from $(USERMOD_DIR))\
10+
$(eval include $(USERMOD_DIR)/micropython.mk)\
11+
)
12+

py/py.mk

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ LD += -m32
2929
endif
3030

3131
# External modules written in C.
32-
ifneq ($(USER_C_MODULES),)
33-
# pre-define USERMOD variables as expanded so that variables are immediate
34-
# expanded as they're added to them
35-
36-
# 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))))
38-
3932
# C/C++ files that are included in the QSTR/module build
4033
SRC_USERMOD_C :=
4134
SRC_USERMOD_CXX :=
@@ -52,11 +45,33 @@ LDFLAGS_USERMOD :=
5245
# added to SRC_USERMOD_C below
5346
SRC_USERMOD :=
5447

48+
ifneq ($(USER_C_MODULES),)
49+
# pre-define USERMOD variables as expanded so that variables are immediate
50+
# expanded as they're added to them
51+
52+
# Confirm the provided path exists, show abspath if not to make it clearer to fix.
53+
ifeq ($(wildcard $(USER_C_MODULES)/.),)
54+
55+
# Check if the provided path is a file
56+
ifeq ($(wildcard $(USER_C_MODULES)),)
57+
$(error USER_C_MODULES doesn't exist: $(abspath $(USER_C_MODULES)))
58+
59+
# USER_C_MODULES is a .mk file
60+
else
61+
USER_C_MODULES_PATH := $(dir $(USER_C_MODULES))
62+
$(eval include $(USER_C_MODULES))
63+
64+
USER_C_MODULES := $(patsubst %/,%,$(USER_C_MODULES_PATH))
65+
66+
endif
67+
68+
else
5569
$(foreach module, $(wildcard $(USER_C_MODULES)/*/micropython.mk), \
5670
$(eval USERMOD_DIR = $(patsubst %/,%,$(dir $(module))))\
5771
$(info Including User C Module from $(USERMOD_DIR))\
5872
$(eval include $(module))\
5973
)
74+
endif
6075

6176
SRC_USERMOD_C += $(SRC_USERMOD)
6277

0 commit comments

Comments
 (0)
0