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 GENERIC98"
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"
68 cp -f GENERIC GENERIC98
83 if [ ! -f kernel ] ; then
84 echo "Error: No $i kernel built"
91 echo "Compiling modules"
96 # Generate the list of object files we want to check
97 # you can put a convenient grep right before the sort
98 # if you want just some specific subset of files checked
103 if [ -d $i -a $i != CVS ] ; then
104 ( cd $i ; ls *.o 2>/dev/null || true)
110 ( cd $i ; ls *.o 2>/dev/null )
129 if [ ! -f compile/$k/$o ] ; then
133 if [ "x$src" = "x" ] ; then
138 src=compile/$k/`awk '$1 == "cc" {print $NF}' _`
140 if expr "x$src" : 'x.*\.c$' > /dev/null ; then
150 if [ ! -d $m -o ! -f $m/$o ] ; then
154 if [ "x$src" = "x" ] ; then
159 src=`awk '$1 == "cc" {print $NF}' _`
161 if expr "x$src" : 'x.*\.c$' > /dev/null ; then
162 if [ "`dirname $src`" = "." ] ; then
172 if [ "x$src" = "x" ] ; then
179 grep -n '^[ ]*#[ ]*include' $src | sed '
180 s/^\([0-9]*\):[ ]*#[ ]*include[ ]*[<"]/\1 /
183 ' | sort -rn | while read lin incl
186 echo " INCL $lin $incl"
189 # Check if we can compile without this #include line.
191 sed "${lin}s/.*//" ${src}_ > ${src}
196 if make ${o} > _log 2>&1 ; then
197 if cmp -s ${o} ${o}_ ; then
198 echo " $t same object"
200 echo " $t changed object"
209 if [ "x$S" != "x" ] ; then
213 if [ "x$S" != "x" ] ; then
218 # Check if this is because it is a nested #include
227 if make INCLMAGIC=-Ifoo ${o} > _log2 2>&1 ; then
228 if cmp -s ${o} ${o}_ ; then
229 echo " $t still same object"
231 echo " $t changed object"
235 echo " $t nested include"
241 if [ "x$S" != "x" ] ; then
245 if [ "x$S" != "x" ] ; then
250 # Check if this is because it is #ifdef'ed out
252 sed "${lin}s/.*/#error \"BARF\"/" ${src}_ > ${src}
257 if make ${o} > /dev/null 2>&1 ; then
258 echo " $t line not read"
263 if [ "x$S" != "x" ] ; then
269 if [ "x$S" != "x" ] ; then
273 # Check if the warnings changed.
279 if make ${o} > _ref 2>&1 ; then
280 if cmp -s _ref _log ; then
281 echo " $t same warnings"
283 echo " $t changed warnings"
293 if [ "x$S" != "x" ] ; then
297 if [ "x$S" != "x" ] ; then
301 sed "${lin}d" ${src}_ > ${src}
304 echo "BINGO $src $lin $incl $obj $l"