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 61 62 63 64 65 66 67 68 69 70 71

#!/bin/sh # Build script for the project. # For details on the basic form of this script, see https://notabug.org/akkartik/basic-build. set -e # stop immediately on error ## prolog: environment defaults test "$CC" || export CC=cc test "$CFLAGS" || export CFLAGS="-g -O3" # some additional flags for safety export CFLAGS="$CFLAGS -std=c99 -Wall -Wextra -ftrapv -fno-strict-aliasing" ## helpers # {{{ # noisily signal success if $1 is older than _any_ of the remaining args older_than() { local target=$1 shift if [ ! -e $target ] then echo "updating $target" >&2 return 0 # success fi local f for f in $* do if [ $f -nt $target ] then echo "updating $target" >&2 return 0 # success fi done return 1 # failure } # noisily switch directories, as a sort of section heading to group older_than blocks noisy_cd() { cd $1 echo "-- `pwd`" >&2 } # redirect to $1, unless it's already identical update() { if [ ! -e $1 ] then cat > $1 else cat > $1.tmp diff -q $1 $1.tmp >/dev/null && rm $1.tmp || mv $1.tmp $1 fi } # }}} ## body: things to generate, what they depend on, and how to generate them from their dependencies # auto-generate a list of function prototypes grep -h "^[^ #].*) {" *.c |sed 's/ {.*/;/' |update function_list # auto-generate a list of test names grep -h "^\s*void test_" *.c |sed 's/^\s*void \(.*\)(void) {.*/\1,/' |update test_list older_than a.out *.c *.h function_list test_list && { $CC $CFLAGS *.c } ## epilog # if we got to the end, signal success # otherwise you incorrectly signal failure when the final target is not older_than its dependencies exit 0