Skip to content

Commit 7549326

Browse files
authored
Update py.mk
1 parent d169823 commit 7549326

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

py/py.mk

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ $(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare
105105
$(BUILD)/extmod/modbtree.o: CFLAGS += $(BTREE_DEFS)
106106
endif
107107

108+
# External modules written in C.
109+
ifneq ($(USER_C_MODULES),)
110+
# pre-define USERMOD variables as expanded so that variables are immediate
111+
# expanded as they're added to them
112+
SRC_USERMOD :=
113+
CFLAGS_USERMOD :=
114+
LDFLAGS_USERMOD :=
115+
$(foreach module, $(wildcard $(USER_C_MODULES)/*/micropython.mk), \
116+
$(eval USERMOD_DIR = $(patsubst %/,%,$(dir $(module))))\
117+
$(info Including User C Module from $(USERMOD_DIR))\
118+
$(eval include $(module))\
119+
)
120+
121+
SRC_MOD += $(patsubst $(USER_C_MODULES)/%.c,%.c,$(SRC_USERMOD))
122+
CFLAGS_MOD += $(CFLAGS_USERMOD)
123+
LDFLAGS_MOD += $(LDFLAGS_USERMOD)
124+
endif
125+
108126
# py object files
109127
PY_CORE_O_BASENAME = $(addprefix py/,\
110128
mpstate.o \
@@ -287,6 +305,13 @@ $(HEADER_BUILD)/mpversion.h: FORCE | $(HEADER_BUILD)
287305
$(STEPECHO) "GEN $@"
288306
$(Q)$(PYTHON) $(PY_SRC)/makeversionhdr.py $@
289307

308+
# build a list of registered modules for py/objmodule.c.
309+
$(HEADER_BUILD)/moduledefs.h: $(SRC_QSTR) $(QSTR_GLOBAL_DEPENDENCIES) | $(HEADER_BUILD)/mpversion.h
310+
@$(ECHO) "GEN $@"
311+
$(Q)$(PYTHON) $(PY_SRC)/makemoduledefs.py --vpath="., $(TOP), $(USER_C_MODULES)" $(SRC_QSTR) > $@
312+
313+
SRC_QSTR += $(HEADER_BUILD)/moduledefs.h
314+
290315
# mpconfigport.mk is optional, but changes to it may drastically change
291316
# overall config, so they need to be caught
292317
MPCONFIGPORT_MK = $(wildcard mpconfigport.mk)

0 commit comments

Comments
 (0)