summaryrefslogtreecommitdiffstats
path: root/tools/style.sh
blob: 08e40b173276988847e42093bf928c46df66c948 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
# Read-only style check: no tabs, no trailing whitespace, nothing past 80
# columns, and every .S file must declare a non-executable stack.

set -eu

here=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
status=0

for file in "$here"/src/*.S "$here"/src/*.inc "$here"/include/*.h \
            "$here"/tests/*.c "$here"/examples/*.c; do
    [ -e "$file" ] || continue
    name=${file#"$here"/}
    if grep -n '	' "$file" >/dev/null 2>&1; then
        echo "$name: contains a tab" >&2
        grep -n '	' "$file" | head -5 >&2
        status=1
    fi
    if grep -n '[ 	]$' "$file" >/dev/null 2>&1; then
        echo "$name: trailing whitespace" >&2
        grep -n '[ 	]$' "$file" | head -5 >&2
        status=1
    fi
    if awk 'length > 80 { print FILENAME ":" FNR ": line over 80 columns"; f=1 }
            END { exit f ? 1 : 0 }' "$file" >&2; then
        :
    else
        status=1
    fi
done

for file in "$here"/src/*.S; do
    name=${file#"$here"/}
    if ! grep -q 'note.GNU-stack' "$file"; then
        echo "$name: missing .note.GNU-stack" >&2
        status=1
    fi
done

if [ "$status" -eq 0 ]; then
    echo "style: ok"
fi
exit "$status"