#!/bin/sh LUA_INTERPRETER=${LUA_INTERPRETER:=lua} case "$LUA_INTERPRETER" in /*) ;; *) ENV_WRAPPER=${ENV_WRAPPER:="$(command -v env)"} ;; esac do_build() { mkdir -p out/lua/cratera/ || exit 1 mkdir -p out/bin || exit 1 # worst tool for this job cp -r src/cratera/* out/lua/cratera/ || exit 1 if [ "$ENV_WRAPPER" = '' ]; then printf "#!%s\n" "$LUA_INTERPRETER" >out/bin/cratera || exit 1 else printf "#!%s %s\n" "$ENV_WRAPPER" "$LUA_INTERPRETER" >out/bin/cratera || exit 1 fi cat src/bin/cratera.lua >>out/bin/cratera || exit 1 chmod +x out/bin/cratera || exit 1 } do_test() { # FIXME this does NOT handle LUA_PATH correctly. # FIXME nor LUA_INIT. do_build || exit 1 mkdir -p out/test || exit 2 # these tests use the regular lua interpreter LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' "$LUA_INTERPRETER" test/testp.lua || exit 2 LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' "$LUA_INTERPRETER" test/testc.lua || exit 2 LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' "$LUA_INTERPRETER" test/testbc.lua || exit 2 # these tests use the cratera interpreter LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' out/bin/cratera test/tests.cratera || exit 2 } case "$1" in -h|--help|help) echo 'The Cratera "Build System"' echo 'To build, use './build.sh build'. Files will be put in out/.' echo 'To run tests, use './build.sh test'.' echo 'The currently selected Lua interpreter is:' printf ' LUA_INTERPRETER=%s' "$LUA_INTERPRETER" echo '' echo 'The currently selected env wrapper is:' printf ' ENV_WRAPPER=%s' "$ENV_WRAPPER" echo '' ;; test) do_test || exit $? ;; build|'') do_build || exit $? ;; *) echo 'sorry' ;; esac