Handle short writes.
[buftee] / tests / make_sanitized.sh
1 #!/bin/bash
2 #
3 # Build a sanitized version with clang.
4 # Author: Emil Mikulic <emikulic@gmail.com>
5 #
6 BOLD=$(tput bold)
7 NORMAL=$(tput sgr0)
8 RED=$(tput setf 9)
9 GRAY=$(tput setf 8)
10 RULER=${GRAY}$(for i in $(seq $(tput cols)); do echo -n -; done)${NORMAL}
11 notice() { echo "${BOLD}==> $*${NORMAL}"; }
12 fatal() { echo "${RED}==> FATAL: $*${NORMAL}" >&2; exit 1; }
13 report() {
14 local RET=$?
15 echo -n "${BOLD}==> $*: "
16 if [[ $RET = 0 ]]; then
17 echo success${NORMAL}
18 else
19 echo ${RED}FAILURE${NORMAL}
20 fi
21 }
22
23 RUNDIR=$PWD
24 notice "[$0] run from [$RUNDIR]"
25 cd $RUNDIR || exit 1
26 SRCDIR=$(cd $(dirname $0)/..; pwd)
27 notice "src dir is [$SRCDIR]"
28 cd $SRCDIR || exit 1
29
30 # Local hacks.
31 MY_CLANG=$HOME/llvm/install/bin/clang
32 if [[ -z $CLANG ]]; then
33 # No CLANG env var set, try to guess.
34 if [[ -e $MY_CLANG ]]; then
35 CLANG=$MY_CLANG
36 else
37 CLANG=clang
38 fi
39 fi
40 if ! which $CLANG >/dev/null; then
41 fatal "can't find clang as [$CLANG]"
42 fi
43 notice "clang is [$CLANG]"
44
45 rm -f buftee
46 echo ${RULER}
47 notice build: clang with sanitizer
48 CFLAGS="-g -O0 -fno-omit-frame-pointer \
49 -fsanitize=address-full \
50 -fsanitize=integer \
51 -fsanitize=undefined \
52 -fsanitize=unsigned-integer-overflow \
53 -Weverything \
54 -Wno-c++98-compat \
55 -Wno-padded \
56 -fshow-diagnostics"
57 env "CC=$CLANG" "CFLAGS=$CFLAGS" make
58 report build
59
60 # vim:set ts=2 sw=2 et tw=80: