aboutsummaryrefslogtreecommitdiff
path: root/Mk/Uses/lua.mk
blob: d49c2a0587e1babef989f69a6305040bf450f6e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# $FreeBSD$
#
# Provide support for lua
#
# MAINTAINER: ports@FreeBSD.org
# Usage:
#
# USES+=	lua[:options,...]
#
# Options:
#
#   NN    (e.g. 52)  - specify an allowed Lua version (can use multiple times)
#   NN+   (e.g. 52+) - specify a minimum Lua version (discouraged)
#   -NN   (e.g. -53) - specify a maximum allowed version
#   NN-NN (e.g. 51-53) - specify a range of allowed versions
#
#   flavors	define FLAVOR / FLAVORS as luaNN from the allowed versions
#
#   noflavors	don't use flavors
#
#   module	(implies flavors) specifies that the port is a Lua module
#		(i.e. that it installes files in MODLIBDIR etc.)
#
#   build	add dependency to BUILD_DEPENDS instead of LIB_DEPENDS
#   run		add dependency to RUN_DEPENDS instead of LIB_DEPENDS
#
#   env		define only the LUA_* vars and add them to PLIST_SUB and
#		MAKE_ENV, do not add dependencies or other global state
#
#   core	for building Lua itself
#
# If more than one version is allowed, then the LUA_DEFAULT version (as set
# in DEFAULT_VERSIONS) is chosen if it is in the allowed range, otherwise
# the closest allowed version to the default is chosen, preferring the
# larger version in case of a tie.
#
# But if "flavors" was requested, and FLAVOR is set, we use that version
# exactly. (It is an error to specify a flavor that isn't supported, but
# that is checked in bsd.port.mk, not here.)
#
# LUA_FLAVOR is defined to the desired flavor whether or not "flavors" was
# selected; ports should use this to specify the flavor of dependencies
# which are Lua modules or otherwise Lua-flavored.
#
# It's not generally expected that applications that embed Lua, or apps
# written in Lua, would use USES=lua:flavors. Given that Lua is lightweight
# and does not carry around a whole lot of module ecosystem with it, it is
# best that application ports simply specify the Lua version or range of
# versions that they support, and let the default one or the latest one be
# used. However, they should still use LUA_FLAVOR as needed when specifying
# dependencies.
#
# We assume Lua versions can be represented as 2 digits.
#
.if !defined(_INCLUDE_USES_LUA_MK)
_INCLUDE_USES_LUA_MK=	yes

# When adding a version, please keep the comment in
# Mk/bsd.default-versions.mk in sync.
_LUA_VALID_VERSIONS:=	54 53 52 51
.if defined(_LUA_EXTRA_VER)
_LUA_VALID_VERSIONS+= ${_LUA_EXTRA_VER}
.endif

_LUA_DEFAULT_VERSION:=	${LUA_DEFAULT:S/.//}

# args
_LUA_ARG_FLAVORS:=
_LUA_ARG_MODULE:=
_LUA_ARG_ENV:=
_LUA_ARG_CORE:=
.if ${lua_ARGS:Mmodule}
_LUA_ARG_FLAVORS:=yes
_LUA_ARG_MODULE:=yes
.endif
.if ${lua_ARGS:Mflavors}
_LUA_ARG_FLAVORS:=yes
.endif
.if ${lua_ARGS:Mnoflavors}
_LUA_ARG_FLAVORS:=
.endif
.if ${lua_ARGS:Menv}
_LUA_ARG_ENV:=yes
.endif
.if ${lua_ARGS:Mcore}
_LUA_ARG_CORE:=yes
_LUA_ARG_ENV:=yes
_LUA_ARG_FLAVORS:=
_LUA_ARG_MODULE:=
.endif

# core is for building Lua itself, so it overrides all version checks
.if ${_LUA_ARG_CORE}

_LUA_WANTED_VERSION:=${lua_ARGS:M[1-9][0-9]:[1]}

.  if ${lua_ARGS:M[1-9][0-9]:[#]} != 1
IGNORE= USES=lua:core must also specify exactly one version number
# set to avoid spurious errors below
_LUA_WANTED_VERSION:=${_LUA_DEFAULT_VERSION}
.  endif

_LUA_VALID_VERSIONS:=${_LUA_WANTED_VERSION}
_LUA_WANTED_VERSIONS:=${_LUA_WANTED_VERSION}
_LUA_DEFAULT_VERSION:=${_LUA_WANTED_VERSION}

.endif # _LUA_ARG_CORE

.if ! ${_LUA_VALID_VERSIONS:M${_LUA_DEFAULT_VERSION}}
IGNORE=	Invalid lua version ${LUA_DEFAULT}
.endif

#
# Parse a ver+ argument
#
.if ${lua_ARGS:M??+}
_LUA_MIN_VERSION:=	${lua_ARGS:M??+:S/+//}
_LUA_MAX_VERSION:=	99
.endif

#
# Parse a -ver argument
#
.if ${lua_ARGS:M-??}
_LUA_MAX_VERSION:=	${lua_ARGS:M-??:S/-//}
_LUA_MIN_VERSION:=	0
.endif

#
# Parse a ver-ver argument
#
.if ${lua_ARGS:M??-??}
_LUA_MIN_VERSION:=	${lua_ARGS:M??-??:C/-.*//}
_LUA_MAX_VERSION:=	${lua_ARGS:M??-??:C/.*-//}
.endif

#
# Parse one or more ver arguments
#
.if ${lua_ARGS:M[1-9][0-9]}
.  for _v in ${lua_ARGS:M[1-9][0-9]}
.    if ${_LUA_VALID_VERSIONS:M${_v}}
_LUA_WANTED_VERSIONS+=${_v}
.    endif
.  endfor
.  if empty(_LUA_WANTED_VERSIONS)
IGNORE= USES=lua:nn did not find any valid version number
.  endif
.endif

#
# Resolve version ranges. Append anything within the range to the list of
# wanted versions.
#
.if defined(_LUA_MIN_VERSION) && defined(_LUA_MAX_VERSION)
.  for _v in ${_LUA_VALID_VERSIONS}
.    if ${_LUA_MIN_VERSION} <= ${_v} && ${_LUA_MAX_VERSION} >= ${_v}
_LUA_WANTED_VERSIONS+=${_v}
.    endif
.  endfor
.  if empty(_LUA_WANTED_VERSIONS)
IGNORE= USES=lua:xx-yy did not find any valid version
.  endif
.endif

#
# If no version was specified with any of the ver or ver+ arguments, allow
# all versions.
#
.if empty(_LUA_WANTED_VERSIONS)
_LUA_WANTED_VERSIONS:=	${_LUA_VALID_VERSIONS}
.endif

# The "preferred" version, which must always exist, is defined as the
# closest value to the default version, preferring higher versions in
# case of ties. We find this by constructing values in sequence:
#  VV VV+1 VV-1 VV+2 VV-2 ...
# and then filtering against the allowed versions. The result is the
# final list of "wanted" versions, with the preferred version first.

_LUA_NUM_ASC:=	\
	${:U:range=99:@_v@${${_v} > ${_LUA_DEFAULT_VERSION}:?${_v}:}@}
_LUA_NUM_DESC:=	\
	${:U:range=99:[-1..1]:@_v@${${_v} <= ${_LUA_DEFAULT_VERSION}:?${_v}:}@}
_LUA_NUM_ALL:=	\
	${:U:range=99:@_v@${_LUA_NUM_DESC:[${_v}]} ${_LUA_NUM_ASC:[${_v}]}@}

_LUA_WANTED_VERSIONS:= \
	${_LUA_NUM_ALL:@_v@${_LUA_WANTED_VERSIONS:M${_v}}@}

.if ${_LUA_ARG_FLAVORS}
.  if empty(FLAVORS)
FLAVORS= ${_LUA_WANTED_VERSIONS:S/^/lua/}
.  endif
.  if empty(FLAVOR)
FLAVOR= ${FLAVORS:[1]}
.  endif
_LUA_WANTED_VERSION:= ${FLAVOR:S/^lua//}
.else
_LUA_WANTED_VERSION:= ${_LUA_WANTED_VERSIONS:[1]}
.endif

# If we're building Lua itself, everything should be in $PREFIX. If
# we're building a module or app, then the stuff we're installing goes
# in $PREFIX but references to Lua itself are in $LOCALBASE.
#
# The assumption is the LUA_MOD* directories are where we're going to
# install (this is common for both modules and apps), and so we also
# define LUA_REFMOD* relative to LOCALBASE for use when specifying
# dependencies and so on.

.if ${_LUA_ARG_CORE}
LUA_BASE=${PREFIX}
.else
LUA_BASE=${LOCALBASE}
.endif

LUA_PREFIX=${PREFIX}

#
# Exported variables
#
LUA_VER_STR=		${_LUA_WANTED_VERSION}
LUA_VER=		${_LUA_WANTED_VERSION:S/^5/5./}
LUA_FLAVOR=		${_LUA_WANTED_VERSION:S/^/lua/}

LUA_CMD=		lua${LUA_VER_STR}
LUAC_CMD=		luac${LUA_VER_STR}
LUA_PKGNAMEPREFIX=	lua${LUA_VER_STR}-

LUA_LIBDIR=		${LUA_BASE}/lib
LUA_INCDIR=		${LUA_BASE}/include/lua${LUA_VER_STR}

LUA_MODLIBDIR=		${LUA_PREFIX}/lib/lua/${LUA_VER}
LUA_MODSHAREDIR=	${LUA_PREFIX}/share/lua/${LUA_VER}
LUA_MODDOCSDIR=		${LUA_PREFIX}/share/doc/lua${LUA_VER_STR}
LUA_MODEXAMPLESDIR=	${LUA_PREFIX}/share/examples/lua${LUA_VER_STR}

LUA_REFMODLIBDIR=	${LUA_BASE}/lib/lua/${LUA_VER}
LUA_REFMODSHAREDIR=	${LUA_BASE}/share/lua/${LUA_VER}

PLIST_SUB+=	LUA_MODLIBDIR=${LUA_MODLIBDIR:S,^${LUA_PREFIX}/,,} \
		LUA_MODSHAREDIR=${LUA_MODSHAREDIR:S,^${LUA_PREFIX}/,,} \
		LUA_MODDOCSDIR=${LUA_MODDOCSDIR:S,^${LUA_PREFIX}/,,} \
		LUA_INCDIR=${LUA_INCDIR:S,^${LUA_BASE}/,,} \
		LUA_VER=${LUA_VER} \
		LUA_VER_STR=${LUA_VER_STR}
MAKE_ENV+=	LUA_MODLIBDIR=${LUA_MODLIBDIR} \
		LUA_MODSHAREDIR=${LUA_MODSHAREDIR} \
		LUA_MODDOCSDIR=${LUA_MODDOCSDIR} \
		LUA_INCDIR=${LUA_INCDIR} \
		LUA_LIBDIR=${LUA_LIBDIR} \
		LUA_VER=${LUA_VER} \
		LUA_VER_STR=${LUA_VER_STR}

# if building a module or Lua itself, or if the port defined LUA_DOCSUBDIR,
# then define LUA_DOCSDIR and LUA_EXAMPLESDIR too
.if ${_LUA_ARG_CORE} || ${_LUA_ARG_MODULE}
LUA_DOCSUBDIR?=${PORTNAME}
.endif
.if !empty(LUA_DOCSUBDIR)
LUA_DOCSDIR=	${LUA_MODDOCSDIR}/${LUA_DOCSUBDIR}
LUA_EXAMPLESDIR=${LUA_MODEXAMPLESDIR}/${LUA_DOCSUBDIR}
PLIST_SUB+=	LUA_DOCSDIR=${LUA_DOCSDIR:S,^${LUA_PREFIX}/,,}
PLIST_SUB+=	LUA_EXAMPLESDIR=${LUA_EXAMPLESDIR:S,^${LUA_PREFIX}/,,}
MAKE_ENV+=	LUA_DOCSDIR=${LUA_DOCSDIR}
MAKE_ENV+=	LUA_EXAMPLESDIR=${LUA_EXAMPLESDIR}
.endif

.if empty(_LUA_ARG_ENV)
.  if ${lua_ARGS:Mbuild}
BUILD_DEPENDS+=	${LUA_CMD}:lang/lua${LUA_VER_STR}
.  endif
.  if ${lua_ARGS:Mrun}
RUN_DEPENDS+=	${LUA_CMD}:lang/lua${LUA_VER_STR}
.  endif
.  if !${lua_ARGS:Mbuild} && !${lua_ARGS:Mrun}
LIB_DEPENDS+=	liblua-${LUA_VER}.so:lang/lua${LUA_VER_STR}
.  endif
.endif

.endif