Improved autogen.sh with options for static analysis.
@@ -23,25 +23,50 @@ set -e
CMAKE_OPTIONS=""
+COMMAND=""
+CORES=
+
while [ $# -gt 0 ] ; do
if [[ "$1" =~ ^(-|--)use-clang$ ]] ; then
# Use these settings for CLang:
export CXX=clang++
export CC=clang
+ elif [[ "$1" =~ ^(-|--)use-clang-scan-build$ ]] ; then
+ # Use these settings for CLang:
+ export CXX=clang++
+ export CC=clang
+ # Ensure build with CLang Static Analyzer
+ mkdir -p scan-build-reports
+ COMMAND="scan-build -o scan-build-reports"
elif [[ "$1" =~ ^(-|--)use-gcc$ ]] ; then
# Use these settings for GCC:
export CXX=g++
export CC=gcc
+ elif [[ "$1" =~ ^(-|--)use-gcc-analyzer$ ]] ; then
+ # Use these settings for GCC:
+ export CXX=g++-10
+ export CC=gcc-10
+ export CFLAGS=-fanalyzer
+ export CXXFLAGS=-fanalyzer
+ CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_VERBOSE_MAKEFILE=ON"
+ CORES=1 # The analyzer takes a *huge* amount of memory!
elif [[ "$1" =~ ^(-|--)debug$ ]] ; then
# Enable debugging build:
CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_BUILD_TYPE=DEBUG"
elif [[ "$1" =~ ^(-|--)verbose$ ]] ; then
# Enable verbose Makefile:
CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_VERBOSE_MAKEFILE=ON"
+ elif [[ "$1" =~ ^(-|--)cores ]] ; then
+ if [[ ! "$2" =~ ^[0-9]*$ ]] ; then
+ echo >&2 "ERROR: Number of cores must be an integer number!"
+ exit 1
+ fi
+ CORES="$2"
+ shift
elif [ "$1" == "--" ] ; then
break
else
- echo >&2 "Usage: autogen.sh [--use-clang|--use-gcc] [--debug] [--verbose]"
+ echo >&2 "Usage: autogen.sh [--use-clang|--use-clang-scan-build|--use-gcc|use-gcc-analyzer] [--debug] [--cores N] [--verbose]"
exit 1
fi
shift
@@ -51,19 +76,21 @@ done
# ====== Configure with CMake ===============================================
rm -f CMakeCache.txt
echo "CMake options:${CMAKE_OPTIONS} -DCMAKE_INSTALL_PREFIX=/usr $@ ."
-cmake ${CMAKE_OPTIONS} -DCMAKE_INSTALL_PREFIX=/usr $@ .
+${COMMAND} cmake ${CMAKE_OPTIONS} -DCMAKE_INSTALL_PREFIX=/usr $@ .
# ------ Obtain number of cores ---------------------------------------------
# Try Linux
-cores=`getconf _NPROCESSORS_ONLN 2>/dev/null || true`
-if [ "${cores}" == "" ] ; then
+if [ "${CORES}" == "" ] ; then
+ CORES=`getconf _NPROCESSORS_ONLN 2>/dev/null || true`
+ if [ "${CORES}" == "" ] ; then
# Try FreeBSD
- cores=`sysctl -a | grep 'hw.ncpu' | cut -d ':' -f2 | tr -d ' ' || true`
+ CORES=`sysctl -a | grep 'hw.ncpu' | cut -d ':' -f2 | tr -d ' ' || true`
+ fi
+ if [ "${CORES}" == "" ] ; then
+ CORES="1"
fi
-if [ "${cores}" == "" ] ; then
- cores="1"
+ echo "This system has ${CORES} cores!"
fi
-echo "This system has ${cores} cores!"
# ====== Build ==============================================================
-make -j${cores}
+${COMMAND} make -j${CORES}
