-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·71 lines (61 loc) · 1.57 KB
/
build.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
67
68
69
70
71
#!/usr/bin/env bash
set -e # fail if any command has a non-zero exit status
set -u # fail if any undefined variable is referenced
set -o pipefail # propagate failure exit status through a pipeline
shopt -s globstar nullglob # enable recursive and null globbing
exe_name="co2minimon"
build_dir="./out"
cc=clang
source_files=("main.c")
cflags=("-std=c11" "-D_XOPEN_SOURCE=700" "-Wall" "-Wextra" "-Wpedantic" "-Wsign-compare" "-Wswitch-enum")
debug_flags=("-g" "-O0")
release_flags=("-O2" "-Os")
build_release() {
release_dir="${build_dir}/release"
release_path="${release_dir}/${exe_name}"
mkdir -p "$release_dir"
(
set -x;
"$cc" "${cflags[@]}" "${release_flags[@]}" "${source_files[@]}" -o "$release_path"
)
}
build_debug() {
debug_dir="${build_dir}/debug"
debug_path="${debug_dir}/${exe_name}"
mkdir -p "$debug_dir"
(
set -x;
"$cc" "${cflags[@]}" "${debug_flags[@]}" "${source_files[@]}" -o "$debug_path"
)
}
usage() {
echo "build.sh - Build ${exe_name}"
echo " "
echo "build.sh [options]"
echo " "
echo "options:"
echo "-h, --help show help"
echo "-d, --debug build only debug executable"
}
debug_build=false
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-d|--debug)
debug_build=true
shift
;;
*)
break
;;
esac
done
if [ "$debug_build" = true ]; then
build_debug
else
build_release
fi
exit 0