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