take ulab (https://github.com/v923z/micropython-ulab/) as an example,
to build ulab module by "make USER_C_MODULES=../../../ulab all"
It can be built with unix port:
Including User C Module from ../../../ulab/code
.......
CC ../../../ulab/code/ndarray.c
CC ../../../ulab/code/ulab_create.c
CC ../../../ulab/code/linalg/linalg.c
CC ../../../ulab/code/vector/vectorise.c
CC ../../../ulab/code/poly/poly.c
CC ../../../ulab/code/fft/fft.c
CC ../../../ulab/code/numerical/numerical.c
CC ../../../ulab/code/filter/filter.c
CC ../../../ulab/code/compare/compare.c
CC ../../../ulab/code/approx/approx.c
CC ../../../ulab/code/user/user.c
CC ../../../ulab/code/ulab.c
... ...
But if use minimal port, it's not built actually:
Including User C Module from ../../../ulab/code
... ...
Is it possible to build with minimal port?
Thanks.
How to add a C module to minimal port?
Re: How to add a C module to minimal port?
manually append SRC_MOD to SRC_C to build the C module.
But there are so many compiling errors.
Seems there are some dependencies to enable C module with minimal port. any flag to enable?
But there are so many compiling errors.
Seems there are some dependencies to enable C module with minimal port. any flag to enable?
Re: How to add a C module to minimal port?
In order to build the user module, it needs SRC_MOD, CFLAGS_MOD, and CFLAGS_EXTRA
Here's the diff I applied to minimal/Makefile to make it work with a simple demo module:
Code: Select all
diff --git a/ports/minimal/Makefile b/ports/minimal/Makefile
index bce544ec1..d13be7ba0 100644
--- a/ports/minimal/Makefile
+++ b/ports/minimal/Makefile
@@ -41,6 +41,8 @@ CFLAGS += -Os -DNDEBUG
CFLAGS += -fdata-sections -ffunction-sections
endif
+CFLAGS += $(CFLAGS_MOD) $(CFLAGS_EXTRA)
+
LIBS =
SRC_C = \
@@ -51,6 +53,7 @@ SRC_C = \
lib/utils/pyexec.c \
lib/mp-readline/readline.c \
$(BUILD)/_frozen_mpy.c \
+ $(SRC_MOD) \
ifeq ($(CROSS), 1)
SRC_C += lib/libc/string0.c
All of the compile errors are due to the fact that the minimal port doesn't support floating point (which is important for ulab!).
So you need to add to minimal/mpconfigport.h
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
Then there will be linker errors for the math functions, so add -lm to the LDFLAGS.
Then it will be missing builtin slice and array support, so add
#define MICROPY_PY_ARRAY (1)
#define MICROPY_PY_BUILTINS_SLICE (1)
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
#define MICROPY_PY_BUILTINS_SLICE_INDICES (1)
to minimal/mpconfigport.h (removing the existing lines that set these to zero)
That will all work if you're using the native build of the minimal port. But if you're using the cross compiler, you might need additional work instead of -lm to add the libm functions (look at the stm32 port for example).
Re: How to add a C module to minimal port?
Thanks. It's very helpful.