fixed and improved the `gcc-warnings` script:
[olsrd.git] / gcc-warnings
1 #!/bin/sh
2 #
3 # We expect warning options for gcc as argumenst and return the ones which are accepted
4 # by the given gcc.
5 #
6 # $Id: gcc-warnings,v 1.6 2007/11/12 00:12:15 bernd67 Exp $
7
8 set -ue
9 #set -vx
10
11 # make sure we do not use some locale ....
12 export LANG=C LC_ALL=C LC_COLLATE=C LC_CTYPE=C LC_MESSAGES=C LC_NUMERIC=C
13
14 OPTS=""
15 for param; do
16     case "$param" in
17     -[fWm]?*) OPTS="$OPTS $param";;
18     *)        echo "Ignoring $param" >&2
19     esac
20 done
21
22 testcompile() {
23     $CC $OPTS -E - 2>&1 <<- EOF
24        int main(void) {
25            return 0;
26        }
27 EOF
28 }
29
30 parsetest() {
31     while read error; do 
32        case "$error" in
33        *error:\ unrecognized\ *option\ \"*)
34                                        opt="${error#*\"}"
35                                        opt="${opt%\"*}"
36                                        OPTS="${OPTS//$opt}"
37                                        ;;
38        *error:\ unrecognized\ *option\ \`*)
39                                        opt="${error#*\`}"
40                                        opt="${opt%\'*}"
41                                        OPTS="${OPTS//$opt}"
42                                        ;;
43        esac
44     done
45     echo $OPTS
46 }
47
48 testcompile | parsetest
49
50 exit 0