#!/bin/sh
bold_white="[1;37m"
bold_green="[1;32m"
bold_red="[1;31m"
end="[0m"
bin_name=$(basename `pwd`)
dev_build_steps=("build")
prod_build_steps=("build" "strip")
test_day=""
build_steps=("${dev_build_steps[@]}")
compiler_defines=""
common_compiler_flags="-debug -vet -strict-style -warnings-as-errors"
for arg in "$@"; do
case $arg in
-test)
build_steps=("test")
if [[ -n "$2" && "$2" != -* ]]; then
test_day="$2"
fi
;;
-release)
common_compiler_flags="-o:speed -no-bounds-check -disable-assert -extra-linker-flags:"-Wl,--gc-sections""
build_steps=("${prod_build_steps[@]}")
;;
*)
;;
esac
done
compiler_flags="${compiler_defines} ${common_compiler_flags}"
echo "${bold_white}Using compiler flags:${end} ${compiler_flags}"
if [ ! -d bin ]; then
mkdir bin
fi
pushd bin 1>/dev/null 2>&1
for step in ${!build_steps[@]}; do
case ${build_steps[$step]} in
"test")
echo ""
echo "${bold_white}Running tests${end}"
if [[ -z $test_day ]]; then
odin test ../src --all-packages $compiler_flags
else
odin test ../src/day_$(printf "%02d" "$test_day") $compiler_flags
fi
result=$?
if [ $result -ne 0 ]; then
echo "${bold_red}FAIL${end}"
exit $result
fi
echo ""
;;
"build")
echo "${bold_white}Building:${end} $(pwd)/$bin_name"
odin build ../src -out:$bin_name -show-timings $compiler_flags
result=$?
if [ $result -ne 0 ]; then
echo "${bold_red}FAIL${end}"
exit $result
fi
echo ""
echo "${bold_green}OK${end}"
;;
"strip")
strip -s $(pwd)/$bin_name
;;
*)
;;
esac
done
popd 1>/dev/null 2>&1