ms format support for mingw.
[official-gcc.git] / contrib / check_warning_flags.sh
blobfcd0f37e1053e3a1507fb8af9aa0c6583cc6c9b1
1 #! /bin/sh
3 # Check that the warning flags documented in invoke.texi match up
4 # with what the compiler accepts.
6 # Copyright (C) 2008 Free Software Foundation, Inc.
7 # Written by Ralf Wildenhues <Ralf.Wildenhues@gmx.de>.
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
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.
18 progname=`echo "$0" | sed 's,.*/,,'`
19 usage ()
21 echo "usage: $progname path/to/gcc/doc"
22 echo "set \$CC to the compiler to be checked"
23 exit 1
26 ret=0
27 LC_ALL=C
28 export LC_ALL
29 : ${CC=gcc}
30 test $# = 1 || usage
31 gcc_docdir=$1
32 invoke_texi=$gcc_docdir/invoke.texi
33 test -r "$invoke_texi" || {
34 echo "$progname: error: cannot read '$invoke_texi'" >&2
35 usage
37 filebase=check_warning_flags_file$$
38 stderr=check_warning_flags_stderr$$
40 remove_problematic_flags='
41 /-Wlarger-than-/d
42 /-W[alp],/d
43 /-Werror/d
44 /-Wpadded/d
45 /=/d'
47 # Ensure that indexed warnings are accepted.
48 set x `sed '/^@opindex W/{
49 s/^@opindex /-/
50 '"$remove_problematic_flags"'
51 /-W[alp]$/d
54 d' <"$invoke_texi"`
55 shift
56 : >$filebase.c
57 $CC -c $filebase.c "$@" 2>&1 |
58 grep -v 'command line option.*is valid for.*but not for' >$stderr
59 if test -s $stderr; then
60 echo "options listed in @opindex but not accepted by the compiler:" >&2
61 cat $stderr >&2
62 ret=1
64 rm -f $filebase.c $stderr
66 # Check documentation of warning options.
67 for lang in c c++ objc obj-c++; do
68 case $lang in
69 c) ext=c; langmatch='[^-]C[^+].*only' ;;
70 c++) ext=C; langmatch='[^-]C++.*only' ;;
71 objc) ext=m; langmatch='Objective-C[^+].*only' ;;
72 obj-c++) ext=M; langmatch='Objective-C++.*only' ;;
73 esac
74 file=$filebase.$ext
75 : >$file
76 $CC -c $file 2>$stderr
77 if grep 'not installed on this system' $stderr >/dev/null ||
78 grep 'installation problem, cannot exec' $stderr >/dev/null ||
79 grep 'error trying to exec' $stderr >/dev/null
80 then
81 echo "$progname: $CC is not configured for language $lang, skipping checks" >&2
82 rm -f $file $filebase.o $filebase.obj $stderr
83 continue
86 # Verify good warning flags.
87 set x `sed '
88 t a
90 /^@item -W/{
91 /'"$langmatch"'/b x
92 / only)/d
93 b x
97 '"$remove_problematic_flags"'
98 s/^@item //
99 s/ .*//
100 ' <"$invoke_texi"`
101 shift
102 $CC -c $file -O "$@" 2>$stderr
103 if test -s $stderr; then
104 echo failures: >&2
105 cat $stderr >&2
106 ret=1
109 # Verify bad warning flags.
110 set x `sed '
113 /^@item -W/{
114 / only)/!d
115 /'"$langmatch"'/d
120 '"$remove_problematic_flags"'
121 s/^@item //
122 s/ .*//
123 ' <"$invoke_texi"`
124 shift
125 $CC -c $file -O "$@" 2>$stderr
126 # cat $stderr >&2
127 test $# = `grep 'command line option.*valid.*but not for' <$stderr | wc -l` || {
128 for warning
130 grep "command line option.*$warning.*valid" <$stderr >&2 ||
131 echo "valid for $lang but not annotated as such: $warning"
132 done
133 ret=1
135 rm -f $file $filebase.o $filebase.obj $stderr
136 done
139 remove_problematic_help_flags='
140 /^W$/d
141 /^W[alp]$/d
142 /^Werror-implicit-function-declaration$/d
143 /^Wsynth$/d
144 /-$/d
145 /=/d'
146 help_flags=`
147 $CC --help -v 2>/dev/null | tr ' ' '\n' |
148 sed -n '
151 s/^-\(W[^<,]*\).*/\1/
155 '"$remove_problematic_help_flags"'
156 p' | sort -u`
157 : >$filebase.c
158 for flag in $help_flags; do
159 $CC -c $filebase.c -$flag 2>/dev/null || {
160 echo "warning -$flag not supported" >&2
161 ret=1
163 grep "@item.*$flag" $gcc_docdir/../*/*.texi >/dev/null || {
164 # For @item, we are satisfied with either -Wfoo or -Wno-foo.
165 inverted_flag=`echo "$flag" | sed '
166 s/^Wno-/W/
168 s/^W/Wno-/'`
169 grep "@item.*$inverted_flag" $gcc_docdir/../*/*.texi >/dev/null || {
170 echo "warning -$flag not documented in $gcc_docdir/../*/*.texi" >&2
171 ret=1
174 done
175 rm -f $filebase.c $filebase.o
177 exit $ret