[RFC] duplicate #include check for build system

From: Herbert Poetzl
Date: Mon Feb 20 2006 - 20:48:54 EST



Hi Sam! Folks!

recently had the idea to utilize cpp or sparse to
do some automated #include checking, and I came up
with the following proof of concept:

I just replaced the sparse binary by the following
script (basically hijacking the make C=1 system)

it would allow kernel developers to easily identify
duplicate includes, which in turn, might reduce
dependancies and thus build time ...


----------------
#!/bin/bash

while [ $# -gt 1 ]; do
case $1 in
-D*) DEF="$DEF $1";;
-W*) ;;
*) OPT="$OPT $1";;
esac
shift
done

# ( $CPP $DEF -H -dI $OPT $1 1>&2 ) 2>&1 | grep "^[#.]"
$CPP $DEF -H $OPT $1 2>&1 >/dev/null | gawk -vFILE="$1" '

BEGIN { I[0]=FILE; }

/^[.]+/ { D=length($1);

for (i=0; i<D; i++)
C[i,$2]++;

I[D]=$2;

for (i=0; i<D; i++)
M[i,$2]=I[i];

if (C[D-1,$2]>1) {
printf "··· %s in %s ",$2,I[D-1];

for (i=D; M[i,$2]; i++)
printf "%c%s", (i==D)?"[":"·", M[i,$2];

printf (i>D) ? "]\n" :
((X[D,$2]==I[D-1]) ? "(dup)\n" : "\n");
}

X[D,$2]=I[D-1];
}
' 1>&2

true
----------------

of course, most of it would not be required if
there was support in the kernel build system,
and, if there is any preference for perl over
bash/gawk it could be easily rewritten ...

please let me know what you think of this and if
you could imagine adding something similar to the
build system

TIA,
Herbert

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/