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 # ----------------------------------------------------------------------------
9 # $FreeBSD: src/tools/tools/kerninclude/kerninclude.sh,v 1.1.2.1 2001/03/05 12:18:27 kris Exp $
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"
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"
74 if [ ! -f kernel ] ; then
75 echo "Error: No $i kernel built"
82 echo "Compiling modules"
87 # Generate the list of object files we want to check
88 # you can put a convenient grep right before the sort
89 # if you want just some specific subset of files checked
95 ( cd $i ; ls *.o 2>/dev/null || true)
101 ( cd $i ; ls *.o 2>/dev/null )
120 if [ ! -f compile/$k/$o ] ; then
124 if [ "x$src" = "x" ] ; then
129 src=compile/$k/`awk '$1 == "cc" {print $NF}' _`
131 if expr "x$src" : 'x.*\.c$' > /dev/null ; then
141 if [ ! -d $m -o ! -f $m/$o ] ; then
145 if [ "x$src" = "x" ] ; then
150 src=`awk '$1 == "cc" {print $NF}' _`
152 if expr "x$src" : 'x.*\.c$' > /dev/null ; then
153 if [ "`dirname $src`" = "." ] ; then
163 if [ "x$src" = "x" ] ; then
170 grep -n '^[ ]*#[ ]*include' $src | sed '
171 s/^\([0-9]*\):[ ]*#[ ]*include[ ]*[<"]/\1 /
174 ' | sort -rn | while read lin incl
177 echo " INCL $lin $incl"
180 # Check if we can compile without this #include line.
182 sed "${lin}s/.*//" ${src}_ > ${src}
187 if make ${o} > _log 2>&1 ; then
188 if cmp -s ${o} ${o}_ ; then
189 echo " $t same object"
191 echo " $t changed object"
200 if [ "x$S" != "x" ] ; then
204 if [ "x$S" != "x" ] ; then
209 # Check if this is because it is a nested #include
218 if make INCLMAGIC=-Ifoo ${o} > _log2 2>&1 ; then
219 if cmp -s ${o} ${o}_ ; then
220 echo " $t still same object"
222 echo " $t changed object"
226 echo " $t nested include"
232 if [ "x$S" != "x" ] ; then
236 if [ "x$S" != "x" ] ; then
241 # Check if this is because it is #ifdef'ed out
243 sed "${lin}s/.*/#error \"BARF\"/" ${src}_ > ${src}
248 if make ${o} > /dev/null 2>&1 ; then
249 echo " $t line not read"
254 if [ "x$S" != "x" ] ; then
260 if [ "x$S" != "x" ] ; then
264 # Check if the warnings changed.
270 if make ${o} > _ref 2>&1 ; then
271 if cmp -s _ref _log ; then
272 echo " $t same warnings"
274 echo " $t changed warnings"
284 if [ "x$S" != "x" ] ; then
288 if [ "x$S" != "x" ] ; then
292 sed "${lin}d" ${src}_ > ${src}
295 echo "BINGO $src $lin $incl $obj $l"