package/pkg-luarocks.mk: add support of host-luarocks-package
authorFrancois Perrad <fperrad@gmail.com>
Sun, 22 Mar 2020 08:07:04 +0000 (09:07 +0100)
committerThomas Petazzoni <thomas.petazzoni@bootlin.com>
Sun, 12 Apr 2020 12:48:18 +0000 (14:48 +0200)
Signed-off-by: Francois Perrad <francois.perrad@gadz.org>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
docs/manual/adding-packages-luarocks.txt
package/luarocks/luarocks-br-host-config.lua [new file with mode: 0644]
package/luarocks/luarocks.mk
package/pkg-luarocks.mk

index df97cdd5033bc0fed6358a1c968dcee66d924dbc..70f48fc02cc8cfee62f5dd43d3212b27309bee82 100644 (file)
@@ -73,9 +73,7 @@ infrastructures in Buildroot, respectively.
 
 The main macro of the LuaRocks package infrastructure is +luarocks-package+:
 like +generic-package+ it works by defining a number of variables providing
-metadata information about the package, and then calling +luarocks-package+. It
-is worth mentioning that building LuaRocks packages for the host is not
-supported, so the macro +host-luarocks-package+ is not implemented.
+metadata information about the package, and then calling +luarocks-package+.
 
 Just like the generic infrastructure, the LuaRocks infrastructure works
 by defining a number of variables before calling the +luarocks-package+
diff --git a/package/luarocks/luarocks-br-host-config.lua b/package/luarocks/luarocks-br-host-config.lua
new file mode 100644 (file)
index 0000000..6319595
--- /dev/null
@@ -0,0 +1,3 @@
+-- BR host compilation
+local function getenv (name) return os_getenv(name) or '' end
+external_deps_dirs = { getenv('HOST_DIR') }
index cf111e4c912b8306ea53d0d994ae8838b7029d7e..2ea3c8d8d65268cc02ab1cf92b150c39e1e5e320 100644 (file)
@@ -14,6 +14,7 @@ HOST_LUAROCKS_DEPENDENCIES = host-luainterpreter
 LUAROCKS_CONFIG_DIR = $(HOST_DIR)/etc
 LUAROCKS_CONFIG_FILE_DEFAULT = $(LUAROCKS_CONFIG_DIR)/luarocks/config-$(LUAINTERPRETER_ABIVER).lua
 LUAROCKS_CONFIG_FILE = $(LUAROCKS_CONFIG_DIR)/luarocks/config.lua
+HOST_LUAROCKS_CONFIG_FILE = $(LUAROCKS_CONFIG_DIR)/luarocks/host-config.lua
 
 define LUAROCKS_ADDON_EXTRACT
        mkdir $(@D)/src/luarocks/cmd/external
@@ -35,6 +36,8 @@ define HOST_LUAROCKS_INSTALL_CMDS
        $(MAKE1) -C $(@D) install
        cat $(LUAROCKS_CONFIG_FILE_DEFAULT) $(HOST_LUAROCKS_PKGDIR)/luarocks-br-config.lua \
                > $(LUAROCKS_CONFIG_FILE)a
+       cat $(LUAROCKS_CONFIG_FILE_DEFAULT) $(HOST_LUAROCKS_PKGDIR)/luarocks-br-host-config.lua \
+               > $(HOST_LUAROCKS_CONFIG_FILE)
        rm -f $(LUAROCKS_CONFIG_FILE_DEFAULT)
 endef
 
index a50a4fcf5a767e45926bad4ed667688f107cc71e..603c0851b45472033a19ebe48d4409aff9ec8597 100644 (file)
 
 LUAROCKS_RUN_CMD = $(HOST_DIR)/bin/luarocks
 LUAROCKS_CFLAGS = $(TARGET_CFLAGS) -fPIC
+HOST_LUAROCKS_CFLAGS = $(HOST_CFLAGS) -fPIC
 ifeq ($(BR2_PACKAGE_LUA_5_3),y)
 LUAROCKS_CFLAGS += -DLUA_COMPAT_5_2
+HOST_LUAROCKS_CFLAGS += -DLUA_COMPAT_5_2
 endif
 
 ################################################################################
@@ -39,16 +41,50 @@ endif
 
 define inner-luarocks-package
 
-$(2)_BUILD_OPTS                ?=
-$(2)_NAME_UPSTREAM     ?= $(1)
-$(2)_SUBDIR            ?= $$($(2)_NAME_UPSTREAM)-$$(shell echo "$$($(2)_VERSION)" | sed -e "s/-[0-9]$$$$//")
-$(2)_ROCKSPEC          ?= $$(call LOWERCASE,$$($(2)_NAME_UPSTREAM))-$$($(2)_VERSION).rockspec
-$(2)_SOURCE            ?= $$(call LOWERCASE,$$($(2)_NAME_UPSTREAM))-$$($(2)_VERSION).src.rock
-$(2)_SITE              ?= $$(call qstrip,$$(BR2_LUAROCKS_MIRROR))
+ifndef $(2)_NAME_UPSTREAM
+  ifdef $(3)_NAME_UPSTREAM
+    $(2)_NAME_UPSTREAM = $($(3)_NAME_UPSTREAM)
+  else
+    $(2)_NAME_UPSTREAM ?= $(1)
+  endif
+endif
+
+ifndef $(2)_SUBDIR
+  ifdef $(3)_SUBDIR
+    $(2)_SUBDIR = $($(3)_SUBDIR)
+  else
+    $(2)_SUBDIR ?= $$($(3)_NAME_UPSTREAM)-$$(shell echo "$$($(3)_VERSION)" | sed -e "s/-[0-9]$$$$//")
+  endif
+endif
+
+ifndef $(2)_ROCKSPEC
+  ifdef $(3)_ROCKSPEC
+    $(2)_ROCKSPEC = $($(3)_ROCKSPEC)
+  else
+    $(2)_ROCKSPEC ?= $$(call LOWERCASE,$$($(3)_NAME_UPSTREAM))-$$($(3)_VERSION).rockspec
+  endif
+endif
+
+ifndef $(2)_SOURCE
+  ifdef $(3)_SOURCE
+    $(2)_SOURCE = $($(3)_SOURCE)
+  else
+    $(2)_SOURCE ?= $$(call LOWERCASE,$$($(3)_NAME_UPSTREAM))-$$($(3)_VERSION).src.rock
+  endif
+endif
+
+ifndef $(2)_SITE
+  ifdef $(3)_SITE
+    $(2)_SITE = $($(3)_SITE)
+  else
+    $(2)_SITE ?= $$(call qstrip,$$(BR2_LUAROCKS_MIRROR))
+  endif
+endif
 
-# Since we do not support host-luarocks-package, we know this is
-# a target package, and can just add the required dependencies
-$(2)_DEPENDENCIES      += luainterpreter
+ifeq ($(4),target)
+$(2)_DEPENDENCIES += luainterpreter
+endif
+# host-luarocks implies host-luainterpreter
 $(2)_EXTRACT_DEPENDENCIES += host-luarocks
 
 #
@@ -83,6 +119,17 @@ define $(2)_INSTALL_TARGET_CMDS
 endef
 endif
 
+ifndef $(2)_INSTALL_CMDS
+define $(2)_INSTALL_CMDS
+       cd $$($(2)_SRCDIR) && \
+               LUAROCKS_CONFIG=$$(HOST_LUAROCKS_CONFIG_FILE) \
+               $$(LUAROCKS_RUN_CMD) make --keep --deps-mode none \
+                       CFLAGS="$$(HOST_LUAROCKS_CFLAGS)" \
+                       LIBFLAG="-shared $$(HOST_LDFLAGS)" \
+                       $$($(2)_BUILD_OPTS) $$($(2)_ROCKSPEC)
+endef
+endif
+
 # Call the generic package infrastructure to generate the necessary
 # make targets
 $(call inner-generic-package,$(1),$(2),$(3),$(4))
@@ -100,4 +147,4 @@ endef
 ################################################################################
 
 luarocks-package = $(call inner-luarocks-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
-# host-luarocks-package not supported
+host-luarocks-package = $(call inner-luarocks-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)