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