pkg-luarocks.mk 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. ################################################################################
  2. # LuaRocks package infrastructure
  3. # see http://luarocks.org/
  4. #
  5. # This file implements an infrastructure that eases development of
  6. # package .mk files for LuaRocks packages.
  7. # LuaRocks supports various build.type : builtin, make, cmake.
  8. # This luarocks infrastructure supports only the builtin mode,
  9. # the make & cmake modes could be directly handled by generic & cmake infrastructure.
  10. #
  11. # See the Buildroot documentation for details on the usage of this
  12. # infrastructure
  13. #
  14. # In terms of implementation, this LuaRocks infrastructure requires
  15. # the .mk file to only specify metadata information about the
  16. # package: name, version, etc.
  17. #
  18. ################################################################################
  19. LUAROCKS_RUN_CMD = $(HOST_DIR)/bin/luarocks
  20. LUAROCKS_CFLAGS = $(TARGET_CFLAGS) -fPIC
  21. HOST_LUAROCKS_CFLAGS = $(HOST_CFLAGS) -fPIC
  22. ifeq ($(BR2_PACKAGE_LUA_5_3),y)
  23. LUAROCKS_CFLAGS += -DLUA_COMPAT_5_2
  24. HOST_LUAROCKS_CFLAGS += -DLUA_COMPAT_5_2
  25. else ifeq ($(BR2_PACKAGE_LUA_5_4),y)
  26. LUAROCKS_CFLAGS += -DLUA_COMPAT_5_3
  27. HOST_LUAROCKS_CFLAGS += -DLUA_COMPAT_5_3
  28. endif
  29. ################################################################################
  30. # inner-luarocks-package -- defines how the configuration, compilation and
  31. # installation of a LuaRocks package should be done, implements a few hooks to
  32. # tune the build process and calls the generic package infrastructure to
  33. # generate the necessary make targets
  34. #
  35. # argument 1 is the lowercase package name
  36. # argument 2 is the uppercase package name, including a HOST_ prefix
  37. # for host packages
  38. # argument 3 is the uppercase package name, without the HOST_ prefix
  39. # for host packages
  40. # argument 4 is the type (target or host)
  41. ################################################################################
  42. define inner-luarocks-package
  43. ifndef $(2)_NAME_UPSTREAM
  44. ifdef $(3)_NAME_UPSTREAM
  45. $(2)_NAME_UPSTREAM = $($(3)_NAME_UPSTREAM)
  46. else
  47. $(2)_NAME_UPSTREAM ?= $(1)
  48. endif
  49. endif
  50. ifndef $(2)_SUBDIR
  51. ifdef $(3)_SUBDIR
  52. $(2)_SUBDIR = $($(3)_SUBDIR)
  53. else
  54. $(2)_SUBDIR ?= $$($(3)_NAME_UPSTREAM)-$$(shell echo "$$($(3)_VERSION)" | sed -e "s/-[0-9]$$$$//")
  55. endif
  56. endif
  57. ifndef $(2)_ROCKSPEC
  58. ifdef $(3)_ROCKSPEC
  59. $(2)_ROCKSPEC = $($(3)_ROCKSPEC)
  60. else
  61. $(2)_ROCKSPEC ?= $$(call LOWERCASE,$$($(3)_NAME_UPSTREAM))-$$($(3)_VERSION).rockspec
  62. endif
  63. endif
  64. ifndef $(2)_SOURCE
  65. ifdef $(3)_SOURCE
  66. $(2)_SOURCE = $($(3)_SOURCE)
  67. else
  68. $(2)_SOURCE ?= $$(call LOWERCASE,$$($(3)_NAME_UPSTREAM))-$$($(3)_VERSION).src.rock
  69. endif
  70. endif
  71. ifndef $(2)_SITE
  72. ifdef $(3)_SITE
  73. $(2)_SITE = $($(3)_SITE)
  74. else
  75. $(2)_SITE ?= $$(call qstrip,$$(BR2_LUAROCKS_MIRROR))
  76. endif
  77. endif
  78. ifeq ($(4),target)
  79. $(2)_DEPENDENCIES += luainterpreter
  80. endif
  81. # host-luarocks implies host-luainterpreter
  82. $(2)_EXTRACT_DEPENDENCIES += host-luarocks
  83. #
  84. # Extract step. Extract into a temporary dir and move the relevant part to the
  85. # source dir.
  86. #
  87. ifndef $(2)_EXTRACT_CMDS
  88. define $(2)_EXTRACT_CMDS
  89. mkdir -p $$($(2)_DIR)/luarocks-extract
  90. cd $$($(2)_DIR)/luarocks-extract && \
  91. $$(LUAROCKS_RUN_CMD) unpack --force $$($(2)_DL_DIR)/$$($(2)_SOURCE)
  92. mv $$($(2)_DIR)/luarocks-extract/*/* $$($(2)_DIR)
  93. endef
  94. endif
  95. #
  96. # Build/install step.
  97. #
  98. ifndef $(2)_INSTALL_TARGET_CMDS
  99. define $(2)_INSTALL_TARGET_CMDS
  100. cd $$($(2)_SRCDIR) && \
  101. LUAROCKS_CONFIG=$$(LUAROCKS_CONFIG_FILE) \
  102. $$(LUAROCKS_RUN_CMD) make --keep --deps-mode none \
  103. --tree "$$(TARGET_DIR)/usr" \
  104. DEPS_DIR="$$(STAGING_DIR)/usr" \
  105. LUA_INCDIR="$$(STAGING_DIR)/usr/include" \
  106. LUA_LIBDIR="$$(STAGING_DIR)/usr/lib" \
  107. CC=$$(TARGET_CC) \
  108. LD=$$(TARGET_CC) \
  109. CFLAGS="$$(LUAROCKS_CFLAGS)" \
  110. LIBFLAG="-shared $$(TARGET_LDFLAGS)" \
  111. $$($(2)_BUILD_OPTS) $$($(2)_ROCKSPEC)
  112. endef
  113. endif
  114. ifndef $(2)_INSTALL_CMDS
  115. define $(2)_INSTALL_CMDS
  116. cd $$($(2)_SRCDIR) && \
  117. LUAROCKS_CONFIG=$$(HOST_LUAROCKS_CONFIG_FILE) \
  118. $$(LUAROCKS_RUN_CMD) make --keep --deps-mode none \
  119. DEPS_DIR="$$(HOST_DIR)" \
  120. CFLAGS="$$(HOST_LUAROCKS_CFLAGS)" \
  121. LIBFLAG="-shared $$(HOST_LDFLAGS)" \
  122. $$($(2)_BUILD_OPTS) $$($(2)_ROCKSPEC)
  123. endef
  124. endif
  125. # Call the generic package infrastructure to generate the necessary
  126. # make targets
  127. $(call inner-generic-package,$(1),$(2),$(3),$(4))
  128. # Upgrade helper
  129. $(1)-upgrade: host-luarocks
  130. $$(LUAROCKS_RUN_CMD) buildroot $$($(2)_NAME_UPSTREAM) $(1)
  131. .PHONY: $(1)-upgrade
  132. endef
  133. ################################################################################
  134. # luarocks-package -- the target generator macro for LuaRocks packages
  135. ################################################################################
  136. luarocks-package = $(call inner-luarocks-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
  137. host-luarocks-package = $(call inner-luarocks-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)