summary refs log tree commit diff stats
path: root/build.sh
blob: cdff7bd2d93b6d646083021c5bc1a08fe15b97b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/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