* printcmd.c (ui_printf): Eliminate single-use variable
[deliverable/binutils-gdb.git] / gdb / contrib / cc-with-tweaks.sh
CommitLineData
ea65fe05 1#! /bin/sh
853254db
TT
2# Wrapper around gcc to tweak the output in various ways when running
3# the testsuite.
ea65fe05 4
0b302171 5# Copyright (C) 2010-2012 Free Software Foundation, Inc.
ea65fe05
DE
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19# This program requires gdb and objcopy in addition to gcc.
0b5574da
DE
20# The default values are gdb from the build tree and objcopy from $PATH.
21# They may be overridden by setting environment variables GDB and OBJCOPY
ea65fe05
DE
22# respectively.
23# We assume the current directory is either $obj/gdb or $obj/gdb/testsuite.
24#
25# Example usage:
26#
27# bash$ cd $objdir/gdb/testsuite
28# bash$ runtest \
aec8845c
JK
29# CC_FOR_TARGET="/bin/sh $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS gcc" \
30# CXX_FOR_TARGET="/bin/sh $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS g++"
ea65fe05
DE
31#
32# For documentation on index files: info -f gdb.info -n "Index Files"
853254db
TT
33# For information about 'dwz', see the announcement:
34# http://gcc.gnu.org/ml/gcc/2012-04/msg00686.html
35# (More documentation is to come.)
ea65fe05 36
853254db
TT
37# ARGS determine what is done. They can be:
38# -z compress using dwz
39# -m compress using dwz -m
40# -i make an index
41# If nothing is given, no changes are made
42
43myname=cc-with-tweaks.sh
ea65fe05
DE
44
45if [ -z "$GDB" ]
46then
47 if [ -f ./gdb ]
48 then
49 GDB="./gdb"
50 elif [ -f ../gdb ]
51 then
52 GDB="../gdb"
b8e9bd6c
DE
53 elif [ -f ../../gdb ]
54 then
55 GDB="../../gdb"
ea65fe05
DE
56 else
57 echo "$myname: unable to find usable gdb" >&2
58 exit 1
59 fi
60fi
61
62OBJCOPY=${OBJCOPY:-objcopy}
63
853254db
TT
64DWZ=${DWZ:-dwz}
65
ea65fe05
DE
66have_link=unknown
67next_is_output_file=no
00e14314 68output_file=a.out
ea65fe05 69
853254db
TT
70want_index=false
71want_dwz=false
72want_multi=false
73
74while [ $# -gt 0 ]; do
75 case "$1" in
76 -z) want_dwz=true ;;
77 -i) want_index=true ;;
78 -m) want_multi=true ;;
79 *) break ;;
80 esac
81 shift
82done
83
ea65fe05
DE
84for arg in "$@"
85do
86 if [ "$next_is_output_file" = "yes" ]
87 then
88 output_file="$arg"
89 next_is_output_file=no
90 continue
91 fi
92
93 # Poor man's gcc argument parser.
94 # We don't need to handle all arguments, we just need to know if we're
95 # doing a link and what the output file is.
96 # It's not perfect, but it seems to work well enough for the task at hand.
97 case "$arg" in
98 "-c") have_link=no ;;
99 "-E") have_link=no ;;
100 "-S") have_link=no ;;
101 "-o") next_is_output_file=yes ;;
102 esac
103done
104
105if [ "$next_is_output_file" = "yes" ]
106then
107 echo "$myname: Unable to find output file" >&2
108 exit 1
109fi
110
111if [ "$have_link" = "no" ]
112then
113 "$@"
114 exit $?
115fi
116
117index_file="${output_file}.gdb-index"
853254db 118if [ "$want_index" = true ] && [ -f "$index_file" ]
ea65fe05
DE
119then
120 echo "$myname: Index file $index_file exists, won't clobber." >&2
121 exit 1
122fi
123
124output_dir="${output_file%/*}"
125[ "$output_dir" = "$output_file" ] && output_dir="."
126
127"$@"
128rc=$?
129[ $rc != 0 ] && exit $rc
130if [ ! -f "$output_file" ]
131then
132 echo "$myname: Internal error: $output_file missing." >&2
133 exit 1
134fi
135
853254db
TT
136if [ "$want_index" = true ]; then
137 $GDB --batch-silent -nx -ex "set auto-load no" -ex "file $output_file" -ex "save gdb-index $output_dir"
ea65fe05 138 rc=$?
853254db
TT
139 [ $rc != 0 ] && exit $rc
140
141 # GDB might not always create an index. Cope.
142 if [ -f "$index_file" ]
143 then
144 $OBJCOPY --add-section .gdb_index="$index_file" \
145 --set-section-flags .gdb_index=readonly \
146 "$output_file" "$output_file"
147 rc=$?
148 else
149 rc=0
150 fi
151 [ $rc != 0 ] && exit $rc
152fi
153
154if [ "$want_dwz" = true ]; then
155 $DWZ "$output_file" > /dev/null 2>&1
156elif [ "$want_multi" = true ]; then
157 cp $output_file ${output_file}.alt
158 $DWZ -m ${output_file}.dwz "$output_file" ${output_file}.alt > /dev/null 2>&1
ea65fe05
DE
159fi
160
161rm -f "$index_file"
162exit $rc
This page took 0.170991 seconds and 4 git commands to generate.