#!/bin/sh

ret=0
for spatch in cocci/*.spatch; do
    patch="$(dirname "$spatch")/$(basename "$spatch" .spatch).patch"
    : > "$patch"
    for dir in bin lib fuzz; do
	spatch --sp-file="$spatch" --use-gitgrep --dir "$dir" --very-quiet --include-headers >> "$patch";
    done
    if [ "$(< "$patch" wc -l)" -gt "0" ]; then
	cat "$patch"
	ret=1
    else
	rm "$patch"
    fi
done

exit $ret
