-
Notifications
You must be signed in to change notification settings - Fork 1
/
gcc-warnings
executable file
·59 lines (52 loc) · 1.24 KB
/
gcc-warnings
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh
#
# We expect warning options for gcc as arguments and return the ones which are
# accepted by the given gcc.
#
set -ue
#set -vx
# make sure we do not use some locale ....
export LANG=C LC_ALL=C LC_COLLATE=C LC_CTYPE=C LC_MESSAGES=C LC_NUMERIC=C
OPTS=""
for param; do
case "$param" in
-[fWm]?*) OPTS="$OPTS $param";;
*) echo "Ignoring $param" >&2
esac
done
testcompile() {
$CC $OPTS -x c -o /dev/null - 2>&1 <<- EOF
int main(void) {
return 0;
}
EOF
}
parsetest() {
while read error; do
case "$error" in
*:\ unrecognized\ *option\ \"*)
opt="${error#*\"}"
opt="${opt%\"*}"
;;
*:\ unrecognized\ *option\ \`*)
opt="${error#*\`}"
opt="${opt%\'*}"
;;
*) continue
;;
esac
# if we come here, we have in $opt the option to remove. and
# we remove all instances. And we save agoinst leading "-"
NEW_OPTS=""
for o in $OPTS; do
case "$o" in
$opt) : echo "Removed $o" >&2;;
*) NEW_OPTS="$NEW_OPTS $o";;
esac
done
OPTS="$NEW_OPTS"
done
echo $OPTS
}
testcompile | parsetest
exit 0