blob: 75524b8ec6978f908924c85b1f50192d6333ed0d [file] [log] [blame]
Igor Opaniuk1c93c2b2016-11-03 13:27:28 +02001#!/bin/bash
2
3DIR="${BASH_SOURCE%/*}"
4
Markus S. Wamser33977c02018-10-17 16:30:06 +02005# if no CHECKPATCH is explicitly given by the environment, try to
6# locate checkpatch.pl: first take the one from the path, then check
7# for a local copy of the linux headers, finally try sources downloaded
8# with OP-TEE (for QEMU)
9if [ -z "$CHECKPATCH" ]; then
10 CHECKPATCH=$(command -v checkpatch.pl)
11fi
12if [ -z "$CHECKPATCH" ]; then
13 CHECKPATCH=$(find /usr/src/linux-headers* -name checkpatch.pl -print -quit)
14fi
15if [ -z "$CHECKPATCH" ]; then
16 CHECKPATCH=$(find "$PWD/../linux" -name checkpatch.pl -print -quit)
17fi
18
Igor Opaniuk1c93c2b2016-11-03 13:27:28 +020019source "$DIR/checkpatch_inc.sh"
20
21hash $CHECKPATCH 2>/dev/null ||
22 { echo >&2 "Could not find checkpatch.pl, aborting"; exit 1; }
23
24usage() {
25 SCR=$(basename "$0")
26 echo "Usage: $SCR [--working] Check working area"
Jerome Forissier849b17b2017-02-22 18:11:36 +010027 echo " $SCR <commit>... Check specific commit(s)"
Igor Opaniuk1c93c2b2016-11-03 13:27:28 +020028 echo " $SCR --diff <commit1> <commit2> Check diff commit1...commit2"
29 echo " $SCR --cached Check staging area"
30 echo " $SCR --help This help"
31 exit 1
32}
33
34op=${1:---working}
35case "$op" in
36 --cached)
37 echo "Checking staging area: "
38 checkstaging
39 ;;
40 --diff)
41 echo "Checking diff (diff $1...$2)"
42 checkdiff "$2" "$3"
43 ;;
44 --working)
45 echo "Checking working area: "
46 checkworking
47 ;;
48 --help|-h)
49 usage
50 ;;
51 *)
Jerome Forissier849b17b2017-02-22 18:11:36 +010052 echo "Checking commit(s):"
53 for c in $*; do checkpatch $c; done
Igor Opaniuk1c93c2b2016-11-03 13:27:28 +020054 ;;
55
56esac