-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·69 lines (60 loc) · 1.79 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
#!/bin/sh
testing () {
for src in *.c; do
[ "$src" = "$main" ] && continue
printf "Testing $src...\n"
flags="$(awk '/flags:/ { $1=$2=""; print $0 }' "$src")"
set -x
if $CC $CFLAGS -D TESTING_THIS_FILE=1 $src -o $src.exe $flags; then
./$src.exe
else
printf "Failed to compile ${RED} $src ${RES}, is main() defined?\n"
fi
set +x
done
rm *.exe
}
target="${1:-build}"
PREFIX="${PREFIX:-/usr/local}"
DESTDIR="${DESTDIR:-/}"
main="main.c"
program="dwmblocks2"
CFLAGS="$CFLAGS -std=c99 -D_DEFAULT_SOURCE "
CFLAGS="$CFLAGS -Wextra -Wall -Wno-unused-macros -Wno-missing-field-initializers "
LDFLAGS="$LDFLAGS -lm $(pkg-config x11 --libs)"
CC=${CC:-cc}
if [ $CC = "clang" ]; then
CFLAGS="$CFLAGS -Weverything "
CFLAGS="$CFLAGS -Wno-unsafe-buffer-usage -Wno-format-nonliteral "
CFLAGS="$CFLAGS -Wno-disabled-macro-expansion "
fi
if [ "$target" = "debug" ]; then
CFLAGS="$CFLAGS -g -fsanitize=undefined -DDWMBLOCKS2_DEBUG=1"
else
CFLAGS="$CFLAGS -O2 -flto -DDWMBLOCKS2_DEBUG=0"
fi
case "$target" in
"uninstall")
set -x
rm -f ${DESTDIR}${PREFIX}/bin/${program}
rm -f ${DESTDIR}${PREFIX}/man/man1/${program}.1
;;
"test")
testing
;;
"install")
[ ! -f $program ] && $0 build
set -x
install -Dm755 ${program} ${DESTDIR}${PREFIX}/bin/${program}
install -Dm644 ${program}.1 ${DESTDIR}${PREFIX}/man/man1/${program}.1
;;
"build"|"debug")
ctags --kinds-C=+l *.h *.c 2> /dev/null || true
vtags.sed tags > .tags.vim 2> /dev/null || true
set -x
$CC $CFLAGS -o ${program} "$main" $LDFLAGS
;;
*)
echo "usage: $0 [ uninstall / test / install / build / debug ]"
;;
esac