4 # $FreeBSD: Mk/bsd.lua.mk 334220 2013-11-18 16:15:51Z bapt $
6 # bsd.lua.mk - Support for Lua based ports.
8 # Created by: Alejandro Pulver <alepulver@FreeBSD.org>
10 # Please view me with 4 column tabs!
12 # The following variables can be defined in a port that uses the Lua library,
13 # tolua, Ruby bindings or related components like .lua modules (with run
14 # and/or build dependencies). It can be used after and/or before
15 # bsd.port.pre.mk, but Ruby components will only work if Ruby variables (e.g.
16 # USE_RUBY) are defined before it (this is a bsd.ruby.mk limitation), at least
17 # it is manually included.
18 # USE_LUA - Set to the list of Lua versions that can be used by the
19 # port. The syntax allows the following elements:
20 # - Single version (e.g. "4.0").
21 # - Range of versions (e.g. "5.0-5.1"). Must be ascending.
22 # - Partial range: single version and upper (e.g. "5.0+").
23 # - Partial range: single version and lower (e.g. "5.1-").
24 # Multiple elements can be specified separated by spaces.
25 # USE_LUA_NOT - Set to the list of Lua versions that can't be used by the
26 # port. In other words, it removes some versions from USE_LUA.
27 # If the latter is not defined, it will have the value of all
28 # the possible versions. The syntax is like USE_LUA.
29 # LUA_COMPS - Set to the list of Lua components the port uses. Several
30 # components can be specified separated by spaces. By default
31 # it will have the value of "lua". Suffixes in the form ":xxx"
32 # may be added to the components to determine the dependency
34 # The available components are:
35 # lua - The Lua library.
36 # tolua - The tolua library (for 4.0-5.1).
37 # toluaxx - The tolua++ library (for 5.0-5.1).
38 # ruby - The Ruby bindings for Lua (for 4.0-5.0).
39 # Other components (modules):
40 # 5.0 - app, compat51, dfui, filename, gettext,
42 # 5.1 - alien, filename, gettext, posix, pty, socket.
43 # The available dependency types are:
44 # build - Requires component for building.
45 # lib - Requires component for building and running.
46 # run - Requires component for running.
47 # If no suffix is present then "lib" will be used for "lua"
48 # 4.0-5.0 and "ruby", "build" for lua 5.1 and "tolua" (they
49 # are static), all others default to "run".
50 # LUA_PREMK - Define to determine version and define variables after
51 # <bsd.port.pre.mk> (in case the port needs to manually run
52 # the Lua program or the like).
53 # WANT_LUA - Set to "yes" or a valid single version (no ranges, etc).
54 # In both cases it will detect the installed Lua components
55 # and add them to the variable HAVE_LUA. If a version is
56 # selected, HAVE_LUA will contain a list of components in the
57 # other case it will contain a list of "component-version"
58 # pairs (e.g. lua-4.0, tolua-5.1, etc).
59 # It has to be used before bsd.port.pre.mk.
60 # WANT_LUA_VER - Set to the prefered Lua version for the port. It must be
61 # present in USE_LUA or missing in USE_LUA_NOT. This is
62 # overriden by the user variable WITH_LUA_VER if set. It can
63 # contain multiple versions in order of preference (last ones
66 # The following variables are intended for the user and can be defined in
68 # WITH_LUA_VER - Define to the list of prefered versions in reverse order.
70 # The following variables are defined by this file, to be read from the port.
71 # HAVE_LUA - The list of Lua components installed, if WANT_LUA was
72 # defined. The components will have version suffix if it was
74 # LUA_VER - The Lua version that is going to be used (e.g. "5.1").
75 # LUA_VER_SH - The Lua shared library major version (e.g. "1").
76 # LUA_VER_STR - The Lua version without the dots (e.g. "51").
77 # LUA_PREFIX - The prefix where Lua (and components) is installed.
78 # NOTE: please see comments below about its double function.
79 # LUA_SUBDIR - The directory under bin/share/lib where Lua is installed.
80 # Also used by Lua ports (lang/lua*) to set LATEST_LINK.
81 # LUA_INCDIR - The directory where Lua, tolua and tolua++ header files are
83 # LUA_LIBDIR - The directory where Lua, tolua and tolua++ libraries are
85 # LUA_MODLIBDIR - The directory where Lua module libraries (.so) are installed.
87 # - The directory where Lua modules (.lua) are installed.
89 # - The package name prefix used by Lua modules.
90 # LUA_CMD - The path to the Lua interpreter.
91 # LUAC_CMD - The path to the Lua compiler.
92 # TOLUA_CMD - The path to the tolua program.
93 # TOLUAXX_CMD - The path to the tolua++ program.
96 # - A port that needs Lua 4.0 and tolua (also 4.0) libraries (lua for building
97 # and running and tolua for building).
99 # LUA_COMPS= lua tolua
100 # - A port that needs Ruby bindings for Lua 5.0 for building and running.
103 # - A port that needs tolua 5.0 or 5.1 for building.
106 # - A port that needs Lua version 5.0 or higher for building and running.
108 # - A port that needs Lua of any version other than 5.1 for building and
112 # Notes about the integration of lua related ports with bsd.lua.mk:
113 # (please read when updating ports referred here, see lang/lua[0-9]*)
115 # The lua/tolua ports have to be patched so they can coexist, as the internal
116 # application build infrastructure does not handle it automatically. Currently
117 # the framework provides variables to the lua ports themselves, so changing
118 # some things here won't require changes in lang/{lua,tolua}*.
120 # For lua ports: if they install a static library, use the same method for
121 # tolua ports, otherwise in addition the libraries have to be symlinked to the
122 # common library directory with a versioned name, and linked with the -soname
123 # parameter (so when a port links with -L/usr/local/lib/lua51 -llua, it stores
124 # the dynamic dependency as the name which figures under /usr/local/lib).
126 # For tolua ports: as it is a static library (.a), installing binaries,
127 # headers and libraries under a versioned directory is fine (binary has also a
130 # The lua modules install in a separate directory, so there is no problem.
133 LUA_Include_MAINTAINER= lua@FreeBSD.org
136 # Global definitions.
139 .if !defined(_LUA_Definitions_Done)
140 _LUA_Definitions_Done= yes
143 # _LUA_COMPS_ALL - List of valid components.
144 # _LUA_DEP_TYPES_ALL - List of valid dependency types.
145 # _LUA_VERS_ALL - List of available Lua versions.
146 # _LUA_VERS_LISTS= - Reverse lists preference order.
147 # _LUA_PLIST_ALL - List of variables to be added to PLIST_SUB.
148 # _LUA_PLIST_DIR_ALL - List of path variables (relative to ${LUA_PREFIX})
149 # to be added to PLIST_SUB.
152 _LUA_COMPS_ALL= lua tolua toluaxx ruby \
153 alien app compat51 dfui filename gettext posix \
155 _LUA_DEP_TYPES_ALL= build lib run
157 _LUA_PLIST_ALL= LUA_VER LUA_VER_SH LUA_VER_STR LUA_PREFIX LUA_SUBDIR
158 _LUA_PLIST_DIR_ALL= LUA_BINDIR LUA_INCDIR LUA_LIBDIR \
159 LUA_MODLIBDIR LUA_MODSHAREDIR
160 _LUA_VERS_LISTS= _LUA_VER_INSTALLED WANT_LUA_VER WITH_LUA_VER
163 # Variables used to determine what is needed.
164 # _LUA_PORT_comp_ver - Port directory.
165 # _LUA_LIB_comp_ver - Name of the shared library (optional).
166 # _LUA_SHVER_comp_ver - Shared library version (optional).
167 # _LUA_FILE_comp_ver - File installed by that component.
168 # _LUA_DEPTYPE_comp_ver - Default dependency type.
171 _LUA_PORT_lua_5.1= lang/lua
172 _LUA_DEPTYPE_lua_5.1= lib
174 _LUA_PORT_alien_5.1= devel/lua-alien
175 _LUA_PORT_filename_5.1= devel/lua-filename
176 _LUA_PORT_gettext_5.1= devel/lua-gettext
177 _LUA_PORT_posix_5.1= devel/lua-posix
178 _LUA_PORT_pty_5.1= devel/lua-pty
179 _LUA_PORT_socket_5.1= net/luasocket
180 _LUA_PORT_tolua_5.1= lang/tolua
181 _LUA_PORT_toluaxx_5.1= lang/tolua++
183 . for comp in ${_LUA_COMPS_ALL}
185 . for ver in ${_LUA_VERS_ALL}
186 # XXX The hardcoded values here have to match LUA_* variables (later), and
187 # are here only to allow autodetection of installed versions.
188 . if ${_LUA_COMP} == "lua"
189 _LUA_LIB_${comp}_${ver}= lua-${ver}.${_LUA_SHVER_${comp}_${ver}}
190 _LUA_SHVER_${comp}_${ver}= ${ver:C/[[:digit:]]\.([[:digit:]])/\1/}
191 _LUA_FILE_${comp}_${ver}= ${LOCALBASE}/lib/lua${ver:S/.//g}/liblua.a
192 . elif ${_LUA_COMP} == "tolua"
193 _LUA_FILE_${comp}_${ver}= ${LOCALBASE}/lib/lua${ver:S/.//g}/libtolua.a
194 _LUA_DEPTYPE_${comp}_${ver}=build
195 . elif ${_LUA_COMP} == "toluaxx"
196 _LUA_FILE_${comp}_${ver}= ${LOCALBASE}/lib/lua${ver:S/.//g}/libtolua++.so
197 _LUA_DEPTYPE_${comp}_${ver}=lib
198 . elif ${_LUA_COMP} == "ruby"
199 _LUA_FILE_${comp}_${ver}= ${RUBY_SITEARCHLIBDIR}/lua-${ver}.so
200 _LUA_DEPTYPE_${comp}_${ver}=lib
201 . elif !defined(_LUA_FILE_${comp}_${ver})
202 _LUA_FILE_${comp}_${ver}= ${LOCALBASE}/share/lua/${ver}/${comp}.lua
204 . if !defined(_LUA_DEPTYPE_${comp}_${ver})
205 _LUA_DEPTYPE_${comp}_${ver}=run
212 # Check if we are going to determine the version.
215 .if !defined(_LUA_Version_Done) && (defined(_POSTMKINCLUDED) || \
216 (defined(LUA_PREMK) && defined(BEFOREPORTMK) && \
217 (defined(USE_LUA) || defined(USE_LUA_NOT))))
218 _LUA_Need_Version= yes
222 # Check for present components.
225 # Requested by the user.
227 .if defined(WANT_LUA) && defined(BEFOREPORTMK)
228 _WANT_LUA= ${WANT_LUA}
231 # Used for autodetection of installed versions.
233 .if defined(_LUA_Need_Version)
237 .if defined(_WANT_LUA)
239 . for __WANT_LUA in ${_WANT_LUA}
240 # Check if _WANT_LUA contains more than one word.
241 . if defined(_HAVE_LUA)
242 IGNORE?= selected multiple values for WANT_LUA: ${_WANT_LUA}
245 # Check for all versions.
246 . if ${_WANT_LUA:tl} == "yes"
247 . for comp in ${_LUA_COMPS_ALL}
248 . for ver in ${_LUA_VERS_ALL}
249 _LUA_COMP= _LUA_FILE_${comp}_${ver}
250 . if defined(${_LUA_COMP}) && exists(${${_LUA_COMP}})
251 _HAVE_LUA+= ${comp}-${ver}
255 # Check for a specific version.
256 . elif ${_LUA_VERS_ALL:M${__WANT_LUA}} != ""
257 . for comp in ${_LUA_COMPS_ALL}
258 . if exists(${_LUA_FILE_${comp}_${__WANT_LUA}})
263 IGNORE?= selected an invalid value for WANT_LUA: ${__WANT_LUA}
268 # Requested by the user.
270 .if defined(WANT_LUA) && defined(BEFOREPORTMK)
271 HAVE_LUA:= ${_HAVE_LUA}
274 # Used for autodetection of installed versions.
276 .if defined(_LUA_Need_Version)
277 _LUA_VER_INSTALLED:= ${_HAVE_LUA:Mlua-*:S/lua-//}
281 # Select Lua version.
284 .if defined(_LUA_Need_Version)
285 _LUA_Version_Done= yes
288 # Basic component parsing (ignores dependency types).
290 # The variables used are:
291 # _LUA_COMP - Component part.
292 # _LUA_COMPS_FINAL - Final list of components.
295 # Detect duplicated components.
298 .for comp in ${LUA_COMPS}
299 _LUA_COMP= ${comp:C/:([[:alpha:]]+)$//}
300 . for __LUA_COMP in ${_LUA_COMP}
301 . if ${_LUA_COMPS_ALL:M${__LUA_COMP}} == ""
302 IGNORE?= selected an invalid Lua component: ${__LUA_COMP}
305 . for newcomp in ${_LUA_COMP}
306 . if ${_LUA_COMPS_FINAL:M${newcomp}} == ""
307 _LUA_COMPS_FINAL+= ${newcomp}
312 # Set defaults (if one isn't present).
314 USE_LUA?= ${_LUA_VERS_ALL}
318 # Make lists of valid and invalid versions.
320 # The following variables are used:
321 # _LUA_VER_CHECK - If the version is a single one, express in a range.
322 # _LUA_VER_MIN - Lower version of the range.
323 # _LUA_VER_MAX - Higher version of the range.
324 # _LUA_VER_LIST - List of requested versions.
325 # _LUA_VER_NOT_LIST - List of disallowed versions.
326 # _LUA_VER_FINAL - List of requested version without disallowed ones.
329 .for list in VER VER_NOT
331 . for ver in ${USE_LUA${list:C/VER//}}
332 _LUA_VER_CHECK:= ${ver:C/^([[:digit:]]+(\.[[:digit:]]+)*)$/\1-\1/}
333 _LUA_VER_MIN:= ${_LUA_VER_CHECK:C/([[:digit:]]+(\.[[:digit:]]+)*)[-+].*/\1/}
334 _LUA_VER_MAX:= ${_LUA_VER_CHECK:C/.*-([[:digit:]]+(\.[[:digit:]]+)*)/\1/}
335 # Minimum version not specified.
336 . if ${_LUA_VER_MIN} == ${_LUA_VER_CHECK}
338 . for v in ${_LUA_VERS_ALL}
342 # Maximum version not specified.
343 . if ${_LUA_VER_MAX} == ${_LUA_VER_CHECK}
344 . for v in ${_LUA_VERS_ALL}
348 # Expand versions and add valid ones to each list.
349 . for v in ${_LUA_VERS_ALL}
350 . if ${_LUA_VER_MIN} <= ${v} && ${_LUA_VER_MAX} >= ${v} && \
351 ${_LUA_${list}_LIST:M${v}} == ""
352 _LUA_${list}_LIST+= ${v}
358 # Merge the lists into a single list of valid versions.
361 .for ver in ${_LUA_VER_LIST}
362 . if ${_LUA_VER_NOT_LIST:M${ver}} == ""
363 _LUA_VER_FINAL+= ${ver}
367 # Remove unusable installed versions.
369 .for ver in ${_LUA_VER_INSTALLED}
370 . if ${_LUA_VER_FINAL:M${ver}} == ""
371 _LUA_VER_INSTALLED:= ${_LUA_VER_INSTALLED:N${ver}}
375 # Check for a null version.
377 .if empty(_LUA_VER_FINAL)
378 IGNORE?= selected a null or invalid Lua version
381 # Avoid versions which have unavailable components.
383 .for ver in ${_LUA_VER_FINAL}
384 . for comp in ${_LUA_COMPS_FINAL}
385 . if !defined(_LUA_PORT_${comp}_${ver})
386 _LUA_WRONG_COMPS+= ${comp}
387 _LUA_WRONG_VERS+= ${ver}
388 _LUA_VER_FINAL:= ${_LUA_VER_FINAL:N${ver}}
393 .if empty(_LUA_VER_FINAL)
394 IGNORE?= selected Lua versions (${_LUA_WRONG_VERS}) which do not have the selected components (${_LUA_WRONG_COMPS})
398 # Choose final version.
402 # Check for the following (in order):
403 # 1) WITH_LUA_VER - User preference.
404 # 2) WANT_LUA_VER - Port preference.
405 # 3) _LUA_VER_INSTALLED - Installed versions.
406 # 4) _LUA_VER_FINAL - Available versions.
409 .for list in _LUA_VER_FINAL ${_LUA_VERS_LISTS}
410 . if defined(${list})
411 . for ver in ${${list}}
412 . if ${_LUA_VER_FINAL:M${ver}} != ""
424 LUA_VER?= ${_LUA_VER}
425 LUA_VER_SH?= ${LUA_VER:C/[[:digit:]]\.([[:digit:]])/\1/}
426 LUA_VER_STR?= ${LUA_VER:S/.//g}
429 LUA_PKGNAMEPREFIX?= lua${LUA_VER_STR}-
430 LUA_SUBDIR?= lua${LUA_VER_STR}
432 # Currently Lua ports (those which install Lua and modules) must either:
433 # 1. Have PORTNAME=lua and LATEST_LINK=${LUA_SUBDIR} (currently Lua ports).
434 # 2. Have PKGNAMEPREFIX=${LUA_PKGNAMEPREFIX} (currently Lua modules).
435 # 3. Have LUA_PREFIX?=${PREFIX} (currently none).
437 # FIXME: the correct solution to this problem could be either:
438 # 1. Create a lua*-config script, and make dependent ports use it.
439 # 2. Set in each port if it's a "Lua module", or just requires Lua.
442 .if (defined(PKGNAMEPREFIX) && ${PKGNAMEPREFIX} == ${LUA_PKGNAMEPREFIX}) || \
443 (${PORTNAME} == "lua" && defined(LATEST_LINK) && \
444 ${LATEST_LINK} == ${LUA_SUBDIR})
445 # For Lua and modules, which need to install in LUA_*DIR, respect PREFIX.
446 LUA_PREFIX?= ${PREFIX}
448 # For dependencies using LUA_{INC,LIB}DIR, use LOCALBASE as expected.
449 LUA_PREFIX?= ${LOCALBASE}
453 LUA_BINDIR?= ${LUA_PREFIX}/bin/${LUA_SUBDIR}
454 LUA_INCDIR?= ${LUA_PREFIX}/include/${LUA_SUBDIR}
455 LUA_LIBDIR?= ${LUA_PREFIX}/lib/${LUA_SUBDIR}
456 LUA_MODLIBDIR?= ${LUA_PREFIX}/lib/lua/${LUA_VER}
457 LUA_MODSHAREDIR?= ${LUA_PREFIX}/share/lua/${LUA_VER}
460 LUA_CMD?= ${LUA_PREFIX}/bin/lua-${LUA_VER}
461 LUAC_CMD?= ${LUA_PREFIX}/bin/luac-${LUA_VER}
462 TOLUA_CMD?= ${LUA_PREFIX}/bin/tolua-${LUA_VER}
463 TOLUAXX_CMD?= ${LUA_PREFIX}/bin/tolua++-${LUA_VER}
465 .endif # _LUA_Need_Version
468 # Process components list and add dependencies, variables, etc.
471 .if defined(_POSTMKINCLUDED)
476 # The variables used are:
477 # _LUA_COMP - Component part.
478 # _LUA_DEP_TYPE - Dependency type part.
479 # _LUA_COMP_NEW - Component + dependency type.
480 # _LUA_COMPS_FINAL - Final list of components with dependency types.
483 # Default components.
487 # Detect invalid and duplicated components.
490 .for comp in ${LUA_COMPS}
491 _LUA_COMP= ${comp:C/:([[:alpha:]]+)$//}
492 . if ${_LUA_COMP} == ${comp}
493 _LUA_DEP_TYPE= ${_LUA_DEPTYPE_${comp}_${_LUA_VER}}
495 _LUA_DEP_TYPE= ${comp:C/.+:([[:alpha:]]+)$/\1/}
497 _LUA_COMP_NEW= ${_LUA_COMP}_${_LUA_DEP_TYPE}
498 . for __LUA_COMP in ${_LUA_COMP}
499 . if ${_LUA_COMPS_ALL:M${__LUA_COMP}} == ""
500 IGNORE?= selected an invalid Lua component: ${__LUA_COMP}
503 . for __LUA_DEP_TYPE in ${_LUA_DEP_TYPE}
504 . if ${_LUA_DEP_TYPES_ALL:M${__LUA_DEP_TYPE}} == ""
505 IGNORE?= selected an invalid Lua dependency type: ${__LUA_DEP_TYPE}
508 . if !defined(_LUA_PORT_${_LUA_COMP}_${_LUA_VER})
509 IGNORE?= selected a Lua component (${_LUA_COMP}) which is not available for the selected version (${_LUA_VER})
511 . for newcomp in ${_LUA_COMP_NEW}
512 . if ${_LUA_COMPS_FINAL:M${newcomp}} == "" && !defined(IGNORE)
513 _LUA_COMPS_FINAL+= ${newcomp}
520 # The variable used are:
521 # _LUA_COMP - - Component part.
522 # _LUA_DEP_TYPE - Dependency type part.
524 .for comp in ${_LUA_COMPS_FINAL}
525 _LUA_DEP_TYPE= ${comp:C/.+_([[:alpha:]]+)$/\1/}
526 _LUA_COMP= ${comp:C/_([[:alpha:]]+)$//}
527 # XXX Need a .for loop here so the variable is expanded before the assignment.
528 . for comp_part in ${_LUA_COMP}
529 . if ${_LUA_DEP_TYPE} == "lib"
530 . if defined(_LUA_LIB_${comp_part}_${_LUA_VER})
531 LIB_DEPENDS+= ${_LUA_LIB_${comp_part}_${_LUA_VER}}:${PORTSDIR}/${_LUA_PORT_${comp_part}_${_LUA_VER}}
533 BUILD_DEPENDS+= ${_LUA_FILE_${comp_part}_${_LUA_VER}}:${PORTSDIR}/${_LUA_PORT_${comp_part}_${_LUA_VER}}
534 RUN_DEPENDS+= ${_LUA_FILE_${comp_part}_${_LUA_VER}}:${PORTSDIR}/${_LUA_PORT_${comp_part}_${_LUA_VER}}
537 ${_LUA_DEP_TYPE:tu}_DEPENDS+= ${_LUA_FILE_${comp_part}_${_LUA_VER}}:${PORTSDIR}/${_LUA_PORT_${comp_part}_${_LUA_VER}}
542 # Packaging list variables.
543 .for var in ${_LUA_PLIST_ALL}
544 PLIST_SUB+= ${var}="${${var}}"
546 .for var in ${_LUA_PLIST_DIR_ALL}
547 PLIST_SUB+= ${var}="${${var}:S/${LUA_PREFIX}\///}"
549 .for var in ${_LUA_PLIST_ALL} ${_LUA_PLIST_DIR_ALL}
550 MAKE_ENV+= ${var}="${${var}}"
553 .endif # _POSTMKINCLUDED