Make pipe wait for its children
[minish.git] / build.sh
blobdaaa5c128d1f6cb4b9d5bb724c88c60ddd873cba
1 #!/bin/sh
3 readonly CLANG="clang -DNDEBUG -ferror-limit=1 -flto \
4 -fvisibility=hidden -march=native -O3 -s -static -std=c11 -Werror \
5 -Weverything -Wno-disabled-macro-expansion -Wno-reserved-id-macro"
7 readonly NEWLINE='
10 readonly SED_SCRIPT='s_[ \t]*#include[ \t]*"\(.*\)".*_src/\1_p'
12 is_not_newer_than() {
13 [ ! -f "$1" ] || [ -z "$(find "$1" -newer "$2")" ]
16 mkdir -p bin/
17 for SOURCE in src/*.c; do
18 OBJECT="${SOURCE%.c}"
19 OBJECT="bin${OBJECT#src}"
20 IFS="$NEWLINE"
21 for DEP in "$SOURCE" $(sed -n "$SED_SCRIPT" "$SOURCE"); do
22 if is_not_newer_than "$OBJECT" "$DEP"; then
23 if [ $# -eq 0 ]; then
24 IFS=' '
25 $CLANG -o "$OBJECT" "$SOURCE" &
26 else
27 "$@" -o "$OBJECT" "$SOURCE" &
29 break
31 done
32 done
33 ERROR=0
34 for JOB in $(jobs -p); do
35 wait "$JOB" || ERROR=$?
36 done
37 exit $ERROR