-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_examples_posix.sh
66 lines (56 loc) · 963 Bytes
/
build_examples_posix.sh
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
#!/bin/sh
set -e
CC=cc
CFLAGS="-Wall -pedantic -O2 -Isrc/include"
verbose=0
build() {
for file in $files; do
source_file="src/$(echo $file | sed -e 's/_example//')"
out_file="out/$(echo $file | sed -e 's/\.c/.exe/')"
if [ -e "$source_file" ]; then
command="$CC $CFLAGS -o $out_file examples/$file $source_file"
else
command="$CC $CFLAGS -o $out_file examples/$file"
fi
if [ $verbose -eq 1 ]; then
echo $command
fi
$command
done
}
if [ ! -d out ]; then
mkdir out
fi
files=""
if [ -z "${1+x}" ]; then
for file in examples/*; do
files="$(basename $file) $files"
done
build
exit
fi
case $1 in
help)
echo "Usage: $0 [help] [examples]"
echo "Builds given examples. Defaults to all."
exit
;;
all)
for f in examples/*; do
files="$files $f"
done
build
exit
;;
-v)
verbose=1
shift
;;
esac
if [ ! -z "${files+x}" ]; then
while [[ $# -gt 0 ]]; do
files="$files $1_example.c"
shift
done
fi
build