build 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. # Build script for the project.
  3. set -e # stop immediately on error
  4. ## prologue: environment defaults
  5. test "$CC" || export CC=cc
  6. test "$CFLAGS" || export CFLAGS="-g -O3"
  7. # some additional flags for safety
  8. export CFLAGS="$CFLAGS -std=c99 -Wall -Wextra -ftrapv -fno-strict-aliasing"
  9. ## helpers
  10. # {{{
  11. # noisily signal success if $1 is older than _any_ of the remaining args
  12. older_than() {
  13. local target="$1"
  14. shift
  15. if [ ! -e "$target" ]
  16. then
  17. echo "updating $target" >&2
  18. return 0 # success
  19. fi
  20. local f
  21. for f in "$@"
  22. do
  23. if [ "$f" -nt "$target" ]
  24. then
  25. echo "updating $target" >&2
  26. return 0 # success
  27. fi
  28. done
  29. return 1 # failure
  30. }
  31. # noisily switch directories, as a sort of section heading to group older_than blocks
  32. noisy_cd() {
  33. cd $1
  34. echo "-- `pwd`" >&2
  35. }
  36. # }}}
  37. ## body: things to generate, what they depend on, and how to generate them from their dependencies
  38. older_than a.out x.c && {
  39. $CC $CFLAGS x.c
  40. }
  41. ## epilogue
  42. # if we got to the end, signal success
  43. # otherwise you incorrectly signal failure when the final target is not older_than its dependencies
  44. exit 0