1*53ee8cc1Swenshuai.xi#!/bin/sh 2*53ee8cc1Swenshuai.xi# Find Kconfig variables used in source code but never defined in Kconfig 3*53ee8cc1Swenshuai.xi# Copyright (C) 2007, Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> 4*53ee8cc1Swenshuai.xi 5*53ee8cc1Swenshuai.xi# Tested with dash. 6*53ee8cc1Swenshuai.xipaths="$@" 7*53ee8cc1Swenshuai.xi[ -z "$paths" ] && paths=. 8*53ee8cc1Swenshuai.xi 9*53ee8cc1Swenshuai.xi# Doing this once at the beginning saves a lot of time, on a cache-hot tree. 10*53ee8cc1Swenshuai.xiKconfigs="`find . -name 'Kconfig' -o -name 'Kconfig*[^~]'`" 11*53ee8cc1Swenshuai.xi 12*53ee8cc1Swenshuai.xi/bin/echo -e "File list \tundefined symbol used" 13*53ee8cc1Swenshuai.xifind $paths -name '*.[chS]' -o -name 'Makefile' -o -name 'Makefile*[^~]'| while read i 14*53ee8cc1Swenshuai.xido 15*53ee8cc1Swenshuai.xi # Output the bare Kconfig variable and the filename; the _MODULE part at 16*53ee8cc1Swenshuai.xi # the end is not removed here (would need perl an not-hungry regexp for that). 17*53ee8cc1Swenshuai.xi sed -ne 's!^.*\<\(UML_\)\?CONFIG_\([0-9A-Za-z_]\+\).*!\2 '$i'!p' < $i 18*53ee8cc1Swenshuai.xidone | \ 19*53ee8cc1Swenshuai.xi# Smart "sort|uniq" implemented in awk and tuned to collect the names of all 20*53ee8cc1Swenshuai.xi# files which use a given symbol 21*53ee8cc1Swenshuai.xiawk '{map[$1, count[$1]++] = $2; } 22*53ee8cc1Swenshuai.xiEND { 23*53ee8cc1Swenshuai.xi for (combIdx in map) { 24*53ee8cc1Swenshuai.xi split(combIdx, separate, SUBSEP); 25*53ee8cc1Swenshuai.xi # The value may have been removed. 26*53ee8cc1Swenshuai.xi if (! ( (separate[1], separate[2]) in map ) ) 27*53ee8cc1Swenshuai.xi continue; 28*53ee8cc1Swenshuai.xi symb=separate[1]; 29*53ee8cc1Swenshuai.xi printf "%s ", symb; 30*53ee8cc1Swenshuai.xi #Use gawk extension to delete the names vector 31*53ee8cc1Swenshuai.xi delete names; 32*53ee8cc1Swenshuai.xi #Portably delete the names vector 33*53ee8cc1Swenshuai.xi #split("", names); 34*53ee8cc1Swenshuai.xi for (i=0; i < count[symb]; i++) { 35*53ee8cc1Swenshuai.xi names[map[symb, i]] = 1; 36*53ee8cc1Swenshuai.xi # Unfortunately, we may still encounter symb, i in the 37*53ee8cc1Swenshuai.xi # outside iteration. 38*53ee8cc1Swenshuai.xi delete map[symb, i]; 39*53ee8cc1Swenshuai.xi } 40*53ee8cc1Swenshuai.xi i=0; 41*53ee8cc1Swenshuai.xi for (name in names) { 42*53ee8cc1Swenshuai.xi if (i > 0) 43*53ee8cc1Swenshuai.xi printf ", %s", name; 44*53ee8cc1Swenshuai.xi else 45*53ee8cc1Swenshuai.xi printf "%s", name; 46*53ee8cc1Swenshuai.xi i++; 47*53ee8cc1Swenshuai.xi } 48*53ee8cc1Swenshuai.xi printf "\n"; 49*53ee8cc1Swenshuai.xi } 50*53ee8cc1Swenshuai.xi}' | 51*53ee8cc1Swenshuai.xiwhile read symb files; do 52*53ee8cc1Swenshuai.xi # Remove the _MODULE suffix when checking the variable name. This should 53*53ee8cc1Swenshuai.xi # be done only on tristate symbols, actually, but Kconfig parsing is 54*53ee8cc1Swenshuai.xi # beyond the purpose of this script. 55*53ee8cc1Swenshuai.xi symb_bare=`echo $symb | sed -e 's/_MODULE//'` 56*53ee8cc1Swenshuai.xi if ! grep -q "\<$symb_bare\>" $Kconfigs; then 57*53ee8cc1Swenshuai.xi /bin/echo -e "$files: \t$symb" 58*53ee8cc1Swenshuai.xi fi 59*53ee8cc1Swenshuai.xidone|sort 60