This script wraps cppcheck and supplies common parameters, as well as pre-defined compiler definitions.
Usage
cppcheck.sh [parameters] [file]
Notes
This script is normally invoked through the cc_driver.pl script, which supplies definitions from the file’s entry in the compilation database (-I and -D parameters).
The script generates a file containing the compiler’s pre-defined macro definitions, which is input to cppcheck using cppcheck’s --include= flag.
#!/bin/bash## helper script for cppcheck that defines a number of common parameters# (also generates and includes compiler pre-defined macros)## Copyright 2016 by Bill Torpey. All Rights Reserved.# This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 United States License.# http://creativecommons.org/licenses/by-nc-nd/3.0/us/deed.en## its a very good idea to include compiler builtin definitionsTEMPFILE=$(mktemp)cpp -dM </dev/null 2>/dev/null >${TEMPFILE}SCRIPT_DIR=$(cd$(dirname ${BASH_SOURCE})&& /bin/pwd)# if CPPCHECK_OPTS is empty, try using .cppcheckrc from different locationsSCRIPT_DIR=$(cd$(dirname ${BASH_SOURCE})&& /bin/pwd)if[[ -z "${CPPCHECK_OPTS}"]]; then# current dirif[[ -e ./.cppcheckrc ]]; thenexport CPPCHECK_OPTS=$(<./.cppcheckrc)# SRC_ROOTelif[[ -z ${SRC_ROOT}&& -e ${SRC_ROOT}/.cppcheckrc ]]; thenexport CPPCHECK_OPTS=$(<${SRC_ROOT}/.cppcheckrc)# home direlif[[ -e ~/.cppcheckrc ]]; thenexport CPPCHECK_OPTS=$(<~/.cppcheckrc)# script direlif[[ -e ${SCRIPT_DIR}/.cppcheckrc ]]; thenexport CPPCHECK_OPTS=$(<${SCRIPT_DIR}/.cppcheckrc)fifi# uncomment the following line if you need to override LD_LIBRARY_PATH for cppcheck# note that you must also supply the required path in place of "<>"#LD_LIBRARY_PATH=<>:$LD_LIBRARY_PATH \cppcheck --include=${TEMPFILE}\${CPPCHECK_OPTS}$*[[ -f ${TEMPFILE}]]&& rm -f ${TEMPFILE} 2>&1 >/dev/null