summary refs log tree commit diff stats
path: root/build.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh63
1 files changed, 59 insertions, 4 deletions
diff --git a/build.sh b/build.sh
index 173fe8c..cdff7bd 100755
--- a/build.sh
+++ b/build.sh
@@ -1,5 +1,60 @@
 #!/bin/sh
-mkdir -p out/cratera/
-# worst tool for this job
-cp -r cratera/* out/cratera/
-cp cratera.lua out/cratera/init.lua
+
+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