1#!/bin/bash
2
3DIR="${BASH_SOURCE%/*}"
4
5# 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
19source "$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"
27  echo "       $SCR <commit>...                 Check specific commit(s)"
28  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	*)
52		echo "Checking commit(s):"
53		for c in $*; do checkpatch $c; done
54		;;
55
56esac
57