2016-05-15 08:11:11 -04:00
|
|
|
#! /bin/bash
|
|
|
|
# Copyright (C) 2016 Sebastian Pipping <sebastian@pipping.org>
|
|
|
|
# Licensed under MIT license
|
|
|
|
|
|
|
|
set -o nounset
|
|
|
|
|
|
|
|
: ${GCC_CC:=gcc}
|
|
|
|
: ${GCC_CXX:=g++}
|
|
|
|
: ${CLANG_CC:=clang}
|
|
|
|
: ${CLANG_CXX:=clang++}
|
|
|
|
|
2016-05-24 14:34:07 -04:00
|
|
|
: ${AR:=ar}
|
2016-05-15 08:11:11 -04:00
|
|
|
: ${CC:="${CLANG_CC}"}
|
|
|
|
: ${CXX:="${CLANG_CXX}"}
|
2016-05-24 14:34:07 -04:00
|
|
|
: ${LD:=ld}
|
2016-05-15 08:11:11 -04:00
|
|
|
: ${MAKE:=make}
|
|
|
|
|
2017-08-23 10:03:19 -04:00
|
|
|
: ${BASE_COMPILE_FLAGS:="-pipe -Wall -Wextra -pedantic -Wno-overlength-strings -Wno-long-long"}
|
2019-01-27 10:13:34 -05:00
|
|
|
: ${BASE_LINK_FLAGS:=}
|
2016-05-15 08:11:11 -04:00
|
|
|
|
2016-05-30 14:56:00 -04:00
|
|
|
ANNOUNCE() {
|
2016-05-24 14:33:13 -04:00
|
|
|
local open='\e[1m'
|
|
|
|
local close='\e[0m'
|
|
|
|
|
|
|
|
echo -e -n "${open}"
|
|
|
|
echo -n "# $*"
|
|
|
|
echo -e "${close}"
|
2016-05-30 14:56:00 -04:00
|
|
|
}
|
2016-05-24 14:33:13 -04:00
|
|
|
|
2016-05-30 14:56:00 -04:00
|
|
|
RUN() {
|
|
|
|
ANNOUNCE "$@"
|
2016-05-24 14:33:13 -04:00
|
|
|
env "$@"
|
|
|
|
}
|
|
|
|
|
2016-05-15 08:11:11 -04:00
|
|
|
main() {
|
|
|
|
local mode="${1:-}"
|
2016-05-24 14:33:13 -04:00
|
|
|
shift
|
|
|
|
|
2016-05-15 08:11:11 -04:00
|
|
|
local RUNENV
|
2017-07-15 13:29:48 -04:00
|
|
|
local BASE_COMPILE_FLAGS="${BASE_COMPILE_FLAGS}"
|
2016-05-15 08:11:11 -04:00
|
|
|
|
|
|
|
case "${mode}" in
|
|
|
|
address)
|
|
|
|
# http://clang.llvm.org/docs/AddressSanitizer.html
|
2017-07-15 13:35:38 -04:00
|
|
|
local CC="${CLANG_CC}"
|
|
|
|
local CXX="${CLANG_CXX}"
|
2017-07-15 13:29:48 -04:00
|
|
|
BASE_COMPILE_FLAGS+=" -g -fsanitize=address -fno-omit-frame-pointer"
|
2019-01-27 10:13:34 -05:00
|
|
|
BASE_LINK_FLAGS+=" -g -Wc,-fsanitize=address" # "-Wc," is for libtool
|
2016-05-15 08:11:11 -04:00
|
|
|
;;
|
2017-01-30 10:27:54 -05:00
|
|
|
coverage | lib-coverage | app-coverage)
|
2016-05-15 08:11:11 -04:00
|
|
|
local CC="${GCC_CC}"
|
|
|
|
local CXX="${GCC_CXX}"
|
2017-07-15 13:29:48 -04:00
|
|
|
BASE_COMPILE_FLAGS+=" --coverage --no-inline"
|
2016-05-15 08:11:11 -04:00
|
|
|
;;
|
2016-05-30 14:29:33 -04:00
|
|
|
egypt)
|
2017-07-15 13:29:48 -04:00
|
|
|
BASE_COMPILE_FLAGS+=" -fdump-rtl-expand"
|
2016-05-30 14:29:33 -04:00
|
|
|
;;
|
2016-05-15 08:11:11 -04:00
|
|
|
memory)
|
|
|
|
# http://clang.llvm.org/docs/MemorySanitizer.html
|
2017-08-30 16:32:46 -04:00
|
|
|
BASE_COMPILE_FLAGS+=" -fsanitize=memory -fno-omit-frame-pointer -g -O2 -fsanitize-memory-track-origins -fsanitize-blacklist=$PWD/memory-sanitizer-blacklist.txt"
|
2016-05-15 08:11:11 -04:00
|
|
|
;;
|
2016-05-24 14:34:07 -04:00
|
|
|
ncc)
|
|
|
|
# http://students.ceid.upatras.gr/~sxanth/ncc/
|
|
|
|
local CC="ncc -ncgcc -ncld -ncfabs"
|
|
|
|
local AR=nccar
|
|
|
|
local LD=nccld
|
2017-07-15 13:29:48 -04:00
|
|
|
BASE_COMPILE_FLAGS+=" -fPIC"
|
2016-05-24 14:34:07 -04:00
|
|
|
;;
|
2016-05-15 08:11:11 -04:00
|
|
|
undefined)
|
|
|
|
# http://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
|
2017-07-15 13:29:48 -04:00
|
|
|
BASE_COMPILE_FLAGS+=" -fsanitize=undefined"
|
2016-05-15 08:11:11 -04:00
|
|
|
export UBSAN_OPTIONS=print_stacktrace=1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage:" 1>&2
|
2017-01-30 10:27:54 -05:00
|
|
|
echo " ${0##*/} (address|coverage|lib-coverage|app-coverage|egypt|memory|ncc|undefined)" 1>&2
|
2016-05-15 08:11:11 -04:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2017-08-23 10:03:19 -04:00
|
|
|
local CFLAGS="-std=c89 ${BASE_COMPILE_FLAGS} ${CFLAGS:-}"
|
2017-07-15 13:29:48 -04:00
|
|
|
local CXXFLAGS="-std=c++98 ${BASE_COMPILE_FLAGS} ${CXXFLAGS:-}"
|
2019-01-27 10:13:34 -05:00
|
|
|
local LDFLAGS="${BASE_LINK_FLAGS} ${LDFLAGS:-}"
|
2016-05-15 08:11:11 -04:00
|
|
|
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
|
2016-05-24 14:33:13 -04:00
|
|
|
RUN CC="${CC}" CFLAGS="${CFLAGS}" \
|
|
|
|
CXX="${CXX}" CXXFLAGS="${CXXFLAGS}" \
|
2016-05-24 14:34:07 -04:00
|
|
|
AR="${AR}" \
|
2019-01-27 10:13:34 -05:00
|
|
|
LD="${LD}" LDFLAGS="${LDFLAGS}" \
|
2016-05-24 14:33:13 -04:00
|
|
|
./configure "$@"
|
2016-05-15 08:11:11 -04:00
|
|
|
|
2017-12-03 11:18:30 -05:00
|
|
|
RUN "${MAKE}" \
|
|
|
|
CFLAGS="${CFLAGS} -Werror" \
|
|
|
|
CXXFLAGS="${CXXFLAGS} -Werror" \
|
|
|
|
clean all
|
2016-05-24 14:34:07 -04:00
|
|
|
|
|
|
|
case "${mode}" in
|
2016-05-30 14:29:33 -04:00
|
|
|
egypt|ncc)
|
2016-05-24 14:34:07 -04:00
|
|
|
;;
|
|
|
|
*)
|
2017-12-03 11:18:30 -05:00
|
|
|
RUN "${MAKE}" \
|
|
|
|
CFLAGS="${CFLAGS} -Werror" \
|
|
|
|
CXXFLAGS="${CXXFLAGS} -Werror" \
|
|
|
|
check run-xmltest
|
2016-05-24 14:34:07 -04:00
|
|
|
;;
|
|
|
|
esac
|
2016-06-06 16:47:50 -04:00
|
|
|
)
|
|
|
|
[[ $? -ne 0 ]] && exit 1
|
2016-05-15 08:11:11 -04:00
|
|
|
|
2016-05-24 14:33:13 -04:00
|
|
|
case "${mode}" in
|
|
|
|
coverage)
|
2016-05-15 08:11:11 -04:00
|
|
|
find -name '*.gcda' | sort | xargs gcov
|
2016-05-24 14:33:13 -04:00
|
|
|
;;
|
2017-01-30 10:27:54 -05:00
|
|
|
lib-coverage)
|
|
|
|
find lib -name '*.gcda' | sort | xargs gcov
|
|
|
|
;;
|
|
|
|
app-coverage)
|
|
|
|
find lib xmlwf -name '*.gcda' | sort | xargs gcov
|
|
|
|
;;
|
2016-05-30 14:29:33 -04:00
|
|
|
egypt)
|
|
|
|
local DOT_FORMAT="${DOT_FORMAT:-svg}"
|
2016-05-30 14:56:00 -04:00
|
|
|
local o="callgraph.${DOT_FORMAT}"
|
|
|
|
ANNOUNCE "egypt ...... | dot ...... > ${o}"
|
|
|
|
find -name '*.expand' \
|
|
|
|
| sort \
|
|
|
|
| xargs -r egypt \
|
|
|
|
| unflatten -c 20 \
|
|
|
|
| dot -T${DOT_FORMAT} -Grankdir=LR \
|
|
|
|
> "${o}"
|
2016-05-30 14:29:33 -04:00
|
|
|
;;
|
2016-05-24 14:34:07 -04:00
|
|
|
ncc)
|
|
|
|
RUN nccnav ./.libs/libexpat.a.nccout
|
|
|
|
;;
|
2016-05-24 14:33:13 -04:00
|
|
|
esac
|
2016-05-15 08:11:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|