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