gdb/testsuite/
[binutils-gdb.git] / gdb / cc-with-dwz.sh
1 #! /bin/sh
2 # Wrapper around gcc to run 'dwz' when running the testsuite.
3
4 # Copyright (C) 2010-2012 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 # This program requires dwz in addition to gcc.
19 #
20 # Example usage:
21 #
22 # bash$ cd $objdir/gdb/testsuite
23 # bash$ runtest \
24 # CC_FOR_TARGET="/bin/sh $srcdir/cc-with-dwz.sh gcc" \
25 # CXX_FOR_TARGET="/bin/sh $srcdir/cc-with-dwz.sh g++"
26 #
27
28 myname=cc-with-dwz.sh
29
30 DWZ=${DWZ:-dwz}
31
32 have_link=unknown
33 next_is_output_file=no
34 output_file=a.out
35
36 for arg in "$@"
37 do
38 if [ "$next_is_output_file" = "yes" ]
39 then
40 output_file="$arg"
41 next_is_output_file=no
42 continue
43 fi
44
45 # Poor man's gcc argument parser.
46 # We don't need to handle all arguments, we just need to know if we're
47 # doing a link and what the output file is.
48 # It's not perfect, but it seems to work well enough for the task at hand.
49 case "$arg" in
50 "-c") have_link=no ;;
51 "-E") have_link=no ;;
52 "-S") have_link=no ;;
53 "-o") next_is_output_file=yes ;;
54 esac
55 done
56
57 if [ "$next_is_output_file" = "yes" ]
58 then
59 echo "$myname: Unable to find output file" >&2
60 exit 1
61 fi
62
63 if [ "$have_link" = "no" ]
64 then
65 "$@"
66 exit $?
67 fi
68
69 "$@"
70 rc=$?
71 [ $rc != 0 ] && exit $rc
72 if [ ! -f "$output_file" ]
73 then
74 echo "$myname: Internal error: $output_file missing." >&2
75 exit 1
76 fi
77
78 $DWZ "$output_file" > /dev/null 2>&1
79
80 exit 0