aboutsummaryrefslogtreecommitdiffstats
path: root/mk
diff options
context:
space:
mode:
authorLibravatarLibravatar William Ahern <william@25thandclement.com> 2016-06-24 21:59:02 -0700
committerLibravatarLibravatar William Ahern <william@25thandclement.com> 2016-06-24 21:59:02 -0700
commitd99465ce769657b6946190377cc8a5223f5e8261 (patch)
treed4ff546c128543fbe97dc39c8fd8ac4d2f6a3a5a /mk
parent81bbb1fa5e14a1911cfd99f4ee791ed1e340602e (diff)
downloadluaossl-d99465ce769657b6946190377cc8a5223f5e8261.tar.gz
luaossl-d99465ce769657b6946190377cc8a5223f5e8261.tar.bz2
luaossl-d99465ce769657b6946190377cc8a5223f5e8261.zip
upgrade luapath script
Diffstat (limited to 'mk')
-rwxr-xr-xmk/luapath (renamed from mk/lua.path)513
1 files changed, 343 insertions, 170 deletions
diff --git a/mk/lua.path b/mk/luapath
index 8df41c9..fe5fc9f 100755
--- a/mk/lua.path
+++ b/mk/luapath
@@ -26,10 +26,10 @@
# Changelog:
#
# * 2013-08-02 - Published. Derived from an earlier script, lua.path,
-# written for the cqueues project.
+# written for the cqueues project.
#
# * 2013-08-05 - Redirect stdin from /dev/null when probing so we don't
-# freeze if a utility tries to read from stdin.
+# freeze if a utility tries to read from stdin.
#
# chdir to a read-only directory by default to try to prevent creation
# of temporary files. These features address the issues of LuaTeX
@@ -82,9 +82,31 @@
# hardcode /usr/local/lib/lua/5.1, ordered before the LuaJIT
# installation prefix.
#
+# * 2015-07-14 - Add recursive glob function implemented in shell code
+# and use instead of find(1).
+#
+# * 2016-03-18 - Fix bug in tryluac where a continue statement was used
+# instead of return 0.
+#
+# * 2016-03-25 - Support ${CC} values with trailing flags, which invoke
+# the compiler through env(1), or which otherwise are intended to
+# expand as multiple words.
+#
+# OpenBSD 5.8 sh does not suppress strict errors within an eval
+# invoked from an if condition compound-list. Workaround by changing
+# trylua to return 0 on matching failure, like tryluainclude and
+# tryluac do.
+#
+# Undeprecate ldir and cdir. The names are more intuitive and
+# convenient as evidenced by the fact that I keep using them instead
+# of package.path and package.cpath. Try to maintain backwards
+# compatibility by using a simple heuristic to differentiate lua
+# interpreter glob patterns from preferred install directory
+# string.match expressions.
+#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Copyright (C) 2012-2015 William Ahern
+# Copyright (C) 2012-2016 William Ahern
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
@@ -116,7 +138,7 @@ unset IFS # no field splitting surprises
unset LUA_PATH || true # interferes search for module install directory
unset LUA_CPATH || true
-MYVERSION=20150119
+MYVERSION=20160325
MYVENDOR="william@25thandClement.com"
@@ -129,8 +151,7 @@ LDDIRS= # -L directories from LDFLAGS
LIBDIRS=
BINDIRS=
RECURSE=no
-MAXDEPTH= # full command switch, like "-maxdepth 3", if supported
-XDEV= # do not cross device boundaries; i.e. "-xdev"
+MAXDEPTH=5 # maximum recursion depth
SHORTEST= # continue searching until shortest pathname found
PKGCONFIG= # path to pkg-config, found by `command -v` when -k option invoked
GLOB= # -e GLOB expression for lua, luac, ldir, and cdir
@@ -165,6 +186,27 @@ LUA_VER=
#
+# warn FORMAT [...]
+#
+# Print message to original stderr.
+#
+exec 9>&2
+warn() {
+ printf "%s: %.0s${1}\n" "${0##*/}" "$@" >&9
+}
+
+#
+# panic FORMAT [...]
+#
+# Print message to original stderr, then exit with failure.
+#
+panic() {
+ warn "$@"
+ exit 1
+}
+
+
+#
# parse CPPFLAGS -I or LDFLAGS -L directories
#
xdirs() {
@@ -231,6 +273,46 @@ append() {
}
#
+# glob PATTERN [MAXDEPTH] [EXEC-COMMAND] [INTERNAL:GLOB-COUNT]
+#
+glob() {
+ glob_N="${4:-0}"
+
+ IFS=
+ set +f
+ for F in ${1}; do
+ [ -e "${F}" ] || continue
+ if eval "${3:-printf '%s\\n'} \"\${F}\""; then
+ glob_N=$((${glob_N} + 1))
+ fi
+ done
+ set -f
+ unset IFS
+
+ if [ "${2-0}" -gt 0 ]; then
+ glob "${1%/*}/*/${1##*/}" "$((${2} - 1))" "${3:-}" "${glob_N}" || :
+ fi
+
+ [ "${glob_N}" -gt 0 ]
+} # glob
+
+
+#
+# runcc [...]
+#
+# Wrapper for invoking ${CC}. Some build system include flags in ${CC},
+# invoke the compiler through env(1), or employ other hacks.
+#
+# TODO: Optionally handle unescaping of words in a manner similar to how
+# ${CC} would be evaluated from a make rule--typically by being passed
+# through system(3).
+#
+runcc() {
+ (unset IFS; exec ${CC} "$@")
+}
+
+
+#
# evalmacro PATH MACRO [REGEX] [SUBST]
#
# PATH Header identifier--#include <PATH>
@@ -240,7 +322,7 @@ append() {
#
evalmacro() {
printf "#include <$1>\n[===[$2]===]\n" \
- | "${CC:-cc}" ${CPPFLAGS:-} -E - 2>>/dev/null \
+ | runcc ${CPPFLAGS:-} -E - 2>>/dev/null \
| sed -ne "
s/^.*\\[===\\[ *\\(${3:-.*}\\) *\\]===\\].*$/${4:-\\1}/
t Found
@@ -267,7 +349,7 @@ testsym() {
# and within [A-T].
(nm -Pg ${1} 2>>/dev/null || nm -g 2>>/dev/null) \
| sed -ne '/ [A-T] /p' \
- | grep -qE "${2}"
+ | grep -q "${2}"
}
@@ -398,7 +480,9 @@ luapc() {
findinstalldir() {
V_DIR=$((${LUA_VER} / 100 % 100)).$((${LUA_VER} % 100))
- if [ "${1}" = "package.cpath" ]; then
+ if [ "${1}" = "package.cpath" -o "${1}" = "cdir" ]; then
+ ARRAY="package.cpath"
+
DIR="$(luapc --variable INSTALL_CMOD)"
[ -n "${DIR}" ] && set -- "$@" "${DIR}"
@@ -418,6 +502,8 @@ findinstalldir() {
set -- "$@" "${LUA_PATH}/../../lib/lua/${V_DIR}"
set -- "$@" "${LUA_PATH}/../../lib/*/lua/${V_DIR}" # e.g. lib/x86_64-linux-gnu
else
+ ARRAY="package.path"
+
DIR="$(luapc --variable INSTALL_LMOD)"
[ -n "${DIR}" ] && set -- "$@" "${DIR}"
@@ -429,7 +515,6 @@ findinstalldir() {
set -- "$@" "${LUA_PATH}/../../share/lua/${V_DIR}"
fi
- ARRAY="${1}"
shift
if [ $# -eq 0 ]; then
@@ -576,13 +661,11 @@ findversion() {
if [ $# -gt 0 ]; then
for D; do
- for F in $(find "${D}" ${MAXDEPTH} ${XDEV} -name lua.h -print 2>>/dev/null); do
- tryluainclude "${F}"
+ glob "${D}/lua.h" "${MAXDEPTH}" tryluainclude || :
- if foundversion; then
- return 0
- fi
- done
+ if foundversion; then
+ return 0
+ fi
done
fi
@@ -594,13 +677,11 @@ findversion() {
if [ $# -gt 0 ]; then
for D; do
- for F in $(find "${D}/." ${MAXDEPTH} ${XDEV} -name lua.h -print 2>>/dev/null); do
- tryluainclude "${F}"
+ glob "${D}/lua.h" "${MAXDEPTH}" tryluainclude || :
- if foundversion; then
- return 0
- fi
- done
+ if foundversion; then
+ return 0
+ fi
done
fi
@@ -612,13 +693,11 @@ findversion() {
D="${D%/*}/include"
if [ -d "${D}" ]; then
- for F in $(find "${D}" ${MAXDEPTH} ${XDEV} -name lua.h -print 2>>/dev/null); do
- tryluainclude "${F}"
+ glob "${D}/lua.h" "${MAXDEPTH}" tryluainclude || :
- if foundversion; then
- return 0
- fi
- done
+ if foundversion; then
+ return 0
+ fi
fi
fi
@@ -631,9 +710,10 @@ findversion() {
# compatible.
#
trylib() {
- if ! testsym "${1}" "lua_newstate"; then
- return 0
- fi
+ testsym "${1}" "lua_newstate" || return 1
+
+ # exclude C++
+ [ "${1#*++}" = "${1}" ] || return 1
V=0
J=0
@@ -662,16 +742,20 @@ trylib() {
if testsym "${1}" "lua_getfenv"; then
V=501
elif testsym "${1}" "lua_yieldk"; then
- V=502
+ if testsym "${1}" "lua_getctx"; then
+ V=502
+ else
+ V=503
+ fi
else
- return 0
+ return 1
fi
- [ "$V" -gt 0 -a "$V" -ge "${LIBLUA_VER:-0}" ] || return 0
+ [ "$V" -gt 0 -a "$V" -ge "${LIBLUA_VER:-0}" ] || return 1
- [ "$V" -gt "${LIBLUA_VER:-0}" -o "${#D}" -lt "${#LIBLUA_DIR}" -o \( "${JIT_REQ}" = "yes" -a "${LIBJIT_VER:-0}" -lt "${JIT_MAX}" \) ] || return 0
+ [ "$V" -gt "${LIBLUA_VER:-0}" -o "${#D}" -lt "${#LIBLUA_DIR}" -o \( "${JIT_REQ}" = "yes" -a "${LIBJIT_VER:-0}" -lt "${JIT_MAX}" \) ] || return 1
- [ "$V" -ge "${API_MIN}" -a "$V" -le "${API_MAX}" ] || return 0
+ [ "$V" -ge "${API_MIN}" -a "$V" -le "${API_MAX}" ] || return 1
if [ -n "${JIT_REQ}" ]; then
@@ -681,12 +765,12 @@ trylib() {
fi
if [ "${JIT_REQ}" = "skip" ]; then
- [ "${J}" -eq 0 ] || return 0
+ [ "${J}" -eq 0 ] || return 1
elif [ "${JIT_REQ}" = "yes" ]; then
- [ "$J" -ge "${LIBJIT_VER:-0}" ] || return 0
- [ "$J" -gt "${LIBJIT_VER:-0}" -o "${#D}" -lt "${#LIBJIT_DIR}" ] || return 0
- [ "$J" -ge ${JIT_MIN} ] || return 0
- [ "$J" -le "${JIT_MAX}" ] || return 0
+ [ "$J" -ge "${LIBJIT_VER:-0}" ] || return 1
+ [ "$J" -gt "${LIBJIT_VER:-0}" -o "${#D}" -lt "${#LIBJIT_DIR}" ] || return 1
+ [ "$J" -ge ${JIT_MIN} ] || return 1
+ [ "$J" -le "${JIT_MAX}" ] || return 1
LIBJIT_VER="$J"
LIBJIT_DIR="$D"
@@ -745,15 +829,17 @@ findlib() {
#printf -- "I=$I K=$K $findlib_L/lib$findlib_l*.*\n"
- for findlib_R in no ${RECURSE}; do
- for findlib_lib in $(findpath "lib${findlib_l}*.*" ${findlib_R} "${findlib_L}"); do
- trylib "${findlib_lib}"
- done
+ glob "${findlib_L}/lib${findlib_l}*.*" 0 trylib || :
- if foundlib; then
- return 0
- fi
- done
+ if foundlib; then
+ return 0;
+ fi
+
+ glob "${findlib_L}/lib${findlib_l}*.*" ${MAXDEPTH} trylib || :
+
+ if foundlib; then
+ return 0;
+ fi
K=$(($K + 1))
done
@@ -768,48 +854,73 @@ findlib() {
unset IFS
for findlib_D; do
- for findlib_R in no ${RECURSE}; do
- for findlib_lib in $(findpath "liblua*.*" ${findlib_R} "${findlib_D}"); do
- trylib "${findlib_lib}"
- done
+ glob "${findlib_D}/liblua*.*" "${MAXDEPTH}" trylib || :
+
+ if foundlib; then
+ return 0
+ fi
+ done
+
+ # if we can find the lua interpreter, use it as a reference for
+ # library locations.
+ if findlua; then
+ findlib_D="${LUA_PATH%/*}"
+ findlib_D="${findlib_D%/*}/lib"
+
+ if [ -d "${findlib_D}" ]; then
+ glob "${findlib_D}/liblua*.*" "${MAXDEPTH}" trylib || :
if foundlib; then
return 0
fi
- done
- done
+ fi
+ fi
}
-findpath() {
- NAME="$1"
- WHERE="$3"
+# check setuid and setgid mode
+safeperm() {
+ [ -f "$1" -a ! -u "$1" -a ! -g "$1" ]
+}
- PRUNE=
- if [ "${2}" = "no" ]; then
- PRUNE="-name . -o -type d -prune -o"
- fi
+tryluac() {
+ tryluac_F="${1}"
- [ ${#WHERE} -gt 0 ] || return 0
+ [ -x "${tryluac_F}" ] && safeperm "${tryluac_F}" || return 0
- IFS=:
- set -- ${WHERE}
- unset IFS
+ tryluac_V="$("${tryluac_F}" -v </dev/null 2>&1 | head -n1 | sed -ne 's/^Lua \([0123456789][0123456789]*\.[0123456789][0123456789]*\).*/\1/p')"
+ : ${tryluac_V:=0}
+ tryluac_V="$((${tryluac_V%%.*} * 100 + ${tryluac_V##*.} % 100))"
- if [ $# -gt 0 ]; then
- for findpath_D; do
- find "${findpath_D}/." ${MAXDEPTH} ${XDEV} ${PRUNE} -name "${NAME}" -print 2>>/dev/null | sed -e 's/\/\.//'
- done
- fi
-}
+ [ "${tryluac_V}" -gt 0 -a "${tryluac_V}" -ge "${LUAC_VER:-0}" ] || return 0
+ [ "${tryluac_V}" -gt "${LUAC_VER:-0}" -o "${#tryluac_F}" -lt "${#LUAC_PATH}" ] || return 0
-# check setuid and setgid mode
-safeperm() {
- [ -f "$1" -a ! -u "$1" -a ! -g "$1" ]
+ [ "${tryluac_V}" -ge "${API_MIN}" -a "${tryluac_V}" -le "${API_MAX}" ] || return 0
+
+ printf "return true" 2>>/dev/null | ${tryluac_F} -p - </dev/null >>/dev/null 2>&1 || return 0
+
+ LUAC_PATH="${tryluac_F}"
+ LUAC_VER="${tryluac_V}"
}
+#
+# foundluac
+#
+# true if found the best (maximum) possible version, false otherwise
+#
+foundluac() {
+ if [ "${LUAC_VER:-0}" -lt "${API_MAX}" ]; then
+ return 1
+ fi
+
+ if [ "${SHORTEST}" = "yes" ]; then
+ return 1
+ fi
+
+ return 0
+}
findluac() {
if [ $# -eq 0 ]; then
@@ -818,36 +929,33 @@ findluac() {
unset IFS
fi
- while [ $# -gt 0 ]; do
- for F in $(findpath "${1}" no "${PATH}"; findpath "${1}" "${RECURSE}" "${BINDIRS}"); do
- [ -x "$F" ] && safeperm "$F" || continue
-
- V="$("$F" -v </dev/null 2>&1 | head -n1 | sed -ne 's/^Lua \([0123456789][0123456789]*\.[0123456789][0123456789]*\).*/\1/p')"
- : ${V:=0}
- V="$((${V%%.*} * 100 + ${V##*.} % 100))"
-
- [ "${V}" -gt 0 -a "${V}" -ge "${LUAC_VER:-0}" ] || continue
+ for findluac_G; do
+ IFS=:
+ for findluac_D in ${PATH}; do
+ unset IFS
- [ "${V}" -gt "${LUAC_VER:-0}" -o "${#F}" -lt "${#LUAC_PATH}" ] || continue
+ glob "${findluac_D}/${findluac_G}" 0 tryluac || :
- [ "${V}" -ge "${API_MIN}" -a "${V}" -le "${API_MAX}" ] || continue
+ if foundluac; then
+ return 0
+ fi
+ done
- printf "return true" 2>>/dev/null | ${F} -p - </dev/null >>/dev/null 2>&1 || continue
+ IFS=:
+ for findluac_D in ${BINDIRS}; do
+ unset IFS
- LUAC_PATH="$F"
- LUAC_VER="$V"
+ glob "${findluac_D}/${findluac_G}" "${MAXDEPTH}" tryluac || :
- [ "${SHORTEST}" = "yes" -o "${LUAC_VER}" -lt "${API_MAX}" ] || break 2
+ if foundluac; then
+ return 0
+ fi
done
- shift
+ unset IFS
done
- if [ -n "${LUAC_PATH}" -a -n "${LUAC_VER}" ]; then
- return 0
- else
- return 1
- fi
+ [ "${LUAC_VER:-0}" -gt 0 ] && [ "${#LUAC_PATH}" -gt 0 ]
}
@@ -871,7 +979,7 @@ isinteger() {
checkints() {
while [ $# -gt 0 ]; do
if ! isinteger "${1}"; then
- printf -- "${0##*/}: ${1}: not a number\n" >&2
+ warn "%s: not a number" "${1}"
return 1
fi
@@ -946,6 +1054,54 @@ mmp2num() {
}
+trylua() {
+ trylua_F="${1}"
+ [ -x "${trylua_F}" ] && safeperm "${trylua_F}" || return 0
+
+ trylua_V="$("${trylua_F}" -e 'print(string.match(_VERSION, [[[%d.]+]]))' </dev/null 2>>/dev/null | head -n1 | sed -ne 's/^\([0123456789][0123456789]*\.[0123456789][0123456789]*\).*/\1/p')"
+ : ${trylua_V:=0}
+ trylua_V="$((${trylua_V%%.*} * 100 + ${trylua_V##*.} % 100))"
+
+ [ "${trylua_V}" -gt 0 -a "${trylua_V}" -ge "${LUA_VER:-0}" ] || return 0
+
+ [ "${trylua_V}" -gt "${LUA_VER:-0}" -o "${#trylua_F}" -lt "${#LUA_PATH}" ] || return 0
+
+ [ "${trylua_V}" -ge "${API_MIN}" -a "${trylua_V}" -le "${API_MAX}" ] || return 0
+
+ if [ -n "${JIT_REQ}" ]; then
+ J="$("${trylua_F}" -v </dev/null 2>&1 | head -n1 | sed -ne 's/^LuaJIT \([0123456789][0123456789]*\.[0123456789][0123456789]*\.[0123456789][0123456789]*\).*/\1/p')"
+ J="$(jit2num ${J:-0})"
+
+ if [ "${JIT_REQ}" = "skip" ]; then
+ [ "${J}" -eq 0 ] || return 0
+ elif [ "${JIT_REQ}" = "yes" ]; then
+ [ "${J}" -gt 0 ] || return 0
+ [ "${J}" -ge "${JIT_MIN}" ] || return 0
+ [ "${J}" -le "${JIT_MAX}" ] || return 0
+ fi
+ fi
+
+ LUA_PATH="${trylua_F}"
+ LUA_VER="${trylua_V}"
+}
+
+#
+# foundlua
+#
+# true if found the best (maximum) possible version, false otherwise
+#
+foundlua() {
+ if [ "${LUA_VER:-0}" -lt "${API_MAX}" ]; then
+ return 1
+ fi
+
+ if [ "${SHORTEST}" = "yes" ]; then
+ return 1
+ fi
+
+ return 0
+}
+
findlua() {
if [ $# -eq 0 ]; then
IFS=:
@@ -953,52 +1109,38 @@ findlua() {
unset IFS
fi
- while [ $# -gt 0 ]; do
- for F in $(findpath "${1}" no "${PATH}"; findpath "${1}" "${RECURSE}" "${BINDIRS}"); do
- [ -x "$F" ] && safeperm "$F" || continue
-
- V="$("$F" -e 'print(string.match(_VERSION, [[[%d.]+]]))' </dev/null 2>>/dev/null | head -n1 | sed -ne 's/^\([0123456789][0123456789]*\.[0123456789][0123456789]*\).*/\1/p')"
- : ${V:=0}
- V="$((${V%%.*} * 100 + ${V##*.} % 100))"
+ for findlua_G; do
+ IFS=:
+ for findlua_D in ${PATH}; do
+ unset IFS
- [ "${V}" -gt 0 -a "${V}" -ge "${LUA_VER:-0}" ] || continue
+ glob "${findlua_D}/${findlua_G}" 0 trylua || :
- [ "${V}" -gt "${LUA_VER:-0}" -o "${#F}" -lt "${#LUA_PATH}" ] || continue
+ if foundlua; then
+ return 0
+ fi
+ done
- [ "${V}" -ge "${API_MIN}" -a "${V}" -le "${API_MAX}" ] || continue
+ IFS=:
+ for findlua_D in ${BINDIRS}; do
+ unset IFS
- if [ -n "${JIT_REQ}" ]; then
- J="$("$F" -v </dev/null 2>&1 | head -n1 | sed -ne 's/^LuaJIT \([0123456789][0123456789]*\.[0123456789][0123456789]*\.[0123456789][0123456789]*\).*/\1/p')"
- J="$(jit2num ${J:-0})"
+ glob "${findlua_D}/${findlua_G}" "${MAXDEPTH}" trylua || :
- if [ "${JIT_REQ}" = "skip" ]; then
- [ "${J}" -eq 0 ] || continue
- elif [ "${JIT_REQ}" = "yes" ]; then
- [ "${J}" -gt 0 ] || continue
- [ "${J}" -ge "${JIT_MIN}" ] || continue
- [ "${J}" -le "${JIT_MAX}" ] || continue
- fi
+ if foundlua; then
+ return 0
fi
-
- LUA_PATH="$F"
- LUA_VER="$V"
-
- [ "${SHORTEST}" = "yes" -o "${LUA_VER}" -lt "${API_MAX}" ] || break 2
done
- shift
+ unset IFS
done
- if [ -n "${LUA_PATH}" -a -n "${LUA_VER}" ]; then
- return 0
- else
- return 1
- fi
+ [ "${LUA_VER:-0}" -gt 0 ] && [ "${#LUA_PATH}" -gt 0 ]
}
ccname() {
- "${CC}" -E - <<-EOF | awk '/sunpro/||/clang/||/gcc/||/other/{ print $1; exit; }'
+ runcc -E - <<-EOF | awk '/sunpro/||/clang/||/gcc/||/other/{ print $1; exit; }'
#if defined __SUNPRO_C
sunpro
#elif defined __clang__
@@ -1026,8 +1168,7 @@ usage() {
-e GLOB glob pattern for finding utilities (lua, luac, etc)
-k query pkg-config if available
-r recursively search directories
- -m MAXDEPTH limit recursion to MAXDEPTH (only for GNU and BSD find)
- -x do not cross device mounts when recursing
+ -m MAXDEPTH limit recursion to MAXDEPTH
-s find shortest pathname, otherwise print first best match
-v VERSION require specific Lua version or range
(e.g. "5.1" or "5.1-5.2")
@@ -1038,8 +1179,10 @@ usage() {
-h print this usage message
cppflags print derived additional CPPFLAGS necessary
+ version print derived Lua API version from cppflags discovery
ldflags print derived additional LDFLAGS necessary (TODO)
- version print derived Lua API version
+ libs print derived additional LIBS necessary (TODO)
+ libversion print derived Lua API version from ldflags/libs discovery
luac print path to luac utility ($(printf "${GLOB_LUA}" | tr ':' ' '))
lua print path to lua interpreter ($(printf "${GLOB_LUAC}" | tr ':' ' '))
package.path print preferred module install path
@@ -1114,20 +1257,21 @@ while getopts I:L:P:d:De:krm:xsv:j:JVh OPT; do
RECURSE=yes
;;
m)
- if [ -n "${OPTARG##[0123456789]}" ]; then
- printf -- "${0##*/}: ${OPTARG}: invalid maxdepth\n" >&2
- exit 1
- fi
-
- if find "${TMPDIR:-/tmp}" -maxdepth ${OPTARG} -prune >>/dev/null 2>&1; then
- MAXDEPTH="-maxdepth ${OPTARG}"
- else
- printf -- "${0##*/}: $(command -v find): -maxdepth unsupported\n" >&2
+ if [ "${#OPTARG}" -eq 0 -o -n "${OPTARG##[0123456789]}" ]; then
+ panic "%s: invalid maxdepth" "${OPTARG}"
fi
+ MAXDEPTH="${OPTARG}"
;;
x)
- XDEV="-xdev"
+ #
+ # NOTE: This option was
+ #
+ # -x do not cross device mounts when recursing
+ #
+ # but is currently unsupported as our built-in glob function
+ # does not implement this functionality. Previously this
+ # option caused -xdev to be added to invocations of find(1).
;;
s)
SHORTEST=yes
@@ -1140,8 +1284,7 @@ while getopts I:L:P:d:De:krm:xsv:j:JVh OPT; do
API_MAX="$(lua2num ${MAX:-99} 99)"
if [ "${API_MIN}" -gt "${API_MAX}" ]; then
- printf -- "${0##*/}: ${OPTARG}: invalid version range\n" >&2
- exit 1
+ panic "%s: invalid version range" "${OPTARG}"
fi
;;
@@ -1153,8 +1296,7 @@ while getopts I:L:P:d:De:krm:xsv:j:JVh OPT; do
JIT_MAX="$(jit2num ${MAX:-99} 99 99)"
if [ "${JIT_MIN}" -gt "${JIT_MAX}" ]; then
- printf -- "${0##*/}: ${OPTARG}: invalid version range\n" >&2
- exit 1
+ panic "%s: invalid version range" "${OPTARG}"
fi
JIT_REQ=yes
@@ -1180,10 +1322,16 @@ done
shift $(($OPTIND - 1))
-for U in "${CC:-cc}" find grep od rm rmdir sed xargs; do
- if ! command -v "${U}" >>/dev/null 2>&1; then
- printf -- "${0##*/}: ${U}: command not found\n" >&2
- fi
+[ "${RECURSE}" = "yes" ] || MAXDEPTH=0
+
+
+for U in "${CC}" grep od rm rmdir sed xargs; do
+ ! command -v "${U}" >>/dev/null 2>&1 || continue
+
+ # ${CC} might have trailing flags or invoke the compiler through env
+ ! command -v "${U%% *}" >>/dev/null 2>&1 || continue
+
+ warn "%s: command not found" "${U}"
done
@@ -1191,15 +1339,13 @@ if [ -n "${SANDBOX}" ]; then
if [ "${SANDBOX}" = "${SANDBOX%/}" ]; then
if [ ! -c "${DEVRANDOM}" ]; then
# TODO: expand DEVRANDOM into set of different possibilities to check
- printf -- "${0##*/}: ${DEVRANDDOM}: no character random device available\n" >&2
- exit 1
+ panic "%s: no character random device available" "${DEVRANDOM}"
fi
TMP="${SANDBOX}$(od -An -N8 -tx1 < ${DEVRANDOM} 2>>/dev/null | tr -d ' ')"
if [ ${#TMP} -ne $((${#SANDBOX} + 16)) ]; then
- printf -- "${0##*/}: ${SANDBOX}: unable to generate random suffix\n" >&2
- exit 1
+ panic "%s: unable to generate random suffix" "${SANDBOX}"
fi
SANDBOX="${TMP}"
@@ -1241,18 +1387,28 @@ cppflags)
[ -z "${API_DIR:-}" ] || printf -- "-I${API_DIR}\n"
;;
+version)
+ findversion || exit 1
+
+ printf "$(((${API_VER} / 100) % 100)).$((($API_VER) % 100))\n"
+
+ ;;
ldflags)
findlib
[ "${LIBLUA_VER:-0}" -gt 0 ] || exit 1
- printf -- "-L${LIBLUA_DIR} -l${LIBLUA_LIB}\n"
+ if [ "${#LIBLUA_DIR}" -gt 0 ]; then
+ printf -- "-L%s\n" "${LIBLUA_DIR}"
+ fi
;;
-version)
- findversion || exit 1
+libs)
+ findlib
- printf "$(((${API_VER} / 100) % 100)).$((($API_VER) % 100))\n"
+ [ "${LIBLUA_VER:-0}" -gt 0 ] || exit 1
+
+ printf -- "-l%s\n" "${LIBLUA_LIB}"
;;
libv*)
@@ -1288,21 +1444,38 @@ lua)
;;
ldir|cdir)
- printf -- "${0##*/}: ${1}: deprecated command\n" >&2
- MODE="${1}"
- shift
+ #
+ # ldir and cdir were deprecated on 2014-12-18. On 2016-03-25 they
+ # were revived because their names are more intuitive than
+ # package.path and package.cpath. For now try to support the
+ # semantics of both by assuming interpreter glob patterns only match
+ # file names, while preferred install directory string.match
+ # expressions have directory components.
+ #
+ if true; then
+ MODE="${1}"
+
+ # move command to end; rotates to ${1} after loop
+ set -- "$@" "${1}"
+ shift
- if [ $# -gt 0 ]; then
- append GLOB $*
+ cdir_I=0
+ cdir_N="$(($# - 1))"
+ while [ "${cdir_I}" -lt "${cdir_N}" ]; do
+ if [ "${1#*/}" = "${1}" ]; then
+ append GLOB "${1}"
+ warn "%s: passing glob patterns to %s is deprecated" "${1}" "${MODE}"
+ else
+ set -- "$@" "${1}"
+ fi
+ shift
+ cdir_I=$((${cdir_I} + 1))
+ done
fi
findlua || exit 1
- if [ "${MODE}" = "cdir" ]; then
- findinstalldir package.cpath
- else
- findinstalldir package.path
- fi
+ findinstalldir "$@" || exit 1
;;
package.path|package.cpath)
@@ -1333,9 +1506,9 @@ testsym)
;;
*)
if [ -n "${1:-}" ]; then
- printf -- "${0##*/}: ${1}: unknown command\n" >&2
+ warn "%s: unknown command" "${1}"
else
- printf -- "${0##*/}: no command specified\n" >&2
+ warn "no command specified"
fi
exit 1