summary refs log blame commit diff stats
path: root/build.sh
blob: 9b78d8c86349c40d18111a0bd1ab6c597488cc38 (plain) (tree)
1
2
3
4
5
6
7
8
         
 
                                       



                          
                                                               






                                           
                                            











                                                                                               










                                                                                                      










                                                                                                      

                  

                        

                  
                        

                  
                                     

                  
#!/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/ || 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.
	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)
		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