micropython.mk 2.4 KB

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