2 # ----------------------------------------------------------------------------
3 # "THE BEER-WARE LICENSE" (Revision 42):
4 # <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
5 # can do whatever you want with this stuff. If we meet some day, and you think
6 # this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 # ----------------------------------------------------------------------------
11 # This script tries to find #include statements which are not needed in
12 # the FreeBSD kernel tree.
17 # Base of the kernel sources you want to work on
20 # Set to true to start from scratch, false to resume
23 # Which kernels you want to check
24 kernels="LINT GENERIC"
31 echo "Cleaning modules"
33 make clean > /dev/null 2>&1
34 make cleandir > /dev/null 2>&1
35 make cleandir > /dev/null 2>&1
36 make clean > /dev/null 2>&1
37 make clean > /dev/null 2>&1
41 echo "Cleaning compile"
43 ls | grep -v CVS | xargs rm -rf
48 echo "Cleaning temp files"
49 find . -name '*.h_' -print | xargs rm -f
50 find . -name '::*' -print | xargs rm -f
51 find . -name '*.o' -size 0 -print | xargs rm -f
54 echo "Configuring kernels"
59 rm -rf ../../compile/LINT ../../compile/GENERIC
72 if [ ! -f kernel ] ; then
73 echo "Error: No $i kernel built"
80 echo "Compiling modules"
85 # Generate the list of object files we want to check
86 # you can put a convenient grep right before the sort
87 # if you want just some specific subset of files checked
92 if [ -d $i -a $i != CVS ] ; then
93 ( cd $i ; ls *.o 2>/dev/null || true)
99 ( cd $i ; ls *.o 2>/dev/null )
118 if [ ! -f compile/$k/$o ] ; then
122 if [ "x$src" = "x" ] ; then
127 src=compile/$k/`awk '$1 == "cc" {print $NF}' _`
129 if expr "x$src" : 'x.*\.c$' > /dev/null ; then
139 if [ ! -d $m -o ! -f $m/$o ] ; then
143 if [ "x$src" = "x" ] ; then
148 src=`awk '$1 == "cc" {print $NF}' _`
150 if expr "x$src" : 'x.*\.c$' > /dev/null ; then
151 if [ "`dirname $src`" = "." ] ; then
161 if [ "x$src" = "x" ] ; then
168 grep -n '^[ ]*#[ ]*include' $src | sed '
169 s/^\([0-9]*\):[ ]*#[ ]*include[ ]*[<"]/\1 /
172 ' | sort -rn | while read lin incl
175 echo " INCL $lin $incl"
178 # Check if we can compile without this #include line.
180 sed "${lin}s/.*//" ${src}_ > ${src}
185 if make ${o} > _log 2>&1 ; then
186 if cmp -s ${o} ${o}_ ; then
187 echo " $t same object"
189 echo " $t changed object"
198 if [ "x$S" != "x" ] ; then
202 if [ "x$S" != "x" ] ; then
207 # Check if this is because it is a nested #include
216 if make INCLMAGIC=-Ifoo ${o} > _log2 2>&1 ; then
217 if cmp -s ${o} ${o}_ ; then
218 echo " $t still same object"
220 echo " $t changed object"
224 echo " $t nested include"
230 if [ "x$S" != "x" ] ; then
234 if [ "x$S" != "x" ] ; then
239 # Check if this is because it is #ifdef'ed out
241 sed "${lin}s/.*/#error \"BARF\"/" ${src}_ > ${src}
246 if make ${o} > /dev/null 2>&1 ; then
247 echo " $t line not read"
252 if [ "x$S" != "x" ] ; then
258 if [ "x$S" != "x" ] ; then
262 # Check if the warnings changed.
268 if make ${o} > _ref 2>&1 ; then
269 if cmp -s _ref _log ; then
270 echo " $t same warnings"
272 echo " $t changed warnings"
282 if [ "x$S" != "x" ] ; then
286 if [ "x$S" != "x" ] ; then
290 sed "${lin}d" ${src}_ > ${src}
293 echo "BINGO $src $lin $incl $obj $l"