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 # ----------------------------------------------------------------------------
10 # This script tries to find #include statements which are not needed in
11 # the FreeBSD kernel tree.
16 # Base of the kernel sources you want to work on
19 # Set to true to start from scratch, false to resume
22 # Which kernels you want to check
23 kernels="LINT GENERIC"
30 echo "Cleaning modules"
32 make clean > /dev/null 2>&1
33 make cleandir > /dev/null 2>&1
34 make cleandir > /dev/null 2>&1
35 make clean > /dev/null 2>&1
36 make clean > /dev/null 2>&1
40 echo "Cleaning compile"
42 ls | grep -v CVS | xargs rm -rf
47 echo "Cleaning temp files"
48 find . -name '*.h_' -print | xargs rm -f
49 find . -name '::*' -print | xargs rm -f
50 find . -name '*.o' -size 0 -print | xargs rm -f
53 echo "Configuring kernels"
58 rm -rf ../../compile/LINT ../../compile/GENERIC
71 if [ ! -f kernel ] ; then
72 echo "Error: No $i kernel built"
79 echo "Compiling modules"
84 # Generate the list of object files we want to check
85 # you can put a convenient grep right before the sort
86 # if you want just some specific subset of files checked
91 if [ -d $i -a $i != CVS ] ; then
92 ( cd $i ; ls *.o 2>/dev/null || true)
98 ( cd $i ; ls *.o 2>/dev/null )
117 if [ ! -f compile/$k/$o ] ; then
121 if [ "x$src" = "x" ] ; then
126 src=compile/$k/`awk '$1 == "cc" {print $NF}' _`
128 if expr "x$src" : 'x.*\.c$' > /dev/null ; then
138 if [ ! -d $m -o ! -f $m/$o ] ; then
142 if [ "x$src" = "x" ] ; then
147 src=`awk '$1 == "cc" {print $NF}' _`
149 if expr "x$src" : 'x.*\.c$' > /dev/null ; then
150 if [ "`dirname $src`" = "." ] ; then
160 if [ "x$src" = "x" ] ; then
167 grep -n '^[ ]*#[ ]*include' $src | sed '
168 s/^\([0-9]*\):[ ]*#[ ]*include[ ]*[<"]/\1 /
171 ' | sort -rn | while read lin incl
174 echo " INCL $lin $incl"
177 # Check if we can compile without this #include line.
179 sed "${lin}s/.*//" ${src}_ > ${src}
184 if make ${o} > _log 2>&1 ; then
185 if cmp -s ${o} ${o}_ ; then
186 echo " $t same object"
188 echo " $t changed object"
197 if [ "x$S" != "x" ] ; then
201 if [ "x$S" != "x" ] ; then
206 # Check if this is because it is a nested #include
215 if make INCLMAGIC=-Ifoo ${o} > _log2 2>&1 ; then
216 if cmp -s ${o} ${o}_ ; then
217 echo " $t still same object"
219 echo " $t changed object"
223 echo " $t nested include"
229 if [ "x$S" != "x" ] ; then
233 if [ "x$S" != "x" ] ; then
238 # Check if this is because it is #ifdef'ed out
240 sed "${lin}s/.*/#error \"BARF\"/" ${src}_ > ${src}
245 if make ${o} > /dev/null 2>&1 ; then
246 echo " $t line not read"
251 if [ "x$S" != "x" ] ; then
257 if [ "x$S" != "x" ] ; then
261 # Check if the warnings changed.
267 if make ${o} > _ref 2>&1 ; then
268 if cmp -s _ref _log ; then
269 echo " $t same warnings"
271 echo " $t changed warnings"
281 if [ "x$S" != "x" ] ; then
285 if [ "x$S" != "x" ] ; then
289 sed "${lin}d" ${src}_ > ${src}
292 echo "BINGO $src $lin $incl $obj $l"