OSDN Git Service

* check_warning_flags.sh: New file.
[pf3gnuchains/gcc-fork.git] / contrib / check_warning_flags.sh
1 #! /bin/sh
2 #
3 # Check that the warning flags documented in invoke.texi match up
4 # with what the compiler accepts.
5 #
6 # Copyright (C) 2008 Free Software Foundation, Inc.
7 # Written by Ralf Wildenhues <Ralf.Wildenhues@gmx.de>.
8 #
9 # This script is Free Software, and it can be copied, distributed and
10 # modified as defined in the GNU General Public License.  A copy of
11 # its license can be downloaded from http://www.gnu.org/copyleft/gpl.html
12 #
13 # Call this script as
14 #    check_warning_flags.sh path/to/invoke.texi
15 # with CC set to the compiler to be tested.
16 # The script scribbles in the current directory.
17
18 progname=`echo "$0" | sed 's,.*/,,'`
19 usage ()
20 {
21   echo "usage: $progname path/to/invoke.texi"
22   echo "set \$CC to the compiler to be checked"
23   exit 1
24 }
25
26 ret=0
27 LC_ALL=C
28 export LC_ALL
29 : ${CC=gcc}
30 test $# = 1 || usage
31 invoke_texi=$1
32 test -r "$invoke_texi" || {
33   echo "$progname: error: cannot read '$invoke_texi'" >&2
34   usage
35 }
36 filebase=check_warning_flags_file$$
37 stderr=check_warning_flags_stderr$$
38
39 remove_problematic_flags='
40   /-Wlarger-than-/d
41   /-W[alp],/d
42   /-Werror/d
43   /-Wpadded/d
44   /=/d'
45
46 # Ensure that indexed warnings are accepted.
47 set x `sed '/^@opindex W/{
48   s/^@opindex /-/
49   '"$remove_problematic_flags"'
50   /-W[alp]$/d
51   p
52 }
53 d' <"$invoke_texi"`
54 shift
55 : >$filebase.c
56 $CC -c $filebase.c "$@" 2>&1 |
57   grep -v 'command line option.*is valid for.*but not for' >$stderr
58 if test -s $stderr; then
59   echo "options listed in @opindex but not accepted by the compiler:" >&2
60   cat $stderr >&2
61   ret=1
62 fi
63 rm -f $filebase.c $stderr
64
65 # Check documentation of warning options.
66 for lang in c c++ objc obj-c++; do
67   case $lang in
68   c)       ext=c; langmatch='[^-]C[^+].*only' ;;
69   c++)     ext=C; langmatch='[^-]C++.*only' ;;
70   objc)    ext=m; langmatch='Objective-C[^+].*only' ;;
71   obj-c++) ext=M; langmatch='Objective-C++.*only' ;;
72   esac
73   file=$filebase.$ext
74   : >$file
75   $CC -c $file 2>$stderr
76   if grep 'not installed on this system' $stderr >/dev/null ||
77     grep 'installation problem, cannot exec' $stderr >/dev/null ||
78     grep 'error trying to exec' $stderr >/dev/null
79   then
80     echo "$progname: $CC is not configured for language $lang, skipping checks" >&2
81     rm -f $file $filebase.o $filebase.obj $stderr
82     continue
83   fi
84
85   # Verify good warning flags.
86   set x `sed '
87     t a
88     :a
89     /^@item -W/{
90       /'"$langmatch"'/b x
91       / only)/d
92       b x
93     }
94     d
95     :x
96     '"$remove_problematic_flags"'
97     s/^@item //
98     s/ .*//
99     ' <"$invoke_texi"`
100   shift
101   $CC -c $file -O "$@" 2>$stderr
102   if test -s $stderr; then
103     echo failures:  >&2
104     cat $stderr >&2
105     ret=1
106   fi
107
108   # Verify bad warning flags.
109   set x `sed '
110     t a
111     :a
112     /^@item -W/{
113       / only)/!d
114       /'"$langmatch"'/d
115       b x
116     }
117     d
118     :x
119     '"$remove_problematic_flags"'
120     s/^@item //
121     s/ .*//
122     ' <"$invoke_texi"`
123   shift
124   $CC -c $file -O "$@" 2>$stderr
125   # cat $stderr >&2
126   test $# = `grep 'command line option.*valid.*but not for' <$stderr | wc -l` || {
127     for warning
128     do
129       grep "command line option.*$warning.*valid" <$stderr >&2 ||
130         echo "valid for $lang but not annotated as such: $warning"
131     done
132     ret=1
133   }
134   rm -f $file $filebase.o $filebase.obj $stderr
135 done
136 exit $ret