-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·54 lines (47 loc) · 1.43 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
#!/bin/sh
# shellcheck disable=SC2086
target="${1:-build}"
PREFIX="${PREFIX:-/usr/local}"
DESTDIR="${DESTDIR:-/}"
main="main.c"
program="piscou"
LDFLAGS="$LDFLAGS $(pkg-config libmagic --libs)"
CC=${CC:-cc}
if [ $CC = "clang" ]; then
CFLAGS="$CFLAGS -Weverything "
CFLAGS="$CFLAGS -Wno-unsafe-buffer-usage -Wno-format-nonliteral "
fi
CFLAGS="$CFLAGS -std=c99 -D_DEFAULT_SOURCE"
CFLAGS="$CFLAGS -Wextra -Wall "
CFLAGS="$CFLAGS -Wno-disabled-macro-expansion -Wno-unused-parameter "
CFLAGS="$CFLAGS -Wno-unused-variable "
echo "target=$target"
if [ "$target" = "debug" ]; then
CFLAGS="$CFLAGS -g -fsanitize=undefined "
CPPFLAGS="$CPPFLAGS -DPISCOU_DEBUG=1"
else
CFLAGS="$CFLAGS -O2 -flto "
CPPFLAGS="$CPPFLAGS -DPISCOU_DEBUG=0"
fi
case "$target" in
"uninstall")
set -x
rm -f ${DESTDIR}${PREFIX}/bin/${program}
rm -f ${DESTDIR}${PREFIX}/man/man1/${program}.1
;;
"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 $CPPFLAGS $CFLAGS -o ${program} "$main" $LDFLAGS
;;
*)
echo "usage: $0 [ uninstall / install / build / debug ]"
;;
esac