xref: /OK3568_Linux_fs/buildroot/docs/manual/adding-packages-luarocks.txt (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1// -*- mode:doc; -*-
2// vim: set syntax=asciidoc:
3
4=== Infrastructure for LuaRocks-based packages
5
6[[luarocks-package-tutorial]]
7
8==== +luarocks-package+ tutorial
9
10First, let's see how to write a +.mk+ file for a LuaRocks-based package,
11with an example :
12
13------------------------
1401: ################################################################################
1502: #
1603: # lua-foo
1704: #
1805: ################################################################################
1906:
2007: LUA_FOO_VERSION = 1.0.2-1
2108: LUA_FOO_NAME_UPSTREAM = foo
2209: LUA_FOO_DEPENDENCIES = bar
2310:
2411: LUA_FOO_BUILD_OPTS += BAR_INCDIR=$(STAGING_DIR)/usr/include
2512: LUA_FOO_BUILD_OPTS += BAR_LIBDIR=$(STAGING_DIR)/usr/lib
2613: LUA_FOO_LICENSE = luaFoo license
2714: LUA_FOO_LICENSE_FILES = $(LUA_FOO_SUBDIR)/COPYING
2815:
2916: $(eval $(luarocks-package))
30------------------------
31
32On line 7, we declare the version of the package (the same as in the rockspec,
33which is the concatenation of the upstream version and the rockspec revision,
34separated by a hyphen '-').
35
36On line 8, we declare that the package is called "foo" on LuaRocks. In
37Buildroot, we give Lua-related packages a name that starts with "lua", so the
38Buildroot name is different from the upstream name. +LUA_FOO_NAME_UPSTREAM+
39makes the link between the two names.
40
41On line 9, we declare our dependencies against native libraries, so that they
42are built before the build process of our package starts.
43
44On lines 11-12, we tell Buildroot to pass custom options to LuaRocks when it is
45building the package.
46
47On lines 13-14, we specify the licensing terms for the package.
48
49Finally, on line 16, we invoke the +luarocks-package+
50macro that generates all the Makefile rules that actually allows the
51package to be built.
52
53Most of these details can be retrieved from the +rock+ and +rockspec+.
54So, this file and the Config.in file can be generated by running the
55command +luarocks buildroot foo lua-foo+ in the Buildroot
56directory. This command runs a specific Buildroot addon of +luarocks+
57that will automatically generate a Buildroot package. The result must
58still be manually inspected and possibly modified.
59
60* The +package/Config.in+ file has to be updated manually to include the
61  generated Config.in files.
62
63[[luarocks-package-reference]]
64
65==== +luarocks-package+ reference
66
67LuaRocks is a deployment and management system for Lua modules, and supports
68various +build.type+: +builtin+, +make+ and +cmake+. In the context of
69Buildroot, the +luarocks-package+ infrastructure only supports the +builtin+
70mode. LuaRocks packages that use the +make+ or +cmake+ build mechanisms
71should instead be packaged using the +generic-package+ and +cmake-package+
72infrastructures in Buildroot, respectively.
73
74The main macro of the LuaRocks package infrastructure is +luarocks-package+:
75like +generic-package+ it works by defining a number of variables providing
76metadata information about the package, and then calling +luarocks-package+.
77
78Just like the generic infrastructure, the LuaRocks infrastructure works
79by defining a number of variables before calling the +luarocks-package+
80macro.
81
82First, all the package metadata information variables that exist in
83the generic infrastructure also exist in the LuaRocks infrastructure:
84+LUA_FOO_VERSION+, +LUA_FOO_SOURCE+, +LUA_FOO_SITE+,
85+LUA_FOO_DEPENDENCIES+, +LUA_FOO_LICENSE+, +LUA_FOO_LICENSE_FILES+.
86
87Two of them are populated by the LuaRocks infrastructure (for the
88+download+ step). If your package is not hosted on the LuaRocks mirror
89+$(BR2_LUAROCKS_MIRROR)+, you can override them:
90
91* +LUA_FOO_SITE+, which defaults to +$(BR2_LUAROCKS_MIRROR)+
92
93* +LUA_FOO_SOURCE+, which defaults to
94  +$(lowercase LUA_FOO_NAME_UPSTREAM)-$(LUA_FOO_VERSION).src.rock+
95
96A few additional variables, specific to the LuaRocks infrastructure, are
97also defined. They can be overridden in specific cases.
98
99* +LUA_FOO_NAME_UPSTREAM+, which defaults to +lua-foo+, i.e. the Buildroot
100  package name
101
102* +LUA_FOO_ROCKSPEC+, which defaults to
103  +$(lowercase LUA_FOO_NAME_UPSTREAM)-$(LUA_FOO_VERSION).rockspec+
104
105* +LUA_FOO_SUBDIR+, which defaults to
106  +$(LUA_FOO_NAME_UPSTREAM)-$(LUA_FOO_VERSION_WITHOUT_ROCKSPEC_REVISION)+
107
108* +LUA_FOO_BUILD_OPTS+ contains additional build options for the
109  +luarocks build+ call.
110