summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2012-01-27 12:46:14 +0100
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2012-01-27 13:12:40 +0100
commit7f02033e13b1633d83403664749c1daf0ab98840 (patch)
tree61f647c876a587871895617983b51244eb61baa6
parentb80b28ee6fdf073e6baf9b893b3ecef9904a2e48 (diff)
buildsys: add cppcheck wrapper script (correct one)
Also incooperate vapier's suggestion on how to set REAL_CC once Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
-rwxr-xr-xextra/scripts/cppcheck.sh53
1 files changed, 43 insertions, 10 deletions
diff --git a/extra/scripts/cppcheck.sh b/extra/scripts/cppcheck.sh
index 7484e09bf..127c5096d 100755
--- a/extra/scripts/cppcheck.sh
+++ b/extra/scripts/cppcheck.sh
@@ -1,23 +1,56 @@
#! /bin/sh
-${REAL_CC-gcc} $*
+# usage:
+#
+# make \
+# REAL_CC=gcc-mine \
+# CC=extra/scripts/cppcheck.sh \
+# CPPCHECK_FLAGS="--enable=style,performance,portability,information,missingInclude --max-configs=256 -j $(($(getconf _NPROCESSORS_ONLN)-1))" \
+# CPPCHECK_LIMIT="yes"
+# CPPCHECK_FLAGS are optional and are not set per default.
+# CPPCHECK_LIMIT limits cppcheck to the -D and -U that would be passed to CC.
+# Setting CPPCHECK_LIMIT greatly improves the check-time but obviously
+# just checks a small subset of the defines found in a file.
+
+: ${REAL_CC:=gcc}
+${REAL_CC} $@
args=""
-add_next=0
+limits=""
+next_arg=0
+next_limit=0
-for i in $*
+for i in $@
do
- if [ $add_next -eq 1 ] ; then
+ if [ $next_arg -eq 1 ] ; then
+ next_arg=0
+ case "/$i" in
+ /-*) exit 0 ;;
+ esac
[ "x$args" = "x" ] && args="$i" || args="$args $i"
- add_next=0
+ continue
+ fi
+ if [ $next_limit -eq 1 ] ; then
+ next_limit=0
+ [ "x$limits" = "x" ] && limits="$i" || limits="$limits $i"
continue
fi
case "/$i" in
- /-c) add_next=1 ;;
- /-D*|/-I*|/-inc) [ "x$args" = "x" ] && args="$i" || args="$args $i" ;;
- /-dumpversion|/--print*) ${CC-gcc} $i ; exit 0 ;;
+ /-c) next_arg=1 ;;
+ /-isystem)
+ next_arg=1;
+ [ "x$args" = "x" ] && args="-I" || args="$args -I" ;;
+ /-I)
+ next_arg=1;
+ [ "x$args" = "x" ] && args="$i" || args="$args $i" ;;
+ /-I*) [ "x$args" = "x" ] && args="$i" || args="$args $i" ;;
+ /-D|/-U)
+ next_limit=1;
+ [ "x$limit" = "x" ] && limit="$i" || limit="$limit $i" ;;
+ /-D*) [ "x$limits" = "x" ] && limits="$i" || limits="$limits $i" ;;
+ /-s|/-S|/-dump*|/--print*|/-print*) exit 0 ;;
*) ;;
esac
done
-
-cppcheck $args
+[ -z "${CPPCHECK_LIMIT}" ] && limits=""
+[ -z "${args}" ] || exec cppcheck ${CPPCHECK_FLAGS} ${args} ${limits}