Make build.sh work evan with no arguments
[minish.git] / build.sh
blob7136953e8946c54cae92ac2bd96f15eaf621612b
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 for JOB in $(jobs -p); do
34 wait "$JOB" || exit $?
35 done