• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/bash
2# Copyright (C) 2016 Sebastian Pipping <sebastian@pipping.org>
3# Licensed under MIT license
4
5set -o nounset
6
7: ${GCC_CC:=gcc}
8: ${GCC_CXX:=g++}
9: ${CLANG_CC:=clang}
10: ${CLANG_CXX:=clang++}
11
12: ${AR:=ar}
13: ${CC:="${CLANG_CC}"}
14: ${CXX:="${CLANG_CXX}"}
15: ${LD:=ld}
16: ${MAKE:=make}
17
18: ${BASE_COMPILE_FLAGS:="-pipe -Wall -Wextra -pedantic -Wno-overlength-strings -Wno-long-long"}
19
20ANNOUNCE() {
21    local open='\e[1m'
22    local close='\e[0m'
23
24    echo -e -n "${open}"
25    echo -n "# $*"
26    echo -e "${close}"
27}
28
29RUN() {
30    ANNOUNCE "$@"
31    env "$@"
32}
33
34main() {
35    local mode="${1:-}"
36    shift
37
38    local RUNENV
39    local BASE_COMPILE_FLAGS="${BASE_COMPILE_FLAGS}"
40
41    case "${mode}" in
42    address)
43        # http://clang.llvm.org/docs/AddressSanitizer.html
44        local CC="${CLANG_CC}"
45        local CXX="${CLANG_CXX}"
46        BASE_COMPILE_FLAGS+=" -g -fsanitize=address -fno-omit-frame-pointer"
47        ;;
48    coverage | lib-coverage | app-coverage)
49        local CC="${GCC_CC}"
50        local CXX="${GCC_CXX}"
51        BASE_COMPILE_FLAGS+=" --coverage --no-inline"
52        ;;
53    egypt)
54        BASE_COMPILE_FLAGS+=" -fdump-rtl-expand"
55        ;;
56    memory)
57        # http://clang.llvm.org/docs/MemorySanitizer.html
58        BASE_COMPILE_FLAGS+=" -fsanitize=memory -fno-omit-frame-pointer -g -O2 -fsanitize-memory-track-origins -fsanitize-blacklist=$PWD/memory-sanitizer-blacklist.txt"
59        ;;
60    ncc)
61        # http://students.ceid.upatras.gr/~sxanth/ncc/
62        local CC="ncc -ncgcc -ncld -ncfabs"
63        local AR=nccar
64        local LD=nccld
65        BASE_COMPILE_FLAGS+=" -fPIC"
66        ;;
67    undefined)
68        # http://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
69        BASE_COMPILE_FLAGS+=" -fsanitize=undefined"
70        export UBSAN_OPTIONS=print_stacktrace=1
71        ;;
72    *)
73        echo "Usage:" 1>&2
74        echo "  ${0##*/} (address|coverage|lib-coverage|app-coverage|egypt|memory|ncc|undefined)" 1>&2
75        exit 1
76        ;;
77    esac
78
79    local CFLAGS="-std=c89 ${BASE_COMPILE_FLAGS} ${CFLAGS:-}"
80    local CXXFLAGS="-std=c++98 ${BASE_COMPILE_FLAGS} ${CXXFLAGS:-}"
81
82    (
83        set -e
84
85        RUN CC="${CC}" CFLAGS="${CFLAGS}" \
86                CXX="${CXX}" CXXFLAGS="${CXXFLAGS}" \
87                AR="${AR}" \
88                LD="${LD}" \
89                ./configure "$@"
90
91        RUN "${MAKE}" clean all
92
93        case "${mode}" in
94        egypt|ncc)
95            ;;
96        *)
97            RUN "${MAKE}" check run-xmltest
98            ;;
99        esac
100    )
101    [[ $? -ne 0 ]] && exit 1
102
103    case "${mode}" in
104    coverage)
105        find -name '*.gcda' | sort | xargs gcov
106        ;;
107    lib-coverage)
108        find lib -name '*.gcda' | sort | xargs gcov
109        ;;
110    app-coverage)
111        find lib xmlwf -name '*.gcda' | sort | xargs gcov
112        ;;
113    egypt)
114        local DOT_FORMAT="${DOT_FORMAT:-svg}"
115        local o="callgraph.${DOT_FORMAT}"
116        ANNOUNCE "egypt ...... | dot ...... > ${o}"
117        find -name '*.expand' \
118                | sort \
119                | xargs -r egypt \
120                | unflatten -c 20 \
121                | dot -T${DOT_FORMAT} -Grankdir=LR \
122                > "${o}"
123        ;;
124    ncc)
125        RUN nccnav ./.libs/libexpat.a.nccout
126        ;;
127    esac
128}
129
130main "$@"
131