checkkconfigsymbols.sh 1.8 KB

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