py: Implement a module system for external, user C modules.

This system makes it a lot easier to include external libraries as static,
native modules in MicroPython.  Simply pass USER_C_MODULES (like
FROZEN_MPY_DIR) as a make parameter.
This commit is contained in:
Ayke van Laethem
2018-06-14 15:57:29 +02:00
committed by Damien George
parent cf22f4793c
commit 2e516074da
8 changed files with 141 additions and 4 deletions

View File

@@ -129,6 +129,13 @@ $(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare
$(BUILD)/extmod/modbtree.o: CFLAGS += $(BTREE_DEFS)
endif
# External modules written in C.
ifneq ($(USER_C_MODULES),)
CFLAGS_MOD += -DMICROPY_CMODULES_INCLUDE_H='"genhdr/cmodules.h"'
include $(USER_C_MODULES)/*/micropython.mk
SRC_QSTR += $(BUILD)/genhdr/cmodules.h
endif
# py object files
PY_CORE_O_BASENAME = $(addprefix py/,\
mpstate.o \
@@ -300,7 +307,7 @@ endif
# Sources that may contain qstrings
SRC_QSTR_IGNORE = py/nlr%
SRC_QSTR = $(SRC_MOD) $(filter-out $(SRC_QSTR_IGNORE),$(PY_CORE_O_BASENAME:.o=.c)) $(PY_EXTMOD_O_BASENAME:.o=.c)
SRC_QSTR += $(SRC_MOD) $(filter-out $(SRC_QSTR_IGNORE),$(PY_CORE_O_BASENAME:.o=.c)) $(PY_EXTMOD_O_BASENAME:.o=.c)
# Anything that depends on FORCE will be considered out-of-date
FORCE: