diff options
author | william <william@25tandclement.com> | 2013-12-09 21:05:17 -0800 |
---|---|---|
committer | william <william@25tandclement.com> | 2013-12-09 21:05:17 -0800 |
commit | fbd452885694da66156e95f671ab364cfe157bef (patch) | |
tree | 0c9f0752ef7ff5693447ccfd64c1e4800a961fc7 /mk | |
parent | d4aa420319bff15a6f84f679c6374dda7cf1b0f2 (diff) | |
download | luaossl-fbd452885694da66156e95f671ab364cfe157bef.tar.gz luaossl-fbd452885694da66156e95f671ab364cfe157bef.tar.bz2 luaossl-fbd452885694da66156e95f671ab364cfe157bef.zip |
copy over build files from cqueues
Diffstat (limited to 'mk')
-rwxr-xr-x | mk/lua.path | 1000 | ||||
-rwxr-xr-x | mk/vendor.cc | 17 | ||||
-rwxr-xr-x | mk/vendor.os | 3 |
3 files changed, 1020 insertions, 0 deletions
diff --git a/mk/lua.path b/mk/lua.path new file mode 100755 index 0000000..eb10d39 --- /dev/null +++ b/mk/lua.path | |||
@@ -0,0 +1,1000 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # This script is used to derive compiler flags and filesystem paths | ||
4 | # necessary to utilize Lua, LuaJIT, and particular versions thereof in both | ||
5 | # simple and mixed installation environments. | ||
6 | # | ||
7 | # For usage help information use the -h switch. | ||
8 | # | ||
9 | # This script attempts to adhere strictly to POSIX shell specifications. The | ||
10 | # known non-POSIX features used are the path of the shell at the very first | ||
11 | # line of this script, the default compiler command name of `cc' instead of | ||
12 | # `c99', and the use of /dev/urandom for generating a random sandbox | ||
13 | # directory suffix. All of these can be override. For any other issues | ||
14 | # please contact the author. | ||
15 | # | ||
16 | # WARNING: When searching for a Lua interpreter this script may execute | ||
17 | # various utilities in an attempt to deduce their fitness and release | ||
18 | # version. By default this script will search for and execute utilities | ||
19 | # using the glob patterns luac* and lua*. But this script CANNOT GUARANTEE | ||
20 | # that executing such utilities, or any other utilities, either wittingly or | ||
21 | # unwittingly, will not result in your COMPUTER EXPLODING. You have been | ||
22 | # warned. | ||
23 | # | ||
24 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
25 | # | ||
26 | # Changelog: | ||
27 | # | ||
28 | # * 2013-08-02 - Published. Derived from an earlier script, lua.path, | ||
29 | # written for the cqueues project. | ||
30 | # | ||
31 | # * 2013-08-05 - Redirect stdin from /dev/null when probing so we don't | ||
32 | # freeze if a utility tries to read from stdin. | ||
33 | # | ||
34 | # chdir to a read-only directory by default to try to prevent creation | ||
35 | # of temporary files. These features address the issues of LuaTeX | ||
36 | # reading from stdin and creating a luatex.out file in the current | ||
37 | # working directory. By default a directory with a random suffix | ||
38 | # generated from /dev/urandom is placed in TMPDIR and removed on exit. | ||
39 | # | ||
40 | # If CPPFLAGS is empty and no -I options directly specified then set | ||
41 | # INCDIRS to "/usr/include:/usr/local/include". | ||
42 | # | ||
43 | # * 2013-08-07 - Add pkg-config support and refactor header probing to delay | ||
44 | # recursive searching. | ||
45 | # | ||
46 | # * 2013-09-09 - NetBSD's sh gets upset over the noclobber option and | ||
47 | # redirection to /dev/null, so use append operator. And check $# | ||
48 | # before iterating over a null parameter set with `do X; ... done` | ||
49 | # when `set -u` is enabled--it complains about $@ being unset. | ||
50 | # | ||
51 | # * 2013-10-22 - Initial ldflags detection. | ||
52 | # | ||
53 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
54 | # | ||
55 | # Copyright (C) 2012-2013 William Ahern | ||
56 | # | ||
57 | # Permission is hereby granted, free of charge, to any person obtaining a | ||
58 | # copy of this software and associated documentation files (the "Software"), | ||
59 | # to deal in the Software without restriction, including without limitation | ||
60 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
61 | # and/or sell copies of the Software, and to permit persons to whom the | ||
62 | # Software is furnished to do so, subject to the following conditions: | ||
63 | # | ||
64 | # The above copyright notice and this permission notice shall be included in | ||
65 | # all copies or substantial portions of the Software. | ||
66 | # | ||
67 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
68 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
69 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
70 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
71 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
72 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
73 | # DEALINGS IN THE SOFTWARE. | ||
74 | # | ||
75 | set -e # strict errors | ||
76 | set -u # don't expand unbound variables | ||
77 | set -f # disable pathname expansion | ||
78 | set -C # noclobber | ||
79 | \unalias -a # no command surprises | ||
80 | export LC_ALL=C # no locale headaches | ||
81 | unset IFS # no field splitting surprises | ||
82 | : ${TMPDIR:=/tmp} # sane TMPDIR | ||
83 | : ${CC:=cc} | ||
84 | |||
85 | MYVERSION=20131025 | ||
86 | MYVENDOR="william@25thandClement.com" | ||
87 | |||
88 | |||
89 | DEVRANDOM=/dev/urandom | ||
90 | SANDBOX="${TMPDIR}/${0##*/}-" | ||
91 | |||
92 | CPPDIRS= # -I directories from CPPFLAGS | ||
93 | INCDIRS= | ||
94 | LDDIRS= # -L directories from LDFLAGS | ||
95 | LIBDIRS= | ||
96 | BINDIRS= | ||
97 | RECURSE=no | ||
98 | MAXDEPTH= # full command switch, like "-maxdepth 3", if supported | ||
99 | XDEV= # do not cross device boundaries; i.e. "-xdev" | ||
100 | SHORTEST= # continue searching until shortest pathname found | ||
101 | PKGCONFIG= # path to pkg-config, found by `command -v` when -k option invoked | ||
102 | |||
103 | API_MIN=500 | ||
104 | API_MAX=999 | ||
105 | API_VER= | ||
106 | API_DIR= | ||
107 | |||
108 | JIT_REQ= | ||
109 | JIT_MIN=20000 | ||
110 | JIT_MAX=99999 | ||
111 | JIT_VER= | ||
112 | JIT_DIR= | ||
113 | |||
114 | LIBLUA_VER= | ||
115 | LIBLUA_DIR= | ||
116 | LIBLUA_LIB= | ||
117 | |||
118 | LIBJIT_VER= | ||
119 | LIBJIT_DIR= | ||
120 | LIBJIT_LIB= | ||
121 | |||
122 | LUAC_PATH= | ||
123 | LUAC_VER= | ||
124 | |||
125 | LUA_PATH= | ||
126 | LUA_VER= | ||
127 | |||
128 | |||
129 | # | ||
130 | # parse CPPFLAGS -I or LDFLAGS -L directories | ||
131 | # | ||
132 | xdirs() { | ||
133 | OPTC="${1:-I}" | ||
134 | DIRS= | ||
135 | |||
136 | set -- ${2:-} | ||
137 | |||
138 | while [ $# -gt 0 ]; do | ||
139 | case "${1}" in | ||
140 | -${OPTC}) | ||
141 | shift | ||
142 | |||
143 | if [ -n "${1:-}" ]; then | ||
144 | DIRS="${DIRS}${DIRS:+:}${1}" | ||
145 | fi | ||
146 | |||
147 | ;; | ||
148 | -${OPTC}*) | ||
149 | if [ "${1}" != "-${OPTC}" ]; then | ||
150 | DIRS="${DIRS}${DIRS:+:}${1#-${OPTC}}" | ||
151 | fi | ||
152 | |||
153 | ;; | ||
154 | esac | ||
155 | |||
156 | shift | ||
157 | done | ||
158 | |||
159 | printf -- "${DIRS}" | ||
160 | } | ||
161 | |||
162 | idirs() { | ||
163 | xdirs "I" "${1:-}" | ||
164 | } | ||
165 | |||
166 | ldirs() { | ||
167 | xdirs "L" "${1:-}" | ||
168 | } | ||
169 | |||
170 | # count ":" delimited directories generated by xdirs | ||
171 | ndirs() { | ||
172 | IFS=: | ||
173 | set -- ${1:-} | ||
174 | unset IFS | ||
175 | |||
176 | printf "$#\n" | ||
177 | } | ||
178 | |||
179 | |||
180 | # | ||
181 | # evalmacro PATH MACRO [REGEX] [SUBST] | ||
182 | # | ||
183 | # PATH Header identifier--#include <PATH> | ||
184 | # MACRO Macro identifier | ||
185 | # REGEX Optional regex pattern to match macro evalutation result | ||
186 | # SUBST Optional replacement expression | ||
187 | # | ||
188 | evalmacro() { | ||
189 | printf "#include <$1>\n[===[$2]===]\n" \ | ||
190 | | ${CC:-cc} ${CPPFLAGS:-} -E - 2>>/dev/null \ | ||
191 | | sed -ne " | ||
192 | s/^.*\\[===\\[ *\\(${3:-.*}\\) *\\]===\\].*$/${4:-\\1}/ | ||
193 | t Found | ||
194 | d | ||
195 | :Found | ||
196 | p | ||
197 | q | ||
198 | " | ||
199 | } | ||
200 | |||
201 | |||
202 | # | ||
203 | # testsym PATH NAME | ||
204 | # | ||
205 | # Test whether global symbol NAME exists in object file at PATH. Exits with | ||
206 | # 0 (true) when found, non-0 (false) otherwise. | ||
207 | # | ||
208 | testsym() { | ||
209 | # NOTE: No -P for OpenBSD nm(1), but the default output format is | ||
210 | # close enough. Section types always have a leading and trailing | ||
211 | # space. U section type means undefined. On AIX [VWZ] are weak | ||
212 | # global symbols. Solaris and OS X have additional symbol types | ||
213 | # beyond the canonical POSIX/BSD types, all of which are uppercase | ||
214 | # and within [A-T]. | ||
215 | (nm -Pg ${1} 2>>/dev/null || nm -g 2>>/dev/null) \ | ||
216 | | sed -ne '/ [A-T] /p' \ | ||
217 | | grep -qE "${2}" | ||
218 | } | ||
219 | |||
220 | |||
221 | tryluainclude() { | ||
222 | V="$(evalmacro ${1} LUA_VERSION_NUM '[0123456789][0123456789]*')" | ||
223 | : ${V:=0} | ||
224 | |||
225 | if [ "${1%/*}" != "${1}" ]; then | ||
226 | D="${1%/*}" | ||
227 | |||
228 | # cleanup after Solaris directory prune trick | ||
229 | if [ "${D##*/./}" != "${D}" ]; then | ||
230 | D="${D%%/./*}/${D##*/./}" | ||
231 | else | ||
232 | D="${D%/.}" | ||
233 | fi | ||
234 | else | ||
235 | D= | ||
236 | fi | ||
237 | |||
238 | [ "$V" -gt 0 -a "$V" -ge "${API_VER:-0}" ] || return 0 | ||
239 | |||
240 | [ "$V" -gt "${API_VER:-0}" -o "${#D}" -lt "${#API_DIR}" -o \( "${JIT_REQ}" = "yes" -a "${JIT_VER:-0}" -lt "${JIT_MAX}" \) ] || return 0 | ||
241 | |||
242 | [ "$V" -ge "${API_MIN}" -a "$V" -le "${API_MAX}" ] || return 0 | ||
243 | |||
244 | if [ -n "${JIT_REQ}" ]; then | ||
245 | J="$(evalmacro ${1%%lua.h}luajit.h LUAJIT_VERSION_NUM '[0123456789][0123456789]*')" | ||
246 | : ${J:=0} | ||
247 | |||
248 | if [ "${JIT_REQ}" = "skip" ]; then | ||
249 | [ "${J}" -eq 0 ] || return 0 | ||
250 | elif [ "${JIT_REQ}" = "yes" ]; then | ||
251 | [ "$J" -ge "${JIT_VER:-0}" ] || return 0 | ||
252 | [ "$J" -gt "${JIT_VER:-0}" -o "${#D}" -lt "${#JIT_DIR}" ] || return 0 | ||
253 | [ "$J" -ge ${JIT_MIN} ] || return 0 | ||
254 | [ "$J" -le "${JIT_MAX}" ] || return 0 | ||
255 | |||
256 | JIT_VER="$J" | ||
257 | JIT_DIR="$D" | ||
258 | fi | ||
259 | fi | ||
260 | |||
261 | API_VER="$V" | ||
262 | API_DIR="$D" | ||
263 | } | ||
264 | |||
265 | |||
266 | # | ||
267 | # foundversion | ||
268 | # | ||
269 | # true if found the best (maximum) possible version, false otherwise | ||
270 | # | ||
271 | foundversion() { | ||
272 | if [ "${API_VER:-0}" -lt "${API_MAX}" ]; then | ||
273 | return 1 | ||
274 | fi | ||
275 | |||
276 | if [ "${JIT_REQ}" = "yes" -a "${JIT_VER:-0}" -lt "${JIT_MAX}" ]; then | ||
277 | return 1 | ||
278 | fi | ||
279 | |||
280 | if [ "${SHORTEST}" = "yes" ]; then | ||
281 | return 1 | ||
282 | fi | ||
283 | |||
284 | return 0 | ||
285 | } | ||
286 | |||
287 | |||
288 | # | ||
289 | # findversion | ||
290 | # | ||
291 | findversion() { | ||
292 | tryluainclude "lua.h" | ||
293 | |||
294 | if foundversion; then | ||
295 | return 0 | ||
296 | fi | ||
297 | |||
298 | |||
299 | # iterate through CPPFLAGS to probe different precedence | ||
300 | if [ "${API_VER:-0}" -lt "${API_MAX}" ]; then | ||
301 | IFS=: | ||
302 | set -- ${CPPDIRS} | ||
303 | unset IFS | ||
304 | |||
305 | if [ $# -gt 0 ]; then | ||
306 | for D; do | ||
307 | tryluainclude "${D}/lua.h" | ||
308 | |||
309 | if foundversion; then | ||
310 | return 0 | ||
311 | fi | ||
312 | done | ||
313 | fi | ||
314 | fi | ||
315 | |||
316 | |||
317 | 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)" | ||
319 | PKGDIRS="$(idirs "${PKGFLAGS}")" | ||
320 | |||
321 | IFS=: | ||
322 | set -- ${PKGDIRS} | ||
323 | unset IFS | ||
324 | |||
325 | if [ $# -gt 0 ]; then | ||
326 | for D; do | ||
327 | tryluainclude "${D}/lua.h" | ||
328 | |||
329 | if foundversion; then | ||
330 | return 0 | ||
331 | fi | ||
332 | done | ||
333 | fi | ||
334 | fi | ||
335 | |||
336 | |||
337 | IFS=: | ||
338 | set -- ${INCDIRS} | ||
339 | unset IFS | ||
340 | |||
341 | if [ $# -gt 0 ]; then | ||
342 | for D; do | ||
343 | tryluainclude "${D}/lua.h" | ||
344 | |||
345 | if foundversion; then | ||
346 | return 0 | ||
347 | fi | ||
348 | done | ||
349 | fi | ||
350 | |||
351 | |||
352 | [ "${RECURSE}" = "yes" ] || return 0 | ||
353 | |||
354 | |||
355 | # recurse into CPPDIRS | ||
356 | IFS=: | ||
357 | set -- ${CPPDIRS} | ||
358 | unset IFS | ||
359 | |||
360 | if [ $# -gt 0 ]; then | ||
361 | for D; do | ||
362 | for F in $(find ${D} ${MAXDEPTH} ${XDEV} -name lua.h -print 2>>/dev/null); do | ||
363 | tryluainclude "${F}" | ||
364 | |||
365 | if foundversion; then | ||
366 | return 0 | ||
367 | fi | ||
368 | done | ||
369 | done | ||
370 | fi | ||
371 | |||
372 | |||
373 | # recurse into INCDIRS | ||
374 | IFS=: | ||
375 | set -- ${INCDIRS} | ||
376 | unset IFS | ||
377 | |||
378 | if [ $# -gt 0 ]; then | ||
379 | for D; do | ||
380 | for F in $(find ${D}/. ${MAXDEPTH} ${XDEV} -name lua.h -print 2>>/dev/null); do | ||
381 | tryluainclude "${F}" | ||
382 | |||
383 | if foundversion; then | ||
384 | return 0 | ||
385 | fi | ||
386 | done | ||
387 | done | ||
388 | fi | ||
389 | } | ||
390 | |||
391 | |||
392 | # | ||
393 | # Unlike API version checking, this is less likely to be accurately forward | ||
394 | # compatible. | ||
395 | # | ||
396 | trylib() { | ||
397 | if ! testsym "${1}" "lua_newstate"; then | ||
398 | return 0 | ||
399 | fi | ||
400 | |||
401 | V=0 | ||
402 | J=0 | ||
403 | D= | ||
404 | F="${1##*/}" | ||
405 | L= | ||
406 | |||
407 | if [ "${1%/*}" != "${1}" ]; then | ||
408 | D="${1%/*}" | ||
409 | |||
410 | # cleanup after Solaris directory prune trick | ||
411 | if [ "${D##*/./}" != "${D}" ]; then | ||
412 | D="${D%%/./*}/${D##*/./}" | ||
413 | else | ||
414 | D="${D%/.}" | ||
415 | fi | ||
416 | fi | ||
417 | |||
418 | L="${F#lib}" | ||
419 | L="${L%.so}" | ||
420 | L="${L%.a}" | ||
421 | L="${L%.dylib}" | ||
422 | |||
423 | |||
424 | # FIXME: need more versioning tests | ||
425 | if testsym "${1}" "lua_getfenv"; then | ||
426 | V=501 | ||
427 | elif testsym "${1}" "lua_yieldk"; then | ||
428 | V=502 | ||
429 | else | ||
430 | return 0 | ||
431 | fi | ||
432 | |||
433 | [ "$V" -gt 0 -a "$V" -ge "${LIBLUA_VER:-0}" ] || return 0 | ||
434 | |||
435 | [ "$V" -gt "${LIBLUA_VER:-0}" -o "${#D}" -lt "${#LIBLUA_DIR}" -o \( "${JIT_REQ}" = "yes" -a "${LIBJIT_VER:-0}" -lt "${JIT_MAX}" \) ] || return 0 | ||
436 | |||
437 | [ "$V" -ge "${API_MIN}" -a "$V" -le "${API_MAX}" ] || return 0 | ||
438 | |||
439 | |||
440 | if [ -n "${JIT_REQ}" ]; then | ||
441 | # FIXME: need more versioning tests | ||
442 | if testsym "${1}" "luaopen_jit"; then | ||
443 | J=20000 | ||
444 | fi | ||
445 | |||
446 | if [ "${JIT_REQ}" = "skip" ]; then | ||
447 | [ "${J}" -eq 0 ] || return 0 | ||
448 | elif [ "${JIT_REQ}" = "yes" ]; then | ||
449 | [ "$J" -ge "${LIBJIT_VER:-0}" ] || return 0 | ||
450 | [ "$J" -gt "${LIBJIT_VER:-0}" -o "${#D}" -lt "${#LIBJIT_DIR}" ] || return 0 | ||
451 | [ "$J" -ge ${JIT_MIN} ] || return 0 | ||
452 | [ "$J" -le "${JIT_MAX}" ] || return 0 | ||
453 | |||
454 | LIBJIT_VER="$J" | ||
455 | LIBJIT_DIR="$D" | ||
456 | LIBJIT_LIB="$L" | ||
457 | fi | ||
458 | fi | ||
459 | |||
460 | LIBLUA_VER="$V" | ||
461 | LIBLUA_DIR="$D" | ||
462 | LIBLUA_LIB="$L" | ||
463 | } | ||
464 | |||
465 | |||
466 | # | ||
467 | # foundlib | ||
468 | # | ||
469 | # true if found the best (maximum) possible version, false otherwise | ||
470 | # | ||
471 | foundlib() { | ||
472 | if [ "${LIBLUA_VER:-0}" -lt "${API_MAX}" ]; then | ||
473 | return 1 | ||
474 | fi | ||
475 | |||
476 | if [ "${JIT_REQ}" = "yes" -a "${LIBJIT_VER:-0}" -lt "${JIT_MAX}" ]; then | ||
477 | return 1 | ||
478 | fi | ||
479 | |||
480 | if [ "${SHORTEST}" = "yes" ]; then | ||
481 | return 1 | ||
482 | fi | ||
483 | |||
484 | return 0 | ||
485 | } | ||
486 | |||
487 | |||
488 | findlib() { | ||
489 | 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)" | ||
491 | PKGDIRS="$(ldirs "${PKGFLAGS}")" | ||
492 | PKGDIRS="${PKGDIRS}${PKGDIRS:+:}/lib:/usr/lib:/usr/local/lib" | ||
493 | NUMDIRS="$(ndirs "${PKGDIRS}")" | ||
494 | PKGLIBS="$(xdirs "l" "${PKGFLAGS}")" | ||
495 | NUMLIBS="$(ndirs "${PKGLIBS}")" | ||
496 | ALLDIRS="${PKGDIRS}${PKGLIBS:+:}${PKGLIBS}" | ||
497 | |||
498 | IFS=: | ||
499 | set -- ${ALLDIRS} | ||
500 | unset IFS | ||
501 | |||
502 | I=1 | ||
503 | while [ $I -le ${NUMDIRS} ]; do | ||
504 | K=$((1 + ${NUMDIRS})) | ||
505 | while [ $K -le $# ]; do | ||
506 | findlib_L=$(eval "printf \${$I}") | ||
507 | findlib_l=$(eval "printf \${$K}") | ||
508 | |||
509 | #printf -- "I=$I K=$K $findlib_L/lib$findlib_l*.*\n" | ||
510 | |||
511 | for findlib_R in no ${RECURSE}; do | ||
512 | for findlib_lib in $(findpath "lib${findlib_l}*.*" ${findlib_R} "${findlib_L}"); do | ||
513 | trylib "${findlib_lib}" | ||
514 | done | ||
515 | |||
516 | if foundlib; then | ||
517 | return 0 | ||
518 | fi | ||
519 | done | ||
520 | |||
521 | K=$(($K + 1)) | ||
522 | done | ||
523 | I=$(($I + 1)) | ||
524 | done | ||
525 | fi | ||
526 | |||
527 | ALLDIRS="${LDDIRS}${LDDIRS:+:}${LIBDIRS}" | ||
528 | |||
529 | IFS=: | ||
530 | set -- ${ALLDIRS} | ||
531 | unset IFS | ||
532 | |||
533 | for findlib_D; do | ||
534 | for findlib_R in no ${RECURSE}; do | ||
535 | for findlib_lib in $(findpath "liblua*.*" ${findlib_R} "${findlib_D}"); do | ||
536 | trylib "${findlib_lib}" | ||
537 | done | ||
538 | |||
539 | if foundlib; then | ||
540 | return 0 | ||
541 | fi | ||
542 | done | ||
543 | done | ||
544 | } | ||
545 | |||
546 | |||
547 | findpath() { | ||
548 | NAME="$1" | ||
549 | WHERE="$3" | ||
550 | |||
551 | PRUNE= | ||
552 | |||
553 | if [ "${2}" = "no" ]; then | ||
554 | PRUNE="-name . -o -type d -prune -o" | ||
555 | fi | ||
556 | |||
557 | [ ${#WHERE} -gt 0 ] || return 0 | ||
558 | |||
559 | IFS=: | ||
560 | set -- ${WHERE} | ||
561 | unset IFS | ||
562 | |||
563 | if [ $# -gt 0 ]; then | ||
564 | for findpath_D; do | ||
565 | find "${findpath_D}/." ${MAXDEPTH} ${XDEV} ${PRUNE} -name "${NAME}" -print 2>>/dev/null | sed -e 's/\/\.//' | ||
566 | done | ||
567 | fi | ||
568 | } | ||
569 | |||
570 | |||
571 | # check setuid and setgid mode | ||
572 | safeperm() { | ||
573 | [ -f "$1" -a ! -u "$1" -a ! -g "$1" ] | ||
574 | } | ||
575 | |||
576 | |||
577 | findluac() { | ||
578 | while [ $# -gt 0 ]; do | ||
579 | for F in $(findpath "${1}" no "${PATH}"; findpath "${1}" "${RECURSE}" "${BINDIRS}"); do | ||
580 | [ -x "$F" ] && safeperm "$F" || continue | ||
581 | |||
582 | V="$($F -v </dev/null 2>&1 | head -n1 | sed -ne 's/^Lua \([0123456789][0123456789]*\.[0123456789][0123456789]*\).*/\1/p')" | ||
583 | : ${V:=0} | ||
584 | V="$((${V%%.*} * 100 + ${V##*.} % 100))" | ||
585 | |||
586 | [ "${V}" -gt 0 -a "${V}" -ge "${LUAC_VER:-0}" ] || continue | ||
587 | |||
588 | [ "${V}" -gt "${LUAC_VER:-0}" -o "${#F}" -lt "${#LUAC_PATH}" ] || continue | ||
589 | |||
590 | [ "${V}" -ge "${API_MIN}" -a "${V}" -le "${API_MAX}" ] || continue | ||
591 | |||
592 | printf "return true" 2>>/dev/null | ${F} -p - </dev/null >>/dev/null 2>&1 || continue | ||
593 | |||
594 | LUAC_PATH="$F" | ||
595 | LUAC_VER="$V" | ||
596 | |||
597 | [ "${SHORTEST}" = "yes" -o "${LUAC_VER}" -lt "${API_MAX}" ] || break 2 | ||
598 | done | ||
599 | |||
600 | shift | ||
601 | done | ||
602 | } | ||
603 | |||
604 | |||
605 | checkints() { | ||
606 | while [ $# -gt 0 ]; do | ||
607 | I="${1}" | ||
608 | while [ "${#I}" -gt 0 ]; do | ||
609 | if [ "${I##[0123456789]}" = "${I}" ]; then | ||
610 | printf -- "${0##*/}: ${1}: not a number\n" >&2 | ||
611 | exit 1 | ||
612 | fi | ||
613 | |||
614 | I=${I##[0123456789]} | ||
615 | done | ||
616 | |||
617 | shift | ||
618 | done | ||
619 | } | ||
620 | |||
621 | |||
622 | lua2num() { | ||
623 | M=0 | ||
624 | m="${2:-0}" | ||
625 | |||
626 | IFS=. | ||
627 | set -- ${1} | ||
628 | unset IFS | ||
629 | |||
630 | M=${1:-${M}} | ||
631 | m=${2:-${m}} | ||
632 | |||
633 | checkints $M $m | ||
634 | |||
635 | printf "$((${M} * 100 + ${m}))\n" | ||
636 | } | ||
637 | |||
638 | |||
639 | jit2num() { | ||
640 | M=0 | ||
641 | m="${2:-0}" | ||
642 | p="${3:-0}" | ||
643 | |||
644 | IFS=. | ||
645 | set -- ${1} | ||
646 | unset IFS | ||
647 | |||
648 | M=${1:-${M}} | ||
649 | m=${2:-${m}} | ||
650 | p=${3:-${p}} | ||
651 | |||
652 | checkints $M $m $p | ||
653 | |||
654 | printf "$((${M} * 10000 + ${m} * 100 + ${p}))\n" | ||
655 | } | ||
656 | |||
657 | |||
658 | findlua() { | ||
659 | while [ $# -gt 0 ]; do | ||
660 | for F in $(findpath "${1}" no "${PATH}"; findpath "${1}" "${RECURSE}" "${BINDIRS}"); do | ||
661 | [ -x "$F" ] && safeperm "$F" || continue | ||
662 | |||
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')" | ||
664 | : ${V:=0} | ||
665 | V="$((${V%%.*} * 100 + ${V##*.} % 100))" | ||
666 | |||
667 | [ "${V}" -gt 0 -a "${V}" -ge "${LUA_VER:-0}" ] || continue | ||
668 | |||
669 | [ "${V}" -gt "${LUA_VER:-0}" -o "${#F}" -lt "${#LUA_PATH}" ] || continue | ||
670 | |||
671 | [ "${V}" -ge "${API_MIN}" -a "${V}" -le "${API_MAX}" ] || continue | ||
672 | |||
673 | 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')" | ||
675 | J="$(jit2num ${J:-0})" | ||
676 | |||
677 | if [ "${JIT_REQ}" = "skip" ]; then | ||
678 | [ "${J}" -eq 0 ] || continue | ||
679 | elif [ "${JIT_REQ}" = "yes" ]; then | ||
680 | [ "${J}" -gt 0 ] || continue | ||
681 | [ "${J}" -ge "${JIT_MIN}" ] || continue | ||
682 | [ "${J}" -le "${JIT_MAX}" ] || continue | ||
683 | fi | ||
684 | fi | ||
685 | |||
686 | LUA_PATH="$F" | ||
687 | LUA_VER="$V" | ||
688 | |||
689 | [ "${SHORTEST}" = "yes" -o "${LUA_VER}" -lt "${API_MAX}" ] || break 2 | ||
690 | done | ||
691 | |||
692 | shift | ||
693 | done | ||
694 | } | ||
695 | |||
696 | |||
697 | usage() { | ||
698 | cat <<-EOF | ||
699 | usage: ${0##*/} [-I:L:P:d:Dkrm:xsv:j:JVh] cppflags|ldflags|version|lua|luac | ||
700 | -I PATH additional search directory for includes | ||
701 | -L PATH additional search directory for libraries | ||
702 | -P PATH additional search directory for binaries | ||
703 | -d PATH use PATH as sandbox directory; a random 16 byte suffix is | ||
704 | generated from /dev/urandom and the directory removed on exit | ||
705 | unless a trailing "/" is present | ||
706 | (default sandbox is \$TMPDIR/${0##*/}-XXXXXXXXXXXXXXXX) | ||
707 | -D do not create a sandbox | ||
708 | -k query pkg-config if available | ||
709 | -r recursively search directories | ||
710 | -m MAXDEPTH limit recursion to MAXDEPTH (only for GNU and BSD find) | ||
711 | -x do not cross device mounts when recursing | ||
712 | -s find shortest pathname, otherwise print first best match | ||
713 | -v VERSION require specific Lua version or range | ||
714 | (e.g. "5.1" or "5.1-5.2") | ||
715 | -j VERSION require specific LuaJIT version or range | ||
716 | (e.g. "2.0.1"; empty ranges like "-" force any LuaJIT version) | ||
717 | -J skip LuaJIT if encountered | ||
718 | -V print this script's version information | ||
719 | -h print this usage message | ||
720 | |||
721 | cppflags print derived additional CPPFLAGS necessary | ||
722 | ldflags print derived additional LDFLAGS necessary (TODO) | ||
723 | version print derived Lua API version | ||
724 | luac [GLOB] print path to luac utility using optional glob patterns | ||
725 | (e.g. "luac5.?"; default is "luac*") | ||
726 | lua [GLOB] print path to lua interpreter using optional glob patterns | ||
727 | (e.g. "lua luajit"; default is "lua*") | ||
728 | evalmacro run internal macro evaluator for debugging | ||
729 | testsym run internal library symbol reader for debugging | ||
730 | |||
731 | This utility is used to derive compiler flags and filesystem paths | ||
732 | necessary to utilize Lua, LuaJIT, and particular versions thereof. | ||
733 | On success it prints the requested information and exits with 0, | ||
734 | otherwise it fails with an exit status of 1. | ||
735 | |||
736 | Note that cppflags may not print anything if no additional flags are | ||
737 | required to compile against the requested API version. | ||
738 | |||
739 | When searching, the highest Lua version is preferred. Searching | ||
740 | stops once the highest version in the allowable range is found | ||
741 | unless the -s flag is specified. | ||
742 | |||
743 | LuaJIT is treated like any other Lua installation. If an explicit | ||
744 | LuaJIT version or range is specified, then only LuaJIT installations | ||
745 | will match. To exclude LuaJIT entirely use the -J switch. | ||
746 | |||
747 | This utility processes the environment variables CC, CPPFLAGS, | ||
748 | LDFLAGS, and PATH if present. If recursion is requested, then | ||
749 | directories specified in CPPFLAGS, LDFLAGS, and PATH are also | ||
750 | recursed. | ||
751 | |||
752 | If the environment variable CPPFLAGS is empty and no -I options are | ||
753 | specified directly, then /usr/include and /usr/local/include are | ||
754 | used when probing for cppflags and API version. | ||
755 | |||
756 | Report bugs to <william@25thandClement.com> | ||
757 | EOF | ||
758 | } | ||
759 | |||
760 | |||
761 | version() { | ||
762 | cat <<-EOF | ||
763 | luapath $MYVERSION | ||
764 | vendor $MYVENDOR | ||
765 | release $MYVERSION | ||
766 | EOF | ||
767 | } | ||
768 | |||
769 | |||
770 | while getopts I:L:P:d:Dkrm:xsv:j:JVh OPT; do | ||
771 | case "${OPT}" in | ||
772 | I) | ||
773 | INCDIRS="${INCDIRS:-}${INCDIRS:+:}${OPTARG}" | ||
774 | ;; | ||
775 | L) | ||
776 | LIBDIRS="${LIBDIRS:-}${LIBDIRS:+:}${OPTARG}" | ||
777 | ;; | ||
778 | P) | ||
779 | BINDIRS="${BINDIRS:-}${BINDIRS:+:}${OPTARG}" | ||
780 | ;; | ||
781 | d) | ||
782 | SANDBOX="${OPTARG}" | ||
783 | ;; | ||
784 | D) | ||
785 | SANDBOX= | ||
786 | ;; | ||
787 | k) | ||
788 | PKGCONFIG="$(command -v pkg-config || true)" | ||
789 | ;; | ||
790 | r) | ||
791 | RECURSE=yes | ||
792 | ;; | ||
793 | m) | ||
794 | if [ -n "${OPTARG##[0123456789]}" ]; then | ||
795 | printf -- "${0##*/}: ${OPTARG}: invalid maxdepth\n" >&2 | ||
796 | exit 1 | ||
797 | fi | ||
798 | |||
799 | if find "${TMPDIR:-/tmp}" -maxdepth ${OPTARG} -prune >>/dev/null 2>&1; then | ||
800 | MAXDEPTH="-maxdepth ${OPTARG}" | ||
801 | else | ||
802 | printf -- "${0##*/}: $(command -v find): -maxdepth unsupported\n" >&2 | ||
803 | fi | ||
804 | |||
805 | ;; | ||
806 | x) | ||
807 | XDEV="-xdev" | ||
808 | ;; | ||
809 | s) | ||
810 | SHORTEST=yes | ||
811 | ;; | ||
812 | v) | ||
813 | MIN=${OPTARG%%[,:-]*} | ||
814 | MAX=${OPTARG##*[,:-]} | ||
815 | |||
816 | API_MIN="$(lua2num ${MIN:-0} 0)" | ||
817 | API_MAX="$(lua2num ${MAX:-99} 99)" | ||
818 | |||
819 | if [ "${API_MIN}" -gt "${API_MAX}" ]; then | ||
820 | printf -- "${0##*/}: ${OPTARG}: invalid version range\n" >&2 | ||
821 | exit 1 | ||
822 | fi | ||
823 | |||
824 | ;; | ||
825 | j) | ||
826 | MIN=${OPTARG%%[,:-]*} | ||
827 | MAX=${OPTARG##*[,:-]} | ||
828 | |||
829 | JIT_MIN="$(jit2num ${MIN:-0} 0 0)" | ||
830 | JIT_MAX="$(jit2num ${MAX:-99} 99 99)" | ||
831 | |||
832 | if [ "${JIT_MIN}" -gt "${JIT_MAX}" ]; then | ||
833 | printf -- "${0##*/}: ${OPTARG}: invalid version range\n" >&2 | ||
834 | exit 1 | ||
835 | fi | ||
836 | |||
837 | JIT_REQ=yes | ||
838 | ;; | ||
839 | J) | ||
840 | JIT_REQ=skip | ||
841 | ;; | ||
842 | V) | ||
843 | version | ||
844 | exit 0 | ||
845 | ;; | ||
846 | h) | ||
847 | usage | ||
848 | exit 0 | ||
849 | ;; | ||
850 | *) | ||
851 | usage >&2 | ||
852 | exit 1 | ||
853 | ;; | ||
854 | esac | ||
855 | done | ||
856 | |||
857 | shift $(($OPTIND - 1)) | ||
858 | |||
859 | |||
860 | for U in ${CC:-cc} find grep od rm rmdir sed xargs; do | ||
861 | if ! command -v ${U} >>/dev/null 2>&1; then | ||
862 | printf -- "${0##*/}: ${U}: command not found\n" >&2 | ||
863 | fi | ||
864 | done | ||
865 | |||
866 | |||
867 | if [ -n "${SANDBOX}" ]; then | ||
868 | if [ "${SANDBOX}" = "${SANDBOX%/}" ]; then | ||
869 | if [ ! -c "${DEVRANDOM}" ]; then | ||
870 | # TODO: expand DEVRANDOM into set of different possibilities to check | ||
871 | printf -- "${0##*/}: ${DEVRANDDOM}: no character random device available\n" >&2 | ||
872 | exit 1 | ||
873 | fi | ||
874 | |||
875 | TMP="${SANDBOX}$(od -An -N8 -tx1 < ${DEVRANDOM} 2>>/dev/null | tr -d ' ')" | ||
876 | |||
877 | if [ ${#TMP} -ne $((${#SANDBOX} + 16)) ]; then | ||
878 | printf -- "${0##*/}: ${SANDBOX}: unable to generate random suffix\n" >&2 | ||
879 | exit 1 | ||
880 | fi | ||
881 | |||
882 | SANDBOX="${TMP}" | ||
883 | |||
884 | trap "cd .. && rm -f -- ${SANDBOX}/* && rmdir -- ${SANDBOX}" EXIT | ||
885 | fi | ||
886 | |||
887 | if [ ! -d "${SANDBOX}" ]; then | ||
888 | OMASK="$(umask)" | ||
889 | umask 0777 | ||
890 | mkdir -m0550 -- "${SANDBOX}" || exit 1 | ||
891 | umask ${OMASK} | ||
892 | fi | ||
893 | |||
894 | cd ${SANDBOX} | ||
895 | fi | ||
896 | |||
897 | |||
898 | CPPDIRS="$(idirs "${CPPFLAGS:-}")" | ||
899 | |||
900 | if [ -z "${CPPDIRS}" -a -z "${INCDIRS}" ]; then | ||
901 | INCDIRS="/usr/include:/usr/local/include" | ||
902 | fi | ||
903 | |||
904 | |||
905 | LDDIRS="$(ldirs "${LDFLAGS:-}")" | ||
906 | |||
907 | if [ -z "${LDDIRS}" -a -z "${LIBDIRS}" ]; then | ||
908 | LIBDIRS="/lib:/usr/lib:/usr/local/lib" | ||
909 | fi | ||
910 | |||
911 | |||
912 | case "${1:-}" in | ||
913 | cppflags) | ||
914 | findversion | ||
915 | |||
916 | [ "${API_VER:-0}" -gt 0 ] || exit 1 | ||
917 | |||
918 | [ -z "${API_DIR:-}" ] || printf -- "-I${API_DIR}\n" | ||
919 | |||
920 | ;; | ||
921 | ldflags) | ||
922 | findlib | ||
923 | |||
924 | [ "${LIBLUA_VER:-0}" -gt 0 ] || exit 1 | ||
925 | |||
926 | printf -- "-L${LIBLUA_DIR} -l${LIBLUA_LIB}\n" | ||
927 | |||
928 | ;; | ||
929 | version) | ||
930 | findversion | ||
931 | |||
932 | [ "${API_VER:-0}" -gt 0 ] || exit 1 | ||
933 | |||
934 | printf "$(((${API_VER} / 100) % 100)).$((($API_VER) % 100))\n" | ||
935 | |||
936 | ;; | ||
937 | libv*) | ||
938 | findlib | ||
939 | |||
940 | [ "${LIBLUA_VER:-0}" -gt 0 ] || exit 1 | ||
941 | |||
942 | printf "$(((${LIBLUA_VER} / 100) % 100)).$((($LIBLUA_VER) % 100))\n" | ||
943 | |||
944 | ;; | ||
945 | luac) | ||
946 | shift | ||
947 | |||
948 | if [ $# -eq 0 ]; then | ||
949 | set -- luac\* | ||
950 | fi | ||
951 | |||
952 | findluac $* | ||
953 | |||
954 | [ -n "${LUAC_PATH}" ] || exit 1 | ||
955 | |||
956 | printf -- "${LUAC_PATH}\n" | ||
957 | |||
958 | ;; | ||
959 | lua) | ||
960 | shift | ||
961 | |||
962 | if [ $# -eq 0 ]; then | ||
963 | set -- lua\* | ||
964 | fi | ||
965 | |||
966 | findlua $* | ||
967 | |||
968 | [ -n "${LUA_PATH}" ] || exit 1 | ||
969 | |||
970 | printf -- "${LUA_PATH}\n" | ||
971 | |||
972 | ;; | ||
973 | evalmacro) | ||
974 | shift | ||
975 | |||
976 | evalmacro $* | ||
977 | ;; | ||
978 | testsym) | ||
979 | shift | ||
980 | |||
981 | if testsym $*; then | ||
982 | printf "found\n" | ||
983 | exit 0 | ||
984 | else | ||
985 | printf "not found\n" | ||
986 | exit 1 | ||
987 | fi | ||
988 | ;; | ||
989 | *) | ||
990 | if [ -n "${1:-}" ]; then | ||
991 | printf -- "${0##*/}: ${1}: unknown command\n" >&2 | ||
992 | else | ||
993 | printf -- "${0##*/}: no command specified\n" >&2 | ||
994 | fi | ||
995 | |||
996 | exit 1 | ||
997 | ;; | ||
998 | esac | ||
999 | |||
1000 | exit 0 | ||
diff --git a/mk/vendor.cc b/mk/vendor.cc new file mode 100755 index 0000000..5ddd99d --- /dev/null +++ b/mk/vendor.cc | |||
@@ -0,0 +1,17 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | set -e | ||
4 | |||
5 | : ${CC:=cc} | ||
6 | |||
7 | ${CC} -E - <<-EOF | awk '/sunpro/||/clang/||/gcc/||/other/{ print $1; exit; }' | ||
8 | #if defined __SUNPRO_C | ||
9 | sunpro | ||
10 | #elif defined __clang__ | ||
11 | clang | ||
12 | #elif defined __GNUC__ | ||
13 | gcc | ||
14 | #else | ||
15 | other | ||
16 | #endif | ||
17 | EOF | ||
diff --git a/mk/vendor.os b/mk/vendor.os new file mode 100755 index 0000000..57d8ff6 --- /dev/null +++ b/mk/vendor.os | |||
@@ -0,0 +1,3 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | uname -s | ||