diff options
author | william <william@25thandclement.com> | 2015-04-22 15:50:23 -0700 |
---|---|---|
committer | william <william@25thandclement.com> | 2015-04-22 15:50:23 -0700 |
commit | 753b60b0f479e226ecdf7e781804906aa8ee369f (patch) | |
tree | 9ccbb398cc17d22aa7cdad3c5eac9a9c9b40c1dc /mk | |
parent | b6ce57a198ed27f314b7183a0876c30f719ef69b (diff) | |
download | luaossl-753b60b0f479e226ecdf7e781804906aa8ee369f.tar.gz luaossl-753b60b0f479e226ecdf7e781804906aa8ee369f.tar.bz2 luaossl-753b60b0f479e226ecdf7e781804906aa8ee369f.zip |
update luapath script
Diffstat (limited to 'mk')
-rwxr-xr-x | mk/lua.path | 459 |
1 files changed, 402 insertions, 57 deletions
diff --git a/mk/lua.path b/mk/lua.path index eb10d39..8df41c9 100755 --- a/mk/lua.path +++ b/mk/lua.path | |||
@@ -22,7 +22,7 @@ | |||
22 | # warned. | 22 | # warned. |
23 | # | 23 | # |
24 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | 24 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
25 | # | 25 | # |
26 | # Changelog: | 26 | # Changelog: |
27 | # | 27 | # |
28 | # * 2013-08-02 - Published. Derived from an earlier script, lua.path, | 28 | # * 2013-08-02 - Published. Derived from an earlier script, lua.path, |
@@ -50,9 +50,41 @@ | |||
50 | # | 50 | # |
51 | # * 2013-10-22 - Initial ldflags detection. | 51 | # * 2013-10-22 - Initial ldflags detection. |
52 | # | 52 | # |
53 | # * 2014-01-26 - Migrate CC vendor detection from external script. | ||
54 | # | ||
55 | # * 2014-09-29 - Add ldir and cdir modes which print install path by parsing | ||
56 | # package.path and package.cpath. | ||
57 | # | ||
58 | # * 2014-12-18 - Add -e GLOB option. | ||
59 | # | ||
60 | # Deprecate ldir and cdir modes. | ||
61 | # | ||
62 | # Add package.path and package.cpath to replace ldir and dir modes. | ||
63 | # Optional arguments to the new modes are preferred install paths, | ||
64 | # rather than globs for finding the lua utility path (use the new -e | ||
65 | # option, instead). | ||
66 | # | ||
67 | # * 2014-12-19 - Fix pkg-config version matching. The --modversion of | ||
68 | # the lua package might be stale. For example, it's 5.2.0 on Ubuntu | ||
69 | # 14.04 even though the Lua release is 5.2.3. | ||
70 | # | ||
71 | # Use the interpreter path as a reference point when searching for | ||
72 | # headers. $(dirname ${LUA_PATH})/../include is a very likely location | ||
73 | # as bindir and includedir have the same prefix in most installations. | ||
74 | # | ||
75 | # * 2015-01-15 - Quote more command names and arguments. Still need to | ||
76 | # handle space characters in code that employs command substitution. I | ||
77 | # think we could handle all whitespace characters, including newlines, | ||
78 | # by using a control character in IFS and using --exec printf "%s\1" {} | ||
79 | # rather than -print with find(1). | ||
80 | # | ||
81 | # * 2015-01-19 - Add fix for LuaJIT's default package.cpath, which tends to | ||
82 | # hardcode /usr/local/lib/lua/5.1, ordered before the LuaJIT | ||
83 | # installation prefix. | ||
84 | # | ||
53 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | 85 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
54 | # | 86 | # |
55 | # Copyright (C) 2012-2013 William Ahern | 87 | # Copyright (C) 2012-2015 William Ahern |
56 | # | 88 | # |
57 | # Permission is hereby granted, free of charge, to any person obtaining a | 89 | # Permission is hereby granted, free of charge, to any person obtaining a |
58 | # copy of this software and associated documentation files (the "Software"), | 90 | # copy of this software and associated documentation files (the "Software"), |
@@ -81,8 +113,10 @@ export LC_ALL=C # no locale headaches | |||
81 | unset IFS # no field splitting surprises | 113 | unset IFS # no field splitting surprises |
82 | : ${TMPDIR:=/tmp} # sane TMPDIR | 114 | : ${TMPDIR:=/tmp} # sane TMPDIR |
83 | : ${CC:=cc} | 115 | : ${CC:=cc} |
116 | unset LUA_PATH || true # interferes search for module install directory | ||
117 | unset LUA_CPATH || true | ||
84 | 118 | ||
85 | MYVERSION=20131025 | 119 | MYVERSION=20150119 |
86 | MYVENDOR="william@25thandClement.com" | 120 | MYVENDOR="william@25thandClement.com" |
87 | 121 | ||
88 | 122 | ||
@@ -99,6 +133,10 @@ MAXDEPTH= # full command switch, like "-maxdepth 3", if supported | |||
99 | XDEV= # do not cross device boundaries; i.e. "-xdev" | 133 | XDEV= # do not cross device boundaries; i.e. "-xdev" |
100 | SHORTEST= # continue searching until shortest pathname found | 134 | SHORTEST= # continue searching until shortest pathname found |
101 | PKGCONFIG= # path to pkg-config, found by `command -v` when -k option invoked | 135 | PKGCONFIG= # path to pkg-config, found by `command -v` when -k option invoked |
136 | GLOB= # -e GLOB expression for lua, luac, ldir, and cdir | ||
137 | |||
138 | GLOB_LUA="lua:lua[5-9]*:lua-[5-9]*:luajit*" | ||
139 | GLOB_LUAC="luac:luac[5-9]*:luac-[5-9]*" | ||
102 | 140 | ||
103 | API_MIN=500 | 141 | API_MIN=500 |
104 | API_MAX=999 | 142 | API_MAX=999 |
@@ -135,7 +173,7 @@ xdirs() { | |||
135 | 173 | ||
136 | set -- ${2:-} | 174 | set -- ${2:-} |
137 | 175 | ||
138 | while [ $# -gt 0 ]; do | 176 | while [ $# -gt 0 ]; do |
139 | case "${1}" in | 177 | case "${1}" in |
140 | -${OPTC}) | 178 | -${OPTC}) |
141 | shift | 179 | shift |
@@ -167,27 +205,42 @@ ldirs() { | |||
167 | xdirs "L" "${1:-}" | 205 | xdirs "L" "${1:-}" |
168 | } | 206 | } |
169 | 207 | ||
170 | # count ":" delimited directories generated by xdirs | 208 | # count ":"-delimited substrings |
171 | ndirs() { | 209 | count() { |
172 | IFS=: | 210 | IFS=: |
173 | set -- ${1:-} | 211 | set -- ${1:-} |
174 | unset IFS | 212 | unset IFS |
175 | 213 | ||
176 | printf "$#\n" | 214 | printf "$#" |
177 | } | 215 | } |
178 | 216 | ||
217 | # append to ":"-delimited string variable | ||
218 | append() { | ||
219 | NAME=${1} | ||
220 | eval VALUE="\${${NAME}}" | ||
221 | shift | ||
222 | |||
223 | IFS=: | ||
224 | TMP="$*" | ||
225 | |||
226 | IFS="\n" | ||
227 | read -r "${NAME}" <<-EOF | ||
228 | ${VALUE:-}${VALUE:+:}${TMP} | ||
229 | EOF | ||
230 | unset IFS | ||
231 | } | ||
179 | 232 | ||
180 | # | 233 | # |
181 | # evalmacro PATH MACRO [REGEX] [SUBST] | 234 | # evalmacro PATH MACRO [REGEX] [SUBST] |
182 | # | 235 | # |
183 | # PATH Header identifier--#include <PATH> | 236 | # PATH Header identifier--#include <PATH> |
184 | # MACRO Macro identifier | 237 | # MACRO Macro identifier |
185 | # REGEX Optional regex pattern to match macro evalutation result | 238 | # REGEX Optional regex pattern to match macro evaluation result |
186 | # SUBST Optional replacement expression | 239 | # SUBST Optional replacement expression |
187 | # | 240 | # |
188 | evalmacro() { | 241 | evalmacro() { |
189 | printf "#include <$1>\n[===[$2]===]\n" \ | 242 | printf "#include <$1>\n[===[$2]===]\n" \ |
190 | | ${CC:-cc} ${CPPFLAGS:-} -E - 2>>/dev/null \ | 243 | | "${CC:-cc}" ${CPPFLAGS:-} -E - 2>>/dev/null \ |
191 | | sed -ne " | 244 | | sed -ne " |
192 | s/^.*\\[===\\[ *\\(${3:-.*}\\) *\\]===\\].*$/${4:-\\1}/ | 245 | s/^.*\\[===\\[ *\\(${3:-.*}\\) *\\]===\\].*$/${4:-\\1}/ |
193 | t Found | 246 | t Found |
@@ -219,7 +272,7 @@ testsym() { | |||
219 | 272 | ||
220 | 273 | ||
221 | tryluainclude() { | 274 | tryluainclude() { |
222 | V="$(evalmacro ${1} LUA_VERSION_NUM '[0123456789][0123456789]*')" | 275 | V="$(evalmacro "${1}" LUA_VERSION_NUM '[0123456789][0123456789]*')" |
223 | : ${V:=0} | 276 | : ${V:=0} |
224 | 277 | ||
225 | if [ "${1%/*}" != "${1}" ]; then | 278 | if [ "${1%/*}" != "${1}" ]; then |
@@ -242,7 +295,7 @@ tryluainclude() { | |||
242 | [ "$V" -ge "${API_MIN}" -a "$V" -le "${API_MAX}" ] || return 0 | 295 | [ "$V" -ge "${API_MIN}" -a "$V" -le "${API_MAX}" ] || return 0 |
243 | 296 | ||
244 | if [ -n "${JIT_REQ}" ]; then | 297 | if [ -n "${JIT_REQ}" ]; then |
245 | J="$(evalmacro ${1%%lua.h}luajit.h LUAJIT_VERSION_NUM '[0123456789][0123456789]*')" | 298 | J="$(evalmacro "${1%%lua.h}luajit.h" LUAJIT_VERSION_NUM '[0123456789][0123456789]*')" |
246 | : ${J:=0} | 299 | : ${J:=0} |
247 | 300 | ||
248 | if [ "${JIT_REQ}" = "skip" ]; then | 301 | if [ "${JIT_REQ}" = "skip" ]; then |
@@ -286,6 +339,167 @@ foundversion() { | |||
286 | 339 | ||
287 | 340 | ||
288 | # | 341 | # |
342 | # luapc | ||
343 | # | ||
344 | # wrapper around `pkg-config ... LIB`, where LIB is derived by | ||
345 | # searching for all libraries with "lua" in the name that have a | ||
346 | # --modversion equal to the release version printed by ${LUA_PATH} -v. | ||
347 | # | ||
348 | LUAPC_LIB= | ||
349 | |||
350 | luapc() { | ||
351 | [ -n "${LUA_PATH}" ] || return 0 | ||
352 | |||
353 | [ -n "${PKGCONFIG}" ] || return 0 | ||
354 | |||
355 | # find pkg-config library name | ||
356 | if [ -z "${LUAPC_LIB}" ]; then | ||
357 | V="$("${LUA_PATH}" -v </dev/null 2>&1 | head -n1 | sed -ne 's/^Lua[^ ]* \([0123456789][0123456789]*\(\.[0123456789][0123456789]*\)*\).*/\1/p')" | ||
358 | |||
359 | [ -n "${V}" ] || return 0 | ||
360 | |||
361 | V_N=$(mmp2num "${V}") | ||
362 | |||
363 | for LIB in $("${PKGCONFIG}" --list-all </dev/null 2>>/dev/null | sed -ne 's/^\(lua[^ ]*\).*/\1/p'); do | ||
364 | M="$("${PKGCONFIG}" --modversion ${LIB} || true)" | ||
365 | |||
366 | # break immediately on exact match | ||
367 | if [ "${V}" = "${M}" ]; then | ||
368 | LUAPC_LIB="${LIB}" | ||
369 | |||
370 | break | ||
371 | fi | ||
372 | |||
373 | # | ||
374 | # NOTE: On Ubuntu 14.04 pkg-config --modversion | ||
375 | # lua5.2 prints 5.2.0 even though the release | ||
376 | # version is 5.2.3 (what lua5.2 -v prints). | ||
377 | # | ||
378 | # If the major.minor components match, then | ||
379 | # tentatively use that package name. | ||
380 | # | ||
381 | M_N=$(mmp2num "${M}" 0 0 0) | ||
382 | |||
383 | if [ "$((${V_N} / 100))" -eq "$((${M_N} / 100))" ]; then | ||
384 | LUAPC_LIB="${LIB}" | ||
385 | fi | ||
386 | done | ||
387 | |||
388 | [ -n "${LUAPC_LIB}" ] || return 0 | ||
389 | fi | ||
390 | |||
391 | ${PKGCONFIG} "$@" "${LUAPC_LIB}" </dev/null 2>>/dev/null || true | ||
392 | } | ||
393 | |||
394 | |||
395 | # | ||
396 | # findinstalldir package.path|package.cpath [preferred-path ...] | ||
397 | # | ||
398 | findinstalldir() { | ||
399 | V_DIR=$((${LUA_VER} / 100 % 100)).$((${LUA_VER} % 100)) | ||
400 | |||
401 | if [ "${1}" = "package.cpath" ]; then | ||
402 | DIR="$(luapc --variable INSTALL_CMOD)" | ||
403 | [ -n "${DIR}" ] && set -- "$@" "${DIR}" | ||
404 | |||
405 | DIR="$(luapc --variable INSTALL_LIB)" | ||
406 | [ -n "${DIR}" ] && set -- "$@" "${DIR}/lua/${V_DIR}" | ||
407 | |||
408 | DIR="$(luapc --variable libdir)" | ||
409 | [ -n "${DIR}" ] && set -- "$@" "${DIR}/lua/${V_DIR}" | ||
410 | |||
411 | DIR="$(luapc --variable prefix)" | ||
412 | [ -n "${DIR}" ] && set -- "$@" "${DIR}/lib/lua/${V_DIR}" | ||
413 | |||
414 | # LuaJIT installations tend to include | ||
415 | # /usr/local/lib/lua/5.1 as one of the first paths, ordered | ||
416 | # before the LuaJIT installation prefix, and regardless of | ||
417 | # whether there exists a /usr/local/lib/lua/5.1. | ||
418 | set -- "$@" "${LUA_PATH}/../../lib/lua/${V_DIR}" | ||
419 | set -- "$@" "${LUA_PATH}/../../lib/*/lua/${V_DIR}" # e.g. lib/x86_64-linux-gnu | ||
420 | else | ||
421 | DIR="$(luapc --variable INSTALL_LMOD)" | ||
422 | [ -n "${DIR}" ] && set -- "$@" "${DIR}" | ||
423 | |||
424 | DIR="$(luapc --variable prefix)" | ||
425 | [ -n "${DIR}" ] && set -- "$@" "${DIR}/share/lua/${V_DIR}" | ||
426 | |||
427 | # See above LuaJIT note. Although the built-in package.path | ||
428 | # usually orders the LuaJIT installation prefix first. | ||
429 | set -- "$@" "${LUA_PATH}/../../share/lua/${V_DIR}" | ||
430 | fi | ||
431 | |||
432 | ARRAY="${1}" | ||
433 | shift | ||
434 | |||
435 | if [ $# -eq 0 ]; then | ||
436 | set -- "/nonexistent" # cannot expand empty $@ on some implementations | ||
437 | fi | ||
438 | |||
439 | "${LUA_PATH}" - "$@" <<-EOF | ||
440 | -- | ||
441 | -- actual pkg-config variable on Ubuntu 14.04 | ||
442 | -- | ||
443 | -- /usr//share/lua/5.1 | ||
444 | -- | ||
445 | local function fixpath(path) | ||
446 | local stack = { path:match"^/" and "" or "." } | ||
447 | |||
448 | for ent in path:gmatch"([^/]+)" do | ||
449 | if ent == ".." and #stack > 1 then | ||
450 | stack[#stack] = nil | ||
451 | elseif ent ~= "." then | ||
452 | stack[#stack + 1] = ent | ||
453 | end | ||
454 | end | ||
455 | |||
456 | return table.concat(stack, "/") | ||
457 | end | ||
458 | |||
459 | local function topattern(path) | ||
460 | if string.match(path, "*") then | ||
461 | path = string.gsub(path, "%%", "%%") | ||
462 | return string.gsub(path, "*", "[^/]+") | ||
463 | end | ||
464 | end | ||
465 | |||
466 | local dirs = { } | ||
467 | |||
468 | for dir in ${ARRAY}:gmatch"([^;?]+)/" do | ||
469 | dir = fixpath(dir) | ||
470 | |||
471 | if dir ~= "." then | ||
472 | dirs[#dirs + 1] = dir | ||
473 | end | ||
474 | end | ||
475 | |||
476 | for _, arg in ipairs{ ... } do | ||
477 | arg = fixpath(arg) | ||
478 | |||
479 | local pat = topattern(arg) | ||
480 | |||
481 | for _, dir in ipairs(dirs) do | ||
482 | if arg == dir then | ||
483 | print(dir) | ||
484 | os.exit(0) | ||
485 | elseif pat and string.match(dir, pat) then | ||
486 | print(dir) | ||
487 | os.exit(0) | ||
488 | end | ||
489 | end | ||
490 | end | ||
491 | |||
492 | if dirs[1] then | ||
493 | print(dirs[1]) | ||
494 | os.exit(0) | ||
495 | else | ||
496 | os.exit(1) | ||
497 | end | ||
498 | EOF | ||
499 | } | ||
500 | |||
501 | |||
502 | # | ||
289 | # findversion | 503 | # findversion |
290 | # | 504 | # |
291 | findversion() { | 505 | findversion() { |
@@ -315,7 +529,7 @@ findversion() { | |||
315 | 529 | ||
316 | 530 | ||
317 | if [ -n "${PKGCONFIG}" ]; then | 531 | if [ -n "${PKGCONFIG}" ]; then |
318 | PKGFLAGS="$(${PKGCONFIG} --list-all </dev/null 2>>/dev/null | sed -ne 's/^\(lua[^ ]*\).*/\1/p' | xargs -- ${PKGCONFIG} --cflags 2>>/dev/null | cat)" | 532 | PKGFLAGS="$("${PKGCONFIG}" --list-all </dev/null 2>>/dev/null | sed -ne 's/^\(lua[^ ]*\).*/\1/p' | xargs -- ${PKGCONFIG} --cflags 2>>/dev/null | cat)" |
319 | PKGDIRS="$(idirs "${PKGFLAGS}")" | 533 | PKGDIRS="$(idirs "${PKGFLAGS}")" |
320 | 534 | ||
321 | IFS=: | 535 | IFS=: |
@@ -349,7 +563,10 @@ findversion() { | |||
349 | fi | 563 | fi |
350 | 564 | ||
351 | 565 | ||
352 | [ "${RECURSE}" = "yes" ] || return 0 | 566 | if [ "${RECURSE}" != "yes" ]; then |
567 | [ "${API_VER:-0}" -gt 0 ] | ||
568 | return $? | ||
569 | fi | ||
353 | 570 | ||
354 | 571 | ||
355 | # recurse into CPPDIRS | 572 | # recurse into CPPDIRS |
@@ -359,7 +576,7 @@ findversion() { | |||
359 | 576 | ||
360 | if [ $# -gt 0 ]; then | 577 | if [ $# -gt 0 ]; then |
361 | for D; do | 578 | for D; do |
362 | for F in $(find ${D} ${MAXDEPTH} ${XDEV} -name lua.h -print 2>>/dev/null); do | 579 | for F in $(find "${D}" ${MAXDEPTH} ${XDEV} -name lua.h -print 2>>/dev/null); do |
363 | tryluainclude "${F}" | 580 | tryluainclude "${F}" |
364 | 581 | ||
365 | if foundversion; then | 582 | if foundversion; then |
@@ -377,7 +594,7 @@ findversion() { | |||
377 | 594 | ||
378 | if [ $# -gt 0 ]; then | 595 | if [ $# -gt 0 ]; then |
379 | for D; do | 596 | for D; do |
380 | for F in $(find ${D}/. ${MAXDEPTH} ${XDEV} -name lua.h -print 2>>/dev/null); do | 597 | for F in $(find "${D}/." ${MAXDEPTH} ${XDEV} -name lua.h -print 2>>/dev/null); do |
381 | tryluainclude "${F}" | 598 | tryluainclude "${F}" |
382 | 599 | ||
383 | if foundversion; then | 600 | if foundversion; then |
@@ -386,6 +603,26 @@ findversion() { | |||
386 | done | 603 | done |
387 | done | 604 | done |
388 | fi | 605 | fi |
606 | |||
607 | |||
608 | # if we can find the lua interpreter, use it as a reference for | ||
609 | # header locations. | ||
610 | if findlua; then | ||
611 | D="${LUA_PATH%/*}" | ||
612 | D="${D%/*}/include" | ||
613 | |||
614 | if [ -d "${D}" ]; then | ||
615 | for F in $(find "${D}" ${MAXDEPTH} ${XDEV} -name lua.h -print 2>>/dev/null); do | ||
616 | tryluainclude "${F}" | ||
617 | |||
618 | if foundversion; then | ||
619 | return 0 | ||
620 | fi | ||
621 | done | ||
622 | fi | ||
623 | fi | ||
624 | |||
625 | [ "${API_VER:-0}" -gt 0 ] | ||
389 | } | 626 | } |
390 | 627 | ||
391 | 628 | ||
@@ -487,12 +724,12 @@ foundlib() { | |||
487 | 724 | ||
488 | findlib() { | 725 | findlib() { |
489 | if [ -n "${PKGCONFIG}" ]; then | 726 | if [ -n "${PKGCONFIG}" ]; then |
490 | PKGFLAGS="$(${PKGCONFIG} --list-all </dev/null 2>>/dev/null | sed -ne 's/^\(lua[^ ]*\).*/\1/p' | xargs -- ${PKGCONFIG} --libs 2>>/dev/null | cat)" | 727 | PKGFLAGS="$("${PKGCONFIG}" --list-all </dev/null 2>>/dev/null | sed -ne 's/^\(lua[^ ]*\).*/\1/p' | xargs -- ${PKGCONFIG} --libs 2>>/dev/null | cat)" |
491 | PKGDIRS="$(ldirs "${PKGFLAGS}")" | 728 | PKGDIRS="$(ldirs "${PKGFLAGS}")" |
492 | PKGDIRS="${PKGDIRS}${PKGDIRS:+:}/lib:/usr/lib:/usr/local/lib" | 729 | PKGDIRS="${PKGDIRS}${PKGDIRS:+:}/lib:/usr/lib:/usr/local/lib" |
493 | NUMDIRS="$(ndirs "${PKGDIRS}")" | 730 | NUMDIRS="$(count "${PKGDIRS}")" |
494 | PKGLIBS="$(xdirs "l" "${PKGFLAGS}")" | 731 | PKGLIBS="$(xdirs "l" "${PKGFLAGS}")" |
495 | NUMLIBS="$(ndirs "${PKGLIBS}")" | 732 | NUMLIBS="$(count "${PKGLIBS}")" |
496 | ALLDIRS="${PKGDIRS}${PKGLIBS:+:}${PKGLIBS}" | 733 | ALLDIRS="${PKGDIRS}${PKGLIBS:+:}${PKGLIBS}" |
497 | 734 | ||
498 | IFS=: | 735 | IFS=: |
@@ -575,11 +812,17 @@ safeperm() { | |||
575 | 812 | ||
576 | 813 | ||
577 | findluac() { | 814 | findluac() { |
815 | if [ $# -eq 0 ]; then | ||
816 | IFS=: | ||
817 | set -- ${GLOB:-${GLOB_LUAC}} | ||
818 | unset IFS | ||
819 | fi | ||
820 | |||
578 | while [ $# -gt 0 ]; do | 821 | while [ $# -gt 0 ]; do |
579 | for F in $(findpath "${1}" no "${PATH}"; findpath "${1}" "${RECURSE}" "${BINDIRS}"); do | 822 | for F in $(findpath "${1}" no "${PATH}"; findpath "${1}" "${RECURSE}" "${BINDIRS}"); do |
580 | [ -x "$F" ] && safeperm "$F" || continue | 823 | [ -x "$F" ] && safeperm "$F" || continue |
581 | 824 | ||
582 | V="$($F -v </dev/null 2>&1 | head -n1 | sed -ne 's/^Lua \([0123456789][0123456789]*\.[0123456789][0123456789]*\).*/\1/p')" | 825 | V="$("$F" -v </dev/null 2>&1 | head -n1 | sed -ne 's/^Lua \([0123456789][0123456789]*\.[0123456789][0123456789]*\).*/\1/p')" |
583 | : ${V:=0} | 826 | : ${V:=0} |
584 | V="$((${V%%.*} * 100 + ${V##*.} % 100))" | 827 | V="$((${V%%.*} * 100 + ${V##*.} % 100))" |
585 | 828 | ||
@@ -599,26 +842,46 @@ findluac() { | |||
599 | 842 | ||
600 | shift | 843 | shift |
601 | done | 844 | done |
845 | |||
846 | if [ -n "${LUAC_PATH}" -a -n "${LUAC_VER}" ]; then | ||
847 | return 0 | ||
848 | else | ||
849 | return 1 | ||
850 | fi | ||
851 | } | ||
852 | |||
853 | |||
854 | isinteger() { | ||
855 | I="${1}" | ||
856 | |||
857 | [ "${#I}" -gt 0 ] || return 1 | ||
858 | |||
859 | while [ "${#I}" -gt 0 ]; do | ||
860 | if [ "${I##[0123456789]}" = "${I}" ]; then | ||
861 | return 1 | ||
862 | fi | ||
863 | |||
864 | I=${I##[0123456789]} | ||
865 | done | ||
866 | |||
867 | return 0 | ||
602 | } | 868 | } |
603 | 869 | ||
604 | 870 | ||
605 | checkints() { | 871 | checkints() { |
606 | while [ $# -gt 0 ]; do | 872 | while [ $# -gt 0 ]; do |
607 | I="${1}" | 873 | if ! isinteger "${1}"; then |
608 | while [ "${#I}" -gt 0 ]; do | 874 | printf -- "${0##*/}: ${1}: not a number\n" >&2 |
609 | if [ "${I##[0123456789]}" = "${I}" ]; then | 875 | return 1 |
610 | printf -- "${0##*/}: ${1}: not a number\n" >&2 | 876 | fi |
611 | exit 1 | ||
612 | fi | ||
613 | |||
614 | I=${I##[0123456789]} | ||
615 | done | ||
616 | 877 | ||
617 | shift | 878 | shift |
618 | done | 879 | done |
619 | } | 880 | } |
620 | 881 | ||
621 | 882 | ||
883 | # Only major.minor for matching LUA_VERSION_NUM in lua.h. Also, _VERSION | ||
884 | # only includes major.minor. | ||
622 | lua2num() { | 885 | lua2num() { |
623 | M=0 | 886 | M=0 |
624 | m="${2:-0}" | 887 | m="${2:-0}" |
@@ -636,6 +899,7 @@ lua2num() { | |||
636 | } | 899 | } |
637 | 900 | ||
638 | 901 | ||
902 | # All major.minor.patch for matching LUAJIT_VERSION_NUM in luajit.h. | ||
639 | jit2num() { | 903 | jit2num() { |
640 | M=0 | 904 | M=0 |
641 | m="${2:-0}" | 905 | m="${2:-0}" |
@@ -655,12 +919,45 @@ jit2num() { | |||
655 | } | 919 | } |
656 | 920 | ||
657 | 921 | ||
922 | mmp2num() { | ||
923 | M="${2:-0}" | ||
924 | m="${3:-0}" | ||
925 | p="${4:-0}" | ||
926 | |||
927 | IFS=".+-_" | ||
928 | set -- ${1} | ||
929 | unset IFS | ||
930 | |||
931 | if isinteger "${1:-}"; then | ||
932 | M=${1} | ||
933 | fi | ||
934 | |||
935 | if isinteger "${2:-}"; then | ||
936 | m=${2} | ||
937 | fi | ||
938 | |||
939 | if isinteger "${3:-}"; then | ||
940 | p=${3} | ||
941 | fi | ||
942 | |||
943 | checkints $M $m $p | ||
944 | |||
945 | printf "$((${M} * 10000 + ${m} * 100 + ${p}))\n" | ||
946 | } | ||
947 | |||
948 | |||
658 | findlua() { | 949 | findlua() { |
950 | if [ $# -eq 0 ]; then | ||
951 | IFS=: | ||
952 | set -- ${GLOB:-${GLOB_LUA}} | ||
953 | unset IFS | ||
954 | fi | ||
955 | |||
659 | while [ $# -gt 0 ]; do | 956 | while [ $# -gt 0 ]; do |
660 | for F in $(findpath "${1}" no "${PATH}"; findpath "${1}" "${RECURSE}" "${BINDIRS}"); do | 957 | for F in $(findpath "${1}" no "${PATH}"; findpath "${1}" "${RECURSE}" "${BINDIRS}"); do |
661 | [ -x "$F" ] && safeperm "$F" || continue | 958 | [ -x "$F" ] && safeperm "$F" || continue |
662 | 959 | ||
663 | V="$($F -e 'print(string.match(_VERSION, [[[%d.]+]]))' </dev/null 2>>/dev/null | head -n1 | sed -ne 's/^\([0123456789][0123456789]*\.[0123456789][0123456789]*\).*/\1/p')" | 960 | V="$("$F" -e 'print(string.match(_VERSION, [[[%d.]+]]))' </dev/null 2>>/dev/null | head -n1 | sed -ne 's/^\([0123456789][0123456789]*\.[0123456789][0123456789]*\).*/\1/p')" |
664 | : ${V:=0} | 961 | : ${V:=0} |
665 | V="$((${V%%.*} * 100 + ${V##*.} % 100))" | 962 | V="$((${V%%.*} * 100 + ${V##*.} % 100))" |
666 | 963 | ||
@@ -671,7 +968,7 @@ findlua() { | |||
671 | [ "${V}" -ge "${API_MIN}" -a "${V}" -le "${API_MAX}" ] || continue | 968 | [ "${V}" -ge "${API_MIN}" -a "${V}" -le "${API_MAX}" ] || continue |
672 | 969 | ||
673 | if [ -n "${JIT_REQ}" ]; then | 970 | if [ -n "${JIT_REQ}" ]; then |
674 | J="$($F -v </dev/null 2>&1 | head -n1 | sed -ne 's/^LuaJIT \([0123456789][0123456789]*\.[0123456789][0123456789]*\.[0123456789][0123456789]*\).*/\1/p')" | 971 | J="$("$F" -v </dev/null 2>&1 | head -n1 | sed -ne 's/^LuaJIT \([0123456789][0123456789]*\.[0123456789][0123456789]*\.[0123456789][0123456789]*\).*/\1/p')" |
675 | J="$(jit2num ${J:-0})" | 972 | J="$(jit2num ${J:-0})" |
676 | 973 | ||
677 | if [ "${JIT_REQ}" = "skip" ]; then | 974 | if [ "${JIT_REQ}" = "skip" ]; then |
@@ -691,12 +988,33 @@ findlua() { | |||
691 | 988 | ||
692 | shift | 989 | shift |
693 | done | 990 | done |
991 | |||
992 | if [ -n "${LUA_PATH}" -a -n "${LUA_VER}" ]; then | ||
993 | return 0 | ||
994 | else | ||
995 | return 1 | ||
996 | fi | ||
997 | } | ||
998 | |||
999 | |||
1000 | ccname() { | ||
1001 | "${CC}" -E - <<-EOF | awk '/sunpro/||/clang/||/gcc/||/other/{ print $1; exit; }' | ||
1002 | #if defined __SUNPRO_C | ||
1003 | sunpro | ||
1004 | #elif defined __clang__ | ||
1005 | clang | ||
1006 | #elif defined __GNUC__ | ||
1007 | gcc | ||
1008 | #else | ||
1009 | other | ||
1010 | #endif | ||
1011 | EOF | ||
694 | } | 1012 | } |
695 | 1013 | ||
696 | 1014 | ||
697 | usage() { | 1015 | usage() { |
698 | cat <<-EOF | 1016 | cat <<-EOF |
699 | usage: ${0##*/} [-I:L:P:d:Dkrm:xsv:j:JVh] cppflags|ldflags|version|lua|luac | 1017 | usage: ${0##*/} [-I:L:P:d:De:krm:xsv:j:JVh] cppflags|version|lua|luac|... |
700 | -I PATH additional search directory for includes | 1018 | -I PATH additional search directory for includes |
701 | -L PATH additional search directory for libraries | 1019 | -L PATH additional search directory for libraries |
702 | -P PATH additional search directory for binaries | 1020 | -P PATH additional search directory for binaries |
@@ -705,6 +1023,7 @@ usage() { | |||
705 | unless a trailing "/" is present | 1023 | unless a trailing "/" is present |
706 | (default sandbox is \$TMPDIR/${0##*/}-XXXXXXXXXXXXXXXX) | 1024 | (default sandbox is \$TMPDIR/${0##*/}-XXXXXXXXXXXXXXXX) |
707 | -D do not create a sandbox | 1025 | -D do not create a sandbox |
1026 | -e GLOB glob pattern for finding utilities (lua, luac, etc) | ||
708 | -k query pkg-config if available | 1027 | -k query pkg-config if available |
709 | -r recursively search directories | 1028 | -r recursively search directories |
710 | -m MAXDEPTH limit recursion to MAXDEPTH (only for GNU and BSD find) | 1029 | -m MAXDEPTH limit recursion to MAXDEPTH (only for GNU and BSD find) |
@@ -718,15 +1037,16 @@ usage() { | |||
718 | -V print this script's version information | 1037 | -V print this script's version information |
719 | -h print this usage message | 1038 | -h print this usage message |
720 | 1039 | ||
721 | cppflags print derived additional CPPFLAGS necessary | 1040 | cppflags print derived additional CPPFLAGS necessary |
722 | ldflags print derived additional LDFLAGS necessary (TODO) | 1041 | ldflags print derived additional LDFLAGS necessary (TODO) |
723 | version print derived Lua API version | 1042 | version print derived Lua API version |
724 | luac [GLOB] print path to luac utility using optional glob patterns | 1043 | luac print path to luac utility ($(printf "${GLOB_LUA}" | tr ':' ' ')) |
725 | (e.g. "luac5.?"; default is "luac*") | 1044 | lua print path to lua interpreter ($(printf "${GLOB_LUAC}" | tr ':' ' ')) |
726 | lua [GLOB] print path to lua interpreter using optional glob patterns | 1045 | package.path print preferred module install path |
727 | (e.g. "lua luajit"; default is "lua*") | 1046 | package.cpath print preferred C module install path |
728 | evalmacro run internal macro evaluator for debugging | 1047 | ccname print CC name (e.g. sunpro, clang, gcc) |
729 | testsym run internal library symbol reader for debugging | 1048 | evalmacro run internal macro evaluator for debugging |
1049 | testsym run internal library symbol reader for debugging | ||
730 | 1050 | ||
731 | This utility is used to derive compiler flags and filesystem paths | 1051 | This utility is used to derive compiler flags and filesystem paths |
732 | necessary to utilize Lua, LuaJIT, and particular versions thereof. | 1052 | necessary to utilize Lua, LuaJIT, and particular versions thereof. |
@@ -767,7 +1087,7 @@ version() { | |||
767 | } | 1087 | } |
768 | 1088 | ||
769 | 1089 | ||
770 | while getopts I:L:P:d:Dkrm:xsv:j:JVh OPT; do | 1090 | while getopts I:L:P:d:De:krm:xsv:j:JVh OPT; do |
771 | case "${OPT}" in | 1091 | case "${OPT}" in |
772 | I) | 1092 | I) |
773 | INCDIRS="${INCDIRS:-}${INCDIRS:+:}${OPTARG}" | 1093 | INCDIRS="${INCDIRS:-}${INCDIRS:+:}${OPTARG}" |
@@ -784,6 +1104,9 @@ while getopts I:L:P:d:Dkrm:xsv:j:JVh OPT; do | |||
784 | D) | 1104 | D) |
785 | SANDBOX= | 1105 | SANDBOX= |
786 | ;; | 1106 | ;; |
1107 | e) | ||
1108 | GLOB="${GLOB:-}${GLOB:+:}${OPTARG}" | ||
1109 | ;; | ||
787 | k) | 1110 | k) |
788 | PKGCONFIG="$(command -v pkg-config || true)" | 1111 | PKGCONFIG="$(command -v pkg-config || true)" |
789 | ;; | 1112 | ;; |
@@ -857,8 +1180,8 @@ done | |||
857 | shift $(($OPTIND - 1)) | 1180 | shift $(($OPTIND - 1)) |
858 | 1181 | ||
859 | 1182 | ||
860 | for U in ${CC:-cc} find grep od rm rmdir sed xargs; do | 1183 | for U in "${CC:-cc}" find grep od rm rmdir sed xargs; do |
861 | if ! command -v ${U} >>/dev/null 2>&1; then | 1184 | if ! command -v "${U}" >>/dev/null 2>&1; then |
862 | printf -- "${0##*/}: ${U}: command not found\n" >&2 | 1185 | printf -- "${0##*/}: ${U}: command not found\n" >&2 |
863 | fi | 1186 | fi |
864 | done | 1187 | done |
@@ -911,7 +1234,7 @@ fi | |||
911 | 1234 | ||
912 | case "${1:-}" in | 1235 | case "${1:-}" in |
913 | cppflags) | 1236 | cppflags) |
914 | findversion | 1237 | findversion || exit 1 |
915 | 1238 | ||
916 | [ "${API_VER:-0}" -gt 0 ] || exit 1 | 1239 | [ "${API_VER:-0}" -gt 0 ] || exit 1 |
917 | 1240 | ||
@@ -927,9 +1250,7 @@ ldflags) | |||
927 | 1250 | ||
928 | ;; | 1251 | ;; |
929 | version) | 1252 | version) |
930 | findversion | 1253 | findversion || exit 1 |
931 | |||
932 | [ "${API_VER:-0}" -gt 0 ] || exit 1 | ||
933 | 1254 | ||
934 | printf "$(((${API_VER} / 100) % 100)).$((($API_VER) % 100))\n" | 1255 | printf "$(((${API_VER} / 100) % 100)).$((($API_VER) % 100))\n" |
935 | 1256 | ||
@@ -945,31 +1266,55 @@ libv*) | |||
945 | luac) | 1266 | luac) |
946 | shift | 1267 | shift |
947 | 1268 | ||
948 | if [ $# -eq 0 ]; then | 1269 | if [ $# -gt 0 ]; then |
949 | set -- luac\* | 1270 | append GLOB $* |
950 | fi | 1271 | fi |
951 | 1272 | ||
952 | findluac $* | 1273 | findluac || exit 1 |
953 | 1274 | ||
954 | [ -n "${LUAC_PATH}" ] || exit 1 | ||
955 | |||
956 | printf -- "${LUAC_PATH}\n" | 1275 | printf -- "${LUAC_PATH}\n" |
957 | 1276 | ||
958 | ;; | 1277 | ;; |
959 | lua) | 1278 | lua) |
960 | shift | 1279 | shift |
961 | 1280 | ||
962 | if [ $# -eq 0 ]; then | 1281 | if [ $# -gt 0 ]; then |
963 | set -- lua\* | 1282 | append GLOB $* |
964 | fi | 1283 | fi |
965 | 1284 | ||
966 | findlua $* | 1285 | findlua || exit 1 |
967 | 1286 | ||
968 | [ -n "${LUA_PATH}" ] || exit 1 | ||
969 | |||
970 | printf -- "${LUA_PATH}\n" | 1287 | printf -- "${LUA_PATH}\n" |
971 | 1288 | ||
972 | ;; | 1289 | ;; |
1290 | ldir|cdir) | ||
1291 | printf -- "${0##*/}: ${1}: deprecated command\n" >&2 | ||
1292 | MODE="${1}" | ||
1293 | shift | ||
1294 | |||
1295 | if [ $# -gt 0 ]; then | ||
1296 | append GLOB $* | ||
1297 | fi | ||
1298 | |||
1299 | findlua || exit 1 | ||
1300 | |||
1301 | if [ "${MODE}" = "cdir" ]; then | ||
1302 | findinstalldir package.cpath | ||
1303 | else | ||
1304 | findinstalldir package.path | ||
1305 | fi | ||
1306 | |||
1307 | ;; | ||
1308 | package.path|package.cpath) | ||
1309 | findlua || exit 1 | ||
1310 | |||
1311 | findinstalldir "$@" || exit 1 | ||
1312 | |||
1313 | ;; | ||
1314 | ccname) | ||
1315 | ccname | ||
1316 | |||
1317 | ;; | ||
973 | evalmacro) | 1318 | evalmacro) |
974 | shift | 1319 | shift |
975 | 1320 | ||