contrib: filter compat lines

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld
2017-10-11 05:26:04 +02:00
parent f57c2d64bf
commit f6369780a8
2 changed files with 29 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
#!/bin/bash
silent=0
level=0
ifs=( )
while IFS= read -r line; do
if [[ $line =~ ^[[:space:]]*(#if.*) ]]; then
ifs[level++]=0
if [[ ${BASH_REMATCH[1]} == "#ifndef COMPAT_CANNOT_"* ]]; then
ifs[level-1]=-1
continue
elif [[ ${BASH_REMATCH[1]} == "#ifdef COMPAT_CANNOT_"* ]]; then
ifs[level-1]=1
((++silent))
continue
fi
elif [[ $line =~ ^[[:space:]]*#else && ${ifs[level-1]} -ne 0 ]]; then
((ifs[level-1]*=-1))
((silent+=ifs[level-1]))
continue
elif [[ $line =~ ^[[:space:]]*#endif ]]; then
((--level))
[[ ${ifs[level]} -eq 1 ]] && ((--silent))
[[ ${ifs[level]} -ne 0 ]] && continue
fi
[[ $silent -eq 0 ]] && printf '%s\n' "$line"
done < "$1"

View File

@@ -68,7 +68,7 @@ coccicheck: clean
@$(MAKE) -C $(KERNELDIR) M=$(PWD) CONFIG_WIREGUARD_DEBUG=y coccicheck MODE=report
cloc: clean
cloc $(wildcard *.c) $(wildcard *.h)
@cloc --skip-uniqueness --by-file --extract-with="$$(readlink -f ../contrib/kernel-tree/filter-compat-defines.sh) >FILE< > \$$(basename >FILE<)" $(wildcard *.c) $(wildcard *.h)
-include tests/debug.mk