check_unused_headers 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. #
  3. # Name: check_unused_headers
  4. # Purpose: checks all wxWidgets headers looking for headers not referenced anywhere
  5. # Usage: run with --verbose for verbose output
  6. # Copyright: (c) 2007 Francesco Montorsi
  7. # Licence: wxWindows licence
  8. ################################################################################
  9. if [[ "$1" = "-v" || "$1" = "--verbose" ]]; then
  10. verbose=yes
  11. else
  12. verbose=no
  13. fi
  14. me=$(basename $0)
  15. path=${0%%/$me} # path from which the script has been launched
  16. current=$(pwd)
  17. # the path where this script resides:
  18. scriptPath=$current/$path
  19. # other interesting wx paths
  20. headerPath="$scriptPath/../../include"
  21. srcPath="$scriptPath/../../src"
  22. # get list of wx source and header filenames
  23. # NOTE: these list won't contain the .svn backup copies of the real sources/headers
  24. # NOTE2: we keep the size of these lists small avoiding to include the prefixes
  25. # like e.g. ../../include so to not incurr in OS limits when passing
  26. # them as arguments of commands
  27. cd $headerPath
  28. headerList=`find wx -name "*.h"`
  29. cd $srcPath
  30. srcList=`find . -name "*.cpp"`
  31. unusedHeaders=0
  32. function checkIfHeaderIsUsed
  33. {
  34. local headerToCheck="$1"
  35. local found=no
  36. if [[ $verbose = yes ]]; then
  37. echo -n "checking if header: $headerToCheck is used... "
  38. fi
  39. # find the first occurrence of this header in wx sources and headers:
  40. cd $headerPath
  41. grep -m 1 "$headerToCheck" $headerList >/dev/null 2>&1
  42. if [[ $? = 0 ]]; then found=yes; fi
  43. cd $srcPath
  44. grep -m 1 "$headerToCheck" $srcList >/dev/null 2>&1
  45. if [[ $? = 0 ]]; then found=yes; fi
  46. if [[ $found = no ]]; then
  47. if [[ $verbose = yes ]]; then
  48. echo "no, it's not!"
  49. fi
  50. # this header is not used anywhere...
  51. echo "WARNING: unused header $headerToCheck"
  52. ((( unusedHeaders++ )))
  53. else
  54. if [[ $verbose = yes ]]; then
  55. echo "yes, it is"
  56. fi
  57. fi
  58. }
  59. echo " This script will look for unused wxWidgets headers"
  60. echo " Note that some headers maybe not referenced by wxWidgets sources/headers but still"
  61. echo " be useful for user applications; others instead are simply old and forgotten."
  62. echo
  63. for header in $headerList; do
  64. checkIfHeaderIsUsed $header
  65. done
  66. if [[ $unusedHeaders -gt 0 ]]; then
  67. echo " => WARNING: found $unusedHeaders unused headers!"
  68. else
  69. echo " => All headers are referenced in either wxWidgets sources or in other headers"
  70. fi