blob: 6f70eb0f0c8da6e8f92f1651eab9b3a9da354e3d (
plain) (
tree)
|
|
#!/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/prebuilt/ || exit 1
mkdir -p out/cratera/cratera.cratera.d || exit 1
mkdir -p out/bin || exit 1
# worst tool for this job
cp -R src/cratera out/lua/ || exit 1
cp -R src/cratera.cratera.d out/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
env -i "$LUA_INTERPRETER" src/host/genpath.lua >out/lua/cratera/prebuilt/path.lua || exit 1
}
do_test() {
# FIXME this does NOT handle LUA_PATH correctly.
# FIXME nor LUA_INIT.
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
LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' CRATERA_PATH='./test/?.cratera;./out/cratera/?.cratera;;' "$LUA_INTERPRETER" test/test_bootstrap.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)
printf '%s\n' \
'The Cratera "Build System"' \
'To build, use '\''./build.sh build'\''. Files will be put in '\''out/'\''.' \
'To run tests, use '\''./build.sh test'\''.' \
'The currently selected Lua interpreter is:' \
"$(printf ' LUA_INTERPRETER=%s' "$LUA_INTERPRETER")" \
'The currently selected env wrapper is:' \
"$(printf ' ENV_WRAPPER=%s' "$ENV_WRAPPER")"
;;
test-only)
do_test
;;
test)
do_build
do_test
;;
build|'')
do_build
;;
*)
printf '%s\n' 'sorry'
;;
esac
|