#!/bin/sh
#dir_name=bulk-scan-`date "+%Y-%m-%d-%H.%M.%S"`
dir_name=/tmp/bulk-scan
mkdir ${dir_name}

doas rm -rf /usr/obj/*
cd /usr/src
make obj

for x in /usr/src/bin/!(CVS|Makefile*) \
	/usr/src/sbin/!(CVS|Makefile*) \
	/usr/src/usr.bin/!(CVS|Makefile*) \
	/usr/src/usr.sbin/!(CVS|Makefile*)
do
	cd $x
	if [[ $? -ne 0 ]]; then
		continue
	fi
	path=`echo $x | awk '{ print substr($0, 9) }'`
	make clean
	mkdir -p ${dir_name}${path}
	scan-build -disable-checker deadcode.DeadStores \
		   -disable-checker core.NullDereference \
		   -disable-checker unix.API \
		   -disable-checker security.insecureAPI.mktemp \
		   -o ${dir_name}${path} make -j2
done

find $dir_name -empty -type d | xargs rmdir
