cppcheck.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #! /bin/sh
  2. # usage:
  3. #
  4. # make \
  5. # REAL_CC=gcc-mine \
  6. # CC=extra/scripts/cppcheck.sh \
  7. # CPPCHECK_FLAGS="--enable=style,performance,portability,information,missingInclude --max-configs=256 -j $(($(getconf _NPROCESSORS_ONLN)-1))" \
  8. # CPPCHECK_LIMIT="yes"
  9. # CPPCHECK_FLAGS are optional and are not set per default.
  10. # CPPCHECK_LIMIT limits cppcheck to the -D and -U that would be passed to CC.
  11. # Setting CPPCHECK_LIMIT greatly improves the check-time but obviously
  12. # just checks a small subset of the defines found in a file.
  13. : ${REAL_CC:=gcc}
  14. ${REAL_CC} $@
  15. args=""
  16. limits=""
  17. next_arg=0
  18. next_limit=0
  19. for i in $@
  20. do
  21. if [ $next_arg -eq 1 ] ; then
  22. next_arg=0
  23. case "/$i" in
  24. /-*) exit 0 ;;
  25. esac
  26. [ "x$args" = "x" ] && args="$i" || args="$args $i"
  27. continue
  28. fi
  29. if [ $next_limit -eq 1 ] ; then
  30. next_limit=0
  31. [ "x$limits" = "x" ] && limits="$i" || limits="$limits $i"
  32. continue
  33. fi
  34. case "/$i" in
  35. /-c) next_arg=1 ;;
  36. /-isystem)
  37. next_arg=1;
  38. [ "x$args" = "x" ] && args="-I" || args="$args -I" ;;
  39. /-I)
  40. next_arg=1;
  41. [ "x$args" = "x" ] && args="$i" || args="$args $i" ;;
  42. /-I*) [ "x$args" = "x" ] && args="$i" || args="$args $i" ;;
  43. /-D|/-U)
  44. next_limit=1;
  45. [ "x$limit" = "x" ] && limit="$i" || limit="$limit $i" ;;
  46. /-D*) [ "x$limits" = "x" ] && limits="$i" || limits="$limits $i" ;;
  47. /-s|/-S|/-dump*|/--print*|/-print*) exit 0 ;;
  48. *) ;;
  49. esac
  50. done
  51. [ -z "${CPPCHECK_LIMIT}" ] && limits=""
  52. [ -z "${args}" ] || exec cppcheck ${CPPCHECK_FLAGS} ${args} ${limits}