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