compile.sh 917 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/sh
  2. arg=-1
  3. if [ -v 1 ]; then
  4. arg=$1
  5. fi
  6. if [ $arg = "help" ]; then
  7. echo "USAGE: compile.sh <option>"
  8. echo ""
  9. echo "Compiles debug build when called without an option."
  10. echo "Options:"
  11. echo " help : Show this help text."
  12. echo " clean : Clean target directory."
  13. echo " release: Build with optimizations."
  14. echo " run : Build debug build and run."
  15. exit
  16. fi
  17. if [ $arg = "clean" ]; then
  18. rm -rf ./target/*
  19. exit
  20. fi
  21. version=$(git rev-parse HEAD)
  22. oflag="-Og"
  23. debug_flag="-ggdb -DDEBUG"
  24. if [ $arg = "release" ]; then
  25. oflag="-O3"
  26. debug_flag=""
  27. fi
  28. src="src/*.c"
  29. macros="-DVERSION=\"$version\""
  30. flags="-std=c23 $oflag $debug_flag $macros -Wall -Wextra -Werror -Wpedantic -pedantic-errors"
  31. includes="-I src/headers"
  32. cmd="clang $flags $includes $src -o target/sanke"
  33. echo $cmd
  34. $cmd
  35. if [ $? -gt 0 ]; then
  36. exit
  37. fi
  38. if [ $arg = "run" ]; then
  39. ./target/sanke
  40. fi