1################################################################################
2#
3# micropython
4#
5################################################################################
6
7MICROPYTHON_VERSION = 1.22.0
8MICROPYTHON_SITE = https://micropython.org/resources/source
9MICROPYTHON_SOURCE = micropython-$(MICROPYTHON_VERSION).tar.xz
10# Micropython has a lot of code copied from other projects, and also a number
11# of submodules for various libs. However, we don't even clone the submodules,
12# and most of the copied code is not used in the unix build.
13MICROPYTHON_LICENSE = MIT, BSD-1-Clause, BSD-3-Clause, Zlib
14MICROPYTHON_LICENSE_FILES = LICENSE
15MICROPYTHON_DEPENDENCIES = host-python3
16MICROPYTHON_CPE_ID_VENDOR = micropython
17
18# Use fallback implementation for exception handling on architectures that don't
19# have explicit support.
20ifeq ($(BR2_i386)$(BR2_x86_64)$(BR2_arm)$(BR2_armeb),)
21MICROPYTHON_CFLAGS = -DMICROPY_GCREGS_SETJMP=1
22endif
23
24# xtensa has problems with nlr_push, use setjmp based implementation instead
25ifeq ($(BR2_xtensa),y)
26MICROPYTHON_CFLAGS = -DMICROPY_NLR_SETJMP=1
27endif
28
29# When building from a tarball we don't have some of the dependencies that are in
30# the git repository as submodules
31MICROPYTHON_MAKE_OPTS += \
32	MICROPY_PY_BTREE=0 \
33	MICROPY_PY_USSL=0 \
34	CROSS_COMPILE=$(TARGET_CROSS) \
35	CFLAGS_EXTRA=$(MICROPYTHON_CFLAGS) \
36	LDFLAGS_EXTRA="$(TARGET_LDFLAGS)" \
37	CWARN=
38
39ifeq ($(BR2_PACKAGE_LIBFFI),y)
40MICROPYTHON_DEPENDENCIES += host-pkgconf libffi
41MICROPYTHON_MAKE_OPTS += MICROPY_PY_FFI=1
42else
43MICROPYTHON_MAKE_OPTS += MICROPY_PY_FFI=0
44endif
45
46define MICROPYTHON_BUILD_CMDS
47	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/mpy-cross
48	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/ports/unix \
49		$(MICROPYTHON_MAKE_OPTS)
50endef
51
52define MICROPYTHON_INSTALL_TARGET_CMDS
53	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/ports/unix \
54		$(MICROPYTHON_MAKE_OPTS) \
55		DESTDIR=$(TARGET_DIR) \
56		PREFIX=/usr \
57		install
58endef
59
60ifeq ($(BR2_PACKAGE_MICROPYTHON_LIB),y)
61define MICROPYTHON_COLLECT_LIBS
62	$(EXTRA_ENV) PYTHONPATH=$(@D)/tools \
63		package/micropython/collect_micropython_lib.py \
64		$(@D) $(@D)/.built_pylib
65endef
66
67define MICROPYTHON_INSTALL_LIBS
68	$(INSTALL) -d -m 0755 $(TARGET_DIR)/usr/lib/micropython
69	cp -a $(@D)/.built_pylib/* $(TARGET_DIR)/usr/lib/micropython
70endef
71
72MICROPYTHON_POST_BUILD_HOOKS += MICROPYTHON_COLLECT_LIBS
73MICROPYTHON_POST_INSTALL_TARGET_HOOKS += MICROPYTHON_INSTALL_LIBS
74endif
75
76$(eval $(generic-package))
77