* NEWS: Mention pointer to member improvements.
[deliverable/binutils-gdb.git] / gdb / gdb_mbuild.sh
CommitLineData
3ed93867
RE
1#!/bin/sh
2
684e56bf
AC
3# Multi-build script for testing compilation of all maintained
4# configs of GDB.
5
197e01b6 6# Copyright (C) 2002, 2003 Free Software Foundation, Inc.
684e56bf 7
3ed93867
RE
8# Contributed by Richard Earnshaw (rearnsha@arm.com)
9
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
197e01b6
EZ
22# Foundation, Inc., 51 Franklin Street, Fifth Floor,
23# Boston, MA 02111-1301, USA
3ed93867 24
6e2c7fa1
DJ
25# Make certain that the script is not running in an internationalized
26# environment.
27LANG=c ; export LANG
28LC_ALL=c ; export LC_ALL
29
684e56bf
AC
30usage()
31{
32 cat <<EOF
33Usage: gdb_mbuild.sh [ <options> ... ] <srcdir> <builddir>
34 Options:
35 -j <makejobs> Run <makejobs> in parallel. Passed to make.
36 On a single cpu machine, 2 is recommended.
37 -k Keep going. Do not stop after the first build fails.
c9a1dc08 38 --keep Keep builds. Do not remove each build when finished.
684e56bf
AC
39 -e <regexp> Regular expression for selecting the targets to build.
40 -f Force rebuild. Even rebuild previously built directories.
41 -v Be more (and more, and more) verbose.
42 Arguments:
43 <srcdir> Source code directory.
44 <builddir> Build directory.
45 Environment variables examined (with default if not defined):
46 MAKE (make)"
47EOF
3ed93867 48 exit 1;
684e56bf
AC
49cat <<NOTYET
50 -b <maxbuilds> Run <maxbuild> builds in parallel.
51 On a single cpu machine, 1 is recommended.
52NOTYET
3ed93867
RE
53}
54
684e56bf
AC
55### COMMAND LINE OPTIONS
56
57makejobs=
58maxbuilds=1
59keepgoing=
60force=false
61targexp=""
62verbose=0
c9a1dc08 63keep=false
684e56bf
AC
64while test $# -gt 0
65do
66 case "$1" in
67 -j )
68 # Number of parallel make jobs.
69 shift
70 test $# -ge 1 || usage
71 makejobs="-j $1"
72 ;;
73 -b | -c )
74 # Number of builds to fire off in parallel.
75 shift
76 test $# -ge 1 || usage
77 maxbuilds=$1
78 ;;
79 -k )
80 # Should we soldier on after the first build fails?
81 keepgoing=-k
82 ;;
c9a1dc08
AC
83 --keep )
84 keep=true
85 ;;
684e56bf
AC
86 -e )
87 # A regular expression for selecting targets
88 shift
89 test $# -ge 1 || usage
90 targexp="${targexp} -e ${1}"
91 ;;
92 -f )
93 # Force a rebuild
e1c1c0f6
DC
94 force=true ;
95 ;;
684e56bf
AC
96 -v )
97 # Be more, and more, and more, verbose
98 verbose=`expr ${verbose} + 1`
99 ;;
100 -* ) usage ;;
101 *) break ;;
102 esac
103 shift
104done
105
106
107### COMMAND LINE PARAMETERS
108
109if test $# -ne 2
110then
3ed93867
RE
111 usage
112fi
113
684e56bf 114# Convert these to absolute directory paths.
3ed93867
RE
115
116# Where the sources live
684e56bf 117srcdir=`cd $1 && /bin/pwd` || exit 1
3ed93867
RE
118
119# Where the builds occur
684e56bf 120builddir=`cd $2 && /bin/pwd` || exit 1
3ed93867
RE
121
122### ENVIRONMENT PARAMETERS
3ed93867
RE
123
124# Version of make to use
125make=${MAKE:-make}
684e56bf
AC
126MAKE=${make}
127export MAKE
3ed93867
RE
128
129
3ed93867
RE
130# Where to look for the list of targets to test
131maintainers=${srcdir}/gdb/MAINTAINERS
684e56bf 132if [ ! -r ${maintainers} ]
3ed93867 133then
684e56bf
AC
134 echo Maintainers file ${maintainers} not found
135 exit 1
3ed93867
RE
136fi
137
684e56bf
AC
138# Get the list of targets and the build options
139alltarg=`cat ${maintainers} | tr -s '[\t]' '[ ]' | sed -n '
140/^[ ]*[-a-z0-9\.]*[ ]*[(]*--target=.*/ !d
141s/^.*--target=//
142s/).*$//
143h
144:loop
145 g
146 /^[^ ]*,/ !b end
147 s/,[^ ]*//
148 p
149 g
150 s/^[^,]*,//
151 h
152b loop
153:end
154p
155' | if test "${targexp}" = ""
3ed93867 156then
684e56bf
AC
157 grep -v -e broken -e OBSOLETE
158else
159 grep ${targexp}
160fi`
3ed93867 161
3ed93867 162
684e56bf
AC
163# Usage: fail <message> <test-that-should-succeed>. Should the build
164# fail? If the test is true, and we don't want to keep going, print
165# the message and shoot everything in sight and abort the build.
3ed93867 166
684e56bf
AC
167fail ()
168{
169 msg="$1" ; shift
170 if test "$@"
171 then
172 echo "${target}: ${msg}"
173 if test "${keepgoing}" != ""
3ed93867 174 then
684e56bf
AC
175 #exit 1
176 continue
177 else
178 kill $$
179 exit 1
3ed93867 180 fi
684e56bf
AC
181 fi
182}
183
184
185# Usage: log <level> <logfile>. Write standard input to <logfile> and
186# stdout (if verbose >= level).
187
188log ()
189{
190 if test ${verbose} -ge $1
191 then
192 tee $2
193 else
194 cat > $2
195 fi
196}
3ed93867 197
3ed93867 198
3ed93867 199
684e56bf
AC
200# Warn the user of what is comming, print the list of targets
201
202echo "$alltarg"
203echo ""
204
205
206# For each target, configure, build and test it.
207
208echo "$alltarg" | while read target gdbopts simopts
3ed93867 209do
684e56bf
AC
210
211 trap "exit 1" 1 2 15
212 dir=${builddir}/${target}
213
b2fa5097 214 # Should a scratch rebuild be forced, for perhaps the entire
684e56bf
AC
215 # build be skipped?
216
217 if ${force}
218 then
219 echo forcing ${target} ...
220 rm -rf ${dir}
221 elif test -f ${dir}
222 then
223 echo "${target}"
224 continue
225 else
226 echo ${target} ...
227 fi
228
229 # Did the previous configure attempt fail? If it did
230 # restart from scratch.
231
232 if test -d ${dir} -a ! -r ${dir}/Makefile
233 then
234 echo ... removing partially configured ${target}
235 rm -rf ${dir}
236 if test -d ${dir}
3ed93867 237 then
684e56bf
AC
238 echo "${target}: unable to remove directory ${dir}"
239 exit 1
3ed93867 240 fi
684e56bf
AC
241 fi
242
243 # From now on, we're in this target's build directory
244
245 mkdir -p ${dir}
246 cd ${dir} || exit 1
247
248 # Configure, if not already. Should this go back to being
249 # separate and done in parallel?
250
251 if test ! -r Makefile
252 then
253 # Default SIMOPTS to GDBOPTS.
254 test -z "${simopts}" && simopts="${gdbopts}"
255 # The config options
256 __target="--target=${target}"
257 __enable_gdb_build_warnings=`test -z "${gdbopts}" \
258 || echo "--enable-gdb-build-warnings=${gdbopts}"`
259 __enable_sim_build_warnings=`test -z "${simopts}" \
260 || echo "--enable-sim-build-warnings=${simopts}"`
261 __configure="${srcdir}/configure \
262 ${__target} \
263 ${__enable_gdb_build_warnings} \
264 ${__enable_sim_build_warnings}"
265 echo ... ${__configure}
266 trap "echo Removing partially configured ${dir} directory ...; rm -rf ${dir}; exit 1" 1 2 15
267 ${__configure} 2>&1 | log 2 Config.log
268 trap "exit 1" 1 2 15
269 fi
270 fail "configure failed" ! -r Makefile
271
272 # Build, if not built.
273
274 if test ! -x gdb/gdb -a ! -x gdb/gdb.exe
275 then
c9a1dc08
AC
276 # Iff the build fails remove the final build target so that
277 # the follow-on code knows things failed. Stops the follow-on
278 # code thinking that a failed rebuild succedded (executable
279 # left around from previous build).
684e56bf 280 echo ... ${make} ${keepgoing} ${makejobs} ${target}
c9a1dc08
AC
281 ( ${make} ${keepgoing} ${makejobs} all-gdb || rm -f gdb/gdb gdb/gdb.exe
282 ) 2>&1 | log 1 Build.log
684e56bf
AC
283 fi
284 fail "compile failed" ! -x gdb/gdb -a ! -x gdb/gdb.exe
285
286 # Check that the built GDB can at least print it's architecture.
287
288 echo ... run ${target}
289 rm -f core gdb.core ${dir}/gdb/x
290 cat <<EOF > x
291maint print architecture
292quit
293EOF
294 ./gdb/gdb -batch -nx -x x 2>&1 | log 1 Gdb.log
295 fail "gdb dumped core" -r core -o -r gdb.core
296 fail "gdb printed no output" ! -s Gdb.log
297 grep -e internal-error Gdb.log && fail "gdb panic" 1
298
dbad9d94
AC
299 echo ... cleanup ${target}
300
301 # Create a sed script that cleans up the output from GDB.
302 rm -f mbuild.sed
303 touch mbuild.sed || exit 1
dbad9d94
AC
304 # Rules to replace <0xNNNN> with the corresponding function's
305 # name.
306 sed -n -e '/<0x0*>/d' -e 's/^.*<0x\([0-9a-f]*\)>.*$/0x\1/p' Gdb.log \
307 | sort -u \
308 | while read addr
309 do
310 func="`addr2line -f -e ./gdb/gdb -s ${addr} | sed -n -e 1p`"
311 test ${verbose} -gt 0 && echo "${addr} ${func}" 1>&2
312 echo "s/<${addr}>/<${func}>/g"
313 done >> mbuild.sed
dbad9d94
AC
314 # Rules to strip the leading paths off of file names.
315 echo 's/"\/.*\/gdb\//"gdb\//g' >> mbuild.sed
c9a1dc08
AC
316 # Run the script
317 sed -f mbuild.sed Gdb.log > Mbuild.log
dbad9d94 318
684e56bf
AC
319 # Replace the build directory with a file as semaphore that stops
320 # a rebuild. (should the logs be saved?)
321
322 cd ${builddir}
c9a1dc08
AC
323
324 if ${keep}
325 then
326 :
327 else
328 rm -f ${target}.tmp
329 mv ${target}/Mbuild.log ${target}.tmp
330 rm -rf ${target}
331 mv ${target}.tmp ${target}
332 fi
684e56bf
AC
333
334 # Success!
335 echo ... ${target} built
336
3ed93867 337done
684e56bf
AC
338
339exit 0
This page took 0.3908 seconds and 4 git commands to generate.