3 # Multi-build script for testing compilation of all maintained
6 # Copyright 2002, 2003 Free Software Foundation, Inc.
8 # Contributed by Richard Earnshaw (rearnsha@arm.com)
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.
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.
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
27 Usage: gdb_mbuild.sh [ <options> ... ] <srcdir> <builddir>
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.
32 --keep Keep builds. Do not remove each build when finished.
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.
37 <srcdir> Source code directory.
38 <builddir> Build directory.
39 Environment variables examined (with default if not defined):
44 -b <maxbuilds> Run <maxbuild> builds in parallel.
45 On a single cpu machine, 1 is recommended.
49 ### COMMAND LINE OPTIONS
62 # Number of parallel make jobs.
64 test $# -ge 1 || usage
68 # Number of builds to fire off in parallel.
70 test $# -ge 1 || usage
74 # Should we soldier on after the first build fails?
81 # A regular expression for selecting targets
83 test $# -ge 1 || usage
84 targexp
="${targexp} -e ${1}"
91 # Be more, and more, and more, verbose
92 verbose
=`expr ${verbose} + 1`
101 ### COMMAND LINE PARAMETERS
108 # Convert these to absolute directory paths.
110 # Where the sources live
111 srcdir
=`cd $1 && /bin/pwd` ||
exit 1
113 # Where the builds occur
114 builddir
=`cd $2 && /bin/pwd` ||
exit 1
116 ### ENVIRONMENT PARAMETERS
118 # Version of make to use
124 # Where to look for the list of targets to test
125 maintainers
=${srcdir}/gdb
/MAINTAINERS
126 if [ ! -r ${maintainers} ]
128 echo Maintainers
file ${maintainers} not found
132 # Get the list of targets and the build options
133 alltarg
=`cat ${maintainers} | tr -s '[\t]' '[ ]' | sed -n '
134 /^[ ]*[-a-z0-9\.]*[ ]*[(]*--target=.*/ !d
149 ' | if test "${targexp}" = ""
151 grep -v -e broken -e OBSOLETE
157 # Usage: fail <message> <test-that-should-succeed>. Should the build
158 # fail? If the test is true, and we don't want to keep going, print
159 # the message and shoot everything in sight and abort the build.
166 echo "${target}: ${msg}"
167 if test "${keepgoing}" != ""
179 # Usage: log <level> <logfile>. Write standard input to <logfile> and
180 # stdout (if verbose >= level).
184 if test ${verbose} -ge $1
194 # Warn the user of what is comming, print the list of targets
200 # For each target, configure, build and test it.
202 echo "$alltarg" |
while read target gdbopts simopts
206 dir
=${builddir}/${target}
208 # Should a scratch rebuild be forced, for perhaps the entire
213 echo forcing
${target} ...
223 # Did the previous configure attempt fail? If it did
224 # restart from scratch.
226 if test -d ${dir} -a ! -r ${dir}/Makefile
228 echo ... removing partially configured
${target}
232 echo "${target}: unable to remove directory ${dir}"
237 # From now on, we're in this target's build directory
242 # Configure, if not already. Should this go back to being
243 # separate and done in parallel?
245 if test ! -r Makefile
247 # Default SIMOPTS to GDBOPTS.
248 test -z "${simopts}" && simopts
="${gdbopts}"
250 __target
="--target=${target}"
251 __enable_gdb_build_warnings
=`test -z "${gdbopts}" \
252 || echo "--enable-gdb-build-warnings=${gdbopts}"`
253 __enable_sim_build_warnings
=`test -z "${simopts}" \
254 || echo "--enable-sim-build-warnings=${simopts}"`
255 __configure
="${srcdir}/configure \
257 ${__enable_gdb_build_warnings} \
258 ${__enable_sim_build_warnings}"
259 echo ...
${__configure}
260 trap "echo Removing partially configured ${dir} directory ...; rm -rf ${dir}; exit 1" 1 2 15
261 ${__configure} 2>&1 | log
2 Config.log
264 fail
"configure failed" ! -r Makefile
266 # Build, if not built.
268 if test ! -x gdb
/gdb
-a ! -x gdb
/gdb.exe
270 # Iff the build fails remove the final build target so that
271 # the follow-on code knows things failed. Stops the follow-on
272 # code thinking that a failed rebuild succedded (executable
273 # left around from previous build).
274 echo ...
${make} ${keepgoing} ${makejobs} ${target}
275 ( ${make} ${keepgoing} ${makejobs} all-gdb ||
rm -f gdb
/gdb gdb
/gdb.exe
276 ) 2>&1 | log
1 Build.log
278 fail
"compile failed" ! -x gdb
/gdb
-a ! -x gdb
/gdb.exe
280 # Check that the built GDB can at least print it's architecture.
282 echo ... run
${target}
283 rm -f core gdb.core
${dir}/gdb
/x
285 maint print architecture
288 .
/gdb
/gdb
-batch -nx -x x
2>&1 | log
1 Gdb.log
289 fail
"gdb dumped core" -r core
-o -r gdb.core
290 fail
"gdb printed no output" ! -s Gdb.log
291 grep -e internal-error Gdb.log
&& fail
"gdb panic" 1
293 echo ... cleanup
${target}
295 # Create a sed script that cleans up the output from GDB.
297 touch mbuild.
sed ||
exit 1
298 # Rules to replace <0xNNNN> with the corresponding function's
300 sed -n -e '/<0x0*>/d' -e 's/^.*<0x\([0-9a-f]*\)>.*$/0x\1/p' Gdb.log \
304 func
="`addr2line -f -e ./gdb/gdb -s ${addr} | sed -n -e 1p`"
305 test ${verbose} -gt 0 && echo "${addr} ${func}" 1>&2
306 echo "s
/<${addr}>/<${func}>/g
"
308 # Rules to strip the leading paths off of file names.
309 echo 's/"\
/.
*\
/gdb\
//"gdb\//g' >> mbuild.sed
311 sed -f mbuild.sed Gdb.log > Mbuild.log
313 # Replace the build directory with a file as semaphore that stops
314 # a rebuild. (should the logs be saved?)
323 mv ${target}/Mbuild.log ${target}.tmp
325 mv ${target}.tmp ${target}
329 echo ... ${target} built