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 20LUAROCKS_RUN_CMD = $(HOST_DIR)/bin/luarocks 21LUAROCKS_CFLAGS = $(TARGET_CFLAGS) -fPIC 22HOST_LUAROCKS_CFLAGS = $(HOST_CFLAGS) -fPIC 23ifeq ($(BR2_PACKAGE_LUA_5_3),y) 24LUAROCKS_CFLAGS += -DLUA_COMPAT_5_2 25HOST_LUAROCKS_CFLAGS += -DLUA_COMPAT_5_2 26else ifeq ($(BR2_PACKAGE_LUA_5_4),y) 27LUAROCKS_CFLAGS += -DLUA_COMPAT_5_3 28HOST_LUAROCKS_CFLAGS += -DLUA_COMPAT_5_3 29endif 30 31################################################################################ 32# inner-luarocks-package -- defines how the configuration, compilation and 33# installation of a LuaRocks package should be done, implements a few hooks to 34# tune the build process and calls the generic package infrastructure to 35# generate the necessary make targets 36# 37# argument 1 is the lowercase package name 38# argument 2 is the uppercase package name, including a HOST_ prefix 39# for host packages 40# argument 3 is the uppercase package name, without the HOST_ prefix 41# for host packages 42# argument 4 is the type (target or host) 43################################################################################ 44 45define inner-luarocks-package 46 47ifndef $(2)_NAME_UPSTREAM 48 ifdef $(3)_NAME_UPSTREAM 49 $(2)_NAME_UPSTREAM = $($(3)_NAME_UPSTREAM) 50 else 51 $(2)_NAME_UPSTREAM ?= $(1) 52 endif 53endif 54 55ifndef $(2)_SUBDIR 56 ifdef $(3)_SUBDIR 57 $(2)_SUBDIR = $($(3)_SUBDIR) 58 else 59 $(2)_SUBDIR ?= $$($(3)_NAME_UPSTREAM)-$$(shell echo "$$($(3)_VERSION)" | sed -e "s/-[0-9]$$$$//") 60 endif 61endif 62 63ifndef $(2)_ROCKSPEC 64 ifdef $(3)_ROCKSPEC 65 $(2)_ROCKSPEC = $($(3)_ROCKSPEC) 66 else 67 $(2)_ROCKSPEC ?= $$(call LOWERCASE,$$($(3)_NAME_UPSTREAM))-$$($(3)_VERSION).rockspec 68 endif 69endif 70 71ifndef $(2)_SOURCE 72 ifdef $(3)_SOURCE 73 $(2)_SOURCE = $($(3)_SOURCE) 74 else 75 $(2)_SOURCE ?= $$(call LOWERCASE,$$($(3)_NAME_UPSTREAM))-$$($(3)_VERSION).src.rock 76 endif 77endif 78 79ifndef $(2)_SITE 80 ifdef $(3)_SITE 81 $(2)_SITE = $($(3)_SITE) 82 else 83 $(2)_SITE ?= $$(call qstrip,$$(BR2_LUAROCKS_MIRROR)) 84 endif 85endif 86 87ifeq ($(4),target) 88$(2)_DEPENDENCIES += luainterpreter 89endif 90# host-luarocks implies host-luainterpreter 91$(2)_EXTRACT_DEPENDENCIES += host-luarocks 92 93# 94# Extract step. Extract into a temporary dir and move the relevant part to the 95# source dir. 96# 97ifndef $(2)_EXTRACT_CMDS 98define $(2)_EXTRACT_CMDS 99 mkdir -p $$($(2)_DIR)/luarocks-extract 100 cd $$($(2)_DIR)/luarocks-extract && \ 101 $$(LUAROCKS_RUN_CMD) unpack --force $$($(2)_DL_DIR)/$$($(2)_SOURCE) 102 mv $$($(2)_DIR)/luarocks-extract/*/* $$($(2)_DIR) 103endef 104endif 105 106# 107# Build/install step. 108# 109ifndef $(2)_INSTALL_TARGET_CMDS 110define $(2)_INSTALL_TARGET_CMDS 111 cd $$($(2)_SRCDIR) && \ 112 LUAROCKS_CONFIG=$$(LUAROCKS_CONFIG_FILE) \ 113 $$(LUAROCKS_RUN_CMD) make --keep --deps-mode none \ 114 --tree "$$(TARGET_DIR)/usr" \ 115 DEPS_DIR="$$(STAGING_DIR)/usr" \ 116 LUA_INCDIR="$$(STAGING_DIR)/usr/include" \ 117 LUA_LIBDIR="$$(STAGING_DIR)/usr/lib" \ 118 CC=$$(TARGET_CC) \ 119 LD=$$(TARGET_CC) \ 120 CFLAGS="$$(LUAROCKS_CFLAGS)" \ 121 LIBFLAG="-shared $$(TARGET_LDFLAGS)" \ 122 $$($(2)_BUILD_OPTS) $$($(2)_ROCKSPEC) 123endef 124endif 125 126ifndef $(2)_INSTALL_CMDS 127define $(2)_INSTALL_CMDS 128 cd $$($(2)_SRCDIR) && \ 129 LUAROCKS_CONFIG=$$(HOST_LUAROCKS_CONFIG_FILE) \ 130 $$(LUAROCKS_RUN_CMD) make --keep --deps-mode none \ 131 DEPS_DIR="$$(HOST_DIR)" \ 132 CFLAGS="$$(HOST_LUAROCKS_CFLAGS)" \ 133 LIBFLAG="-shared $$(HOST_LDFLAGS)" \ 134 $$($(2)_BUILD_OPTS) $$($(2)_ROCKSPEC) 135endef 136endif 137 138# Call the generic package infrastructure to generate the necessary 139# make targets 140$(call inner-generic-package,$(1),$(2),$(3),$(4)) 141 142# Upgrade helper 143$(1)-upgrade: host-luarocks 144 $$(LUAROCKS_RUN_CMD) buildroot $$($(2)_NAME_UPSTREAM) $(1) 145 146.PHONY: $(1)-upgrade 147 148endef 149 150################################################################################ 151# luarocks-package -- the target generator macro for LuaRocks packages 152################################################################################ 153 154luarocks-package = $(call inner-luarocks-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target) 155host-luarocks-package = $(call inner-luarocks-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host) 156