cppcheck.sh 892 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bash
  2. # echo >>/tmp/cppcheck.log "cppcheck ${*}"
  3. # shellcheck disable=SC2230
  4. cppcheck=$(which cppcheck 2>/dev/null || command -v cppcheck 2>/dev/null)
  5. [ -z "${cppcheck}" ] && echo >&2 "install cppcheck." && exit 1
  6. processors=$(grep -c ^processor /proc/cpuinfo)
  7. [ $(( processors )) -lt 1 ] && processors=1
  8. base="$(dirname "${0}")"
  9. [ "${base}" = "." ] && base="${PWD}"
  10. cd "${base}" || exit 1
  11. [ ! -d "cppcheck-build" ] && mkdir "cppcheck-build"
  12. file="${1}"
  13. shift
  14. # shellcheck disable=SC2235
  15. ([ "${file}" = "${base}" ] || [ -z "${file}" ]) && file="${base}"
  16. "${cppcheck}" \
  17. -j ${processors} \
  18. --cppcheck-build-dir="cppcheck-build" \
  19. -I .. \
  20. --force \
  21. --enable=warning,performance,portability,information \
  22. --library=gnu \
  23. --library=posix \
  24. --suppress="unusedFunction:*" \
  25. --suppress="nullPointerRedundantCheck:*" \
  26. --suppress="readdirCalled:*" \
  27. "${file}" "${@}"