Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 145 lines (131 sloc) 4.28 KB
#!/usr/bin/env bash
#
# Copyright 2017-2018 AVSystem <avsystem@avsystem.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
rm -rf avs_commons/install
rm -rf avs_commons/git/CMakeFiles
rm -f avs_commons/git/CMakeCache.txt
if [[ -d '.git' ]]; then
echo "Updating submodules" && git submodule update --init --recursive || exit 1
fi
C_FLAGS='-g -std=c99'
EXTRA_C_FLAGS=
EXTRA_FLAGS=()
MODULE_DYNAMIC_LIBS='ON'
MODULE_STATIC_LIBS='ON'
ANJAY_VERSION=$(git rev-parse --short HEAD)
DTLS_BACKEND="mbedtls"
WITH_STATIC_ANALYSIS='ON'
if valgrind --version >/dev/null 2>/dev/null; then
WITH_VALGRIND=ON
WITH_ASAN=OFF
else
WITH_VALGRIND=OFF
WITH_ASAN=ON
fi
if [[ "$ANJAY_VERSION" == "" ]]; then
ANJAY_VERSION="unknown"
fi
if ! which afl-gcc &>/dev/null; then
if [[ -d "$HOME/tools/afl/latest" ]]; then
AFL_FUZZER_DIR="$HOME/tools/afl/latest"
fi
fi
# in case both CMake 2 and 3 is available, prefer newer
CMAKE_COMMAND=cmake
which cmake3 &>/dev/null && CMAKE_COMMAND=cmake3
# argument parsing
while [ $# -gt 0 ]; do
case "$1" in
'--c-flags')
shift
C_FLAGS="$1"
;;
'--fuzz-tests')
EXTRA_FLAGS[${#EXTRA_FLAGS[@]}]="-DCMAKE_TOOLCHAIN_FILE=$SCRIPT_DIR/cmake/toolchain/afl-gcc.cmake"
EXTRA_FLAGS[${#EXTRA_FLAGS[@]}]="-DWITH_FUZZ_TESTS=ON"
[[ "$AFL_FUZZER_DIR" ]] && EXTRA_FLAGS[${#EXTRA_FLAGS[@]}]="-DAFL_FUZZER_DIR=$AFL_FUZZER_DIR"
;;
'--with-mbedtls')
DTLS_BACKEND="mbedtls"
;;
'--with-openssl')
DTLS_BACKEND="openssl"
;;
'--with-tinydtls')
DTLS_BACKEND="tinydtls"
;;
'--without-dtls')
DTLS_BACKEND=
;;
'--with-valgrind')
WITH_ASAN=OFF
WITH_VALGRIND=ON
;;
'--with-asan')
WITH_VALGRIND=OFF
WITH_ASAN=ON
;;
'--without-memcheck')
WITH_ASAN=OFF
WITH_VALGRIND=OFF
;;
'--without-analysis')
WITH_STATIC_ANALYSIS=OFF
;;
'--tiny')
EXTRA_FLAGS[${#EXTRA_FLAGS[@]}]="-DMAX_PK_OR_IDENTITY_SIZE=256"
EXTRA_FLAGS[${#EXTRA_FLAGS[@]}]="-DMAX_SERVER_PK_OR_IDENTITY_SIZE=256"
EXTRA_FLAGS[${#EXTRA_FLAGS[@]}]="-DMAX_SECRET_KEY_SIZE=128"
EXTRA_FLAGS[${#EXTRA_FLAGS[@]}]="-DMAX_OBSERVABLE_RESOURCE_SIZE=256"
EXTRA_FLAGS[${#EXTRA_FLAGS[@]}]="-DMAX_FLOAT_STRING_SIZE=64"
EXTRA_FLAGS[${#EXTRA_FLAGS[@]}]="-DMAX_DOUBLE_STRING_SIZE=64"
EXTRA_FLAGS[${#EXTRA_FLAGS[@]}]="-DMAX_URI_SEGMENT_SIZE=64"
EXTRA_FLAGS[${#EXTRA_FLAGS[@]}]="-DMAX_URI_QUERY_SEGMENT_SIZE=64"
;;
*)
EXTRA_FLAGS[${#EXTRA_FLAGS[@]}]="$1"
;;
esac
shift
done
if [ "$WITH_ASAN" == "ON" ]; then
EXTRA_C_FLAGS="${EXTRA_C_FLAGS} -fsanitize=address"
fi
# use Homebrew-installed OpenSSL on macOS if available
if brew ls --versions openssl >/dev/null 2>/dev/null; then
EXTRA_FLAGS[${#EXTRA_FLAGS[@]}]="-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl"
fi
rm -f CMakeCache.txt
rm -rf CMakeFiles
${CMAKE_COMMAND} \
-D WITH_TEST=ON \
-D WITH_LICENSE_TEST=ON \
-D WITH_DEMO=ON \
-D WITH_EXTRA_WARNINGS=ON \
-D WITH_CON_ATTR=ON \
-D WITH_HTTP_DOWNLOAD=ON \
-D WITH_VALGRIND=${WITH_VALGRIND} \
-D WITH_INTEGRATION_TESTS=ON \
-D WITH_DOC_CHECK=ON \
-D WITH_STATIC_ANALYSIS=${WITH_STATIC_ANALYSIS} \
-D DTLS_BACKEND="${DTLS_BACKEND}" \
-D AVS_LOG_WITH_TRACE=ON \
-D CMAKE_C_FLAGS="${C_FLAGS} ${EXTRA_C_FLAGS}" \
-D CMAKE_CXX_FLAGS="${EXTRA_C_FLAGS}" \
-D ANJAY_VERSION="${ANJAY_VERSION}" \
"${EXTRA_FLAGS[@]}" \
"$@" -H"$(dirname "$0")" -B. &&
make clean