3 # Multi-build script for testing compilation of all maintained
6 # Copyright (C) 2002-2016 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 3 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, see <http://www.gnu.org/licenses/>.
23 # Make certain that the script is not running in an internationalized
26 LC_ALL=c ; export LC_ALL
31 Usage: gdb_mbuild.sh [ <options> ... ] <srcdir> <builddir>
33 -j <makejobs> Run <makejobs> in parallel. Passed to make.
34 On a single cpu machine, 2 is recommended.
35 -k Keep going. Do not stop after the first build fails.
36 --keep Keep builds. Do not remove each build when finished.
37 -e <regexp> Regular expression for selecting the targets to build.
38 -f Force rebuild. Even rebuild previously built directories.
39 -v Be more (and more, and more) verbose.
41 <srcdir> Source code directory.
42 <builddir> Build directory.
43 Environment variables examined (with default if not defined):
48 -b <maxbuilds> Run <maxbuild> builds in parallel.
49 On a single cpu machine, 1 is recommended.
53 ### COMMAND LINE OPTIONS
66 # Number of parallel make jobs.
68 test $# -ge 1 || usage
72 # Number of builds to fire off in parallel.
74 test $# -ge 1 || usage
78 # Should we soldier on after the first build fails?
85 # A regular expression for selecting targets
87 test $# -ge 1 || usage
88 targexp="${targexp} -e ${1}"
95 # Be more, and more, and more, verbose
96 verbose=`expr ${verbose} + 1`
105 ### COMMAND LINE PARAMETERS
112 # Convert these to absolute directory paths.
114 # Where the sources live
115 srcdir=`cd $1 && /bin/pwd` || exit 1
117 # Where the builds occur
118 builddir=`cd $2 && /bin/pwd` || exit 1
120 ### ENVIRONMENT PARAMETERS
122 # Version of make to use
128 # Where to look for the list of targets to test
129 maintainers=${srcdir}/gdb/MAINTAINERS
130 if [ ! -r ${maintainers} ]
132 echo Maintainers file ${maintainers} not found
136 # Get the list of targets and the build options
137 alltarg=`cat ${maintainers} | tr -s '[\t]' '[ ]' | sed -n '
138 /^[ ]*[-a-z0-9\.]*[ ]*[(]*--target=.*/ !d
153 ' | if test "${targexp}" = ""
155 grep -v -e broken -e OBSOLETE
161 # Usage: fail <message> <test-that-should-succeed>. Should the build
162 # fail? If the test is true, and we don't want to keep going, print
163 # the message and shoot everything in sight and abort the build.
170 echo "${target}: ${msg}"
171 if test "${keepgoing}" != ""
183 # Usage: log <level> <logfile>. Write standard input to <logfile> and
184 # stdout (if verbose >= level).
188 if test ${verbose} -ge $1
198 # Warn the user of what is coming, print the list of targets
204 # For each target, configure, build and test it.
206 echo "$alltarg" | while read target gdbopts simopts
210 dir=${builddir}/${target}
212 # Should a scratch rebuild be forced, for perhaps the entire
217 echo forcing ${target} ...
227 # Did the previous configure attempt fail? If it did
228 # restart from scratch.
230 if test -d ${dir} -a ! -r ${dir}/Makefile
232 echo ... removing partially configured ${target}
236 echo "${target}: unable to remove directory ${dir}"
241 # From now on, we're in this target's build directory
246 # Configure, if not already. Should this go back to being
247 # separate and done in parallel?
249 if test ! -r Makefile
251 # Default SIMOPTS to GDBOPTS.
252 test -z "${simopts}" && simopts="${gdbopts}"
254 __target="--target=${target}"
255 __enable_gdb_build_warnings=`test -z "${gdbopts}" \
256 || echo "--enable-gdb-build-warnings=${gdbopts}"`
257 __enable_sim_build_warnings=`test -z "${simopts}" \
258 || echo "--enable-sim-build-warnings=${simopts}"`
259 __configure="${srcdir}/configure \
261 ${__enable_gdb_build_warnings} \
262 ${__enable_sim_build_warnings}"
263 echo ... ${__configure}
264 trap "echo Removing partially configured ${dir} directory ...; rm -rf ${dir}; exit 1" 1 2 15
265 ${__configure} 2>&1 | log 2 Config.log
268 fail "configure failed" ! -r Makefile
270 # Build, if not built.
272 if test ! -x gdb/gdb -a ! -x gdb/gdb.exe
274 # Iff the build fails remove the final build target so that
275 # the follow-on code knows things failed. Stops the follow-on
276 # code thinking that a failed rebuild succeeded (executable
277 # left around from previous build).
278 echo ... ${make} ${keepgoing} ${makejobs} ${target}
279 ( ${make} ${keepgoing} ${makejobs} all-gdb || rm -f gdb/gdb gdb/gdb.exe
280 ) 2>&1 | log 1 Build.log
282 fail "compile failed" ! -x gdb/gdb -a ! -x gdb/gdb.exe
284 # Check that the built GDB can at least print it's architecture.
286 echo ... run ${target}
287 rm -f core gdb.core ${dir}/gdb/x
289 maint print architecture
292 ./gdb/gdb -batch -nx -x x 2>&1 | log 1 Gdb.log
293 fail "gdb dumped core" -r core -o -r gdb.core
294 fail "gdb printed no output" ! -s Gdb.log
295 grep -e internal-error Gdb.log && fail "gdb panic" 1
297 echo ... cleanup ${target}
299 # Create a sed script that cleans up the output from GDB.
301 touch mbuild.sed || exit 1
302 # Rules to replace <0xNNNN> with the corresponding function's
304 sed -n -e '/<0x0*>/d' -e 's/^.*<0x\([0-9a-f]*\)>.*$/0x\1/p' Gdb.log \
308 func="`addr2line -f -e ./gdb/gdb -s ${addr} | sed -n -e 1p`"
309 test ${verbose} -gt 0 && echo "${addr} ${func}" 1>&2
310 echo "s/<${addr}>/<${func}>/g"
312 # Rules to strip the leading paths off of file names.
313 echo 's/"\/.*\/gdb\//"gdb\//g' >> mbuild.sed
315 sed -f mbuild.sed Gdb.log > Mbuild.log
317 # Replace the build directory with a file as semaphore that stops
318 # a rebuild. (should the logs be saved?)
327 mv ${target}/Mbuild.log ${target}.tmp
329 mv ${target}.tmp ${target}
333 echo ... ${target} built