3 # Build script to build GDB with all targets enabled.
5 # Copyright (C) 2008-2019 Free Software Foundation, Inc.
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.
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.
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/>.
19 # Make certain that the script is not running in an internationalized
20 # environment. The script is grepping for GDB's output.
22 # Contributed by Markus Deuling <deuling@de.ibm.com>.
23 # Based on gdb_mbuild.sh from Richard Earnshaw.
27 LC_ALL=c ; export LC_ALL
29 # Prints a usage message.
33 Usage: gdb_buildall.sh [ <options> ... ] <srcdir> <builddir>
37 --bfd64 Enable 64-bit BFD.
38 --clean Delete build directory after check.
39 -e <regexp> Regular expression for selecting the targets to build.
40 --force Force rebuild.
41 -j <makejobs> Run <makejobs> in parallel. Passed to make.
42 On a single cpu machine, 2 is recommended.
44 <srcdir> Source code directory.
45 <builddir> Build directory.
47 Environment variables examined (with default if not defined):
53 ### Command line options.
63 # Number of parallel make jobs.
65 test $# -ge 1 || usage
69 # Shall the build directory be deleted after processing?
73 # A regular expression for selecting targets
75 test $# -ge 1 || usage
76 targexp="${targexp} -e ${1}"
84 bfd_flag="--enable-64-bit-bfd"
99 # Convert these to absolute directory paths.
100 srcdir=`cd $1 && /bin/pwd` || exit 1
101 builddir=`cd $2 && /bin/pwd` || exit 1
102 # Version of make to use
106 # We don't want GDB do dump cores.
109 # Just make sure we're in the right directory.
110 maintainers=${srcdir}/gdb/MAINTAINERS
111 if [ ! -r ${maintainers} ]
113 echo Maintainers file ${maintainers} not found
118 # Build GDB with all targets enabled.
119 echo "Starting gdb_buildall.sh ..."
124 # Should a scratch rebuild be forced, for perhaps the entire build be skipped?
127 echo ... forcing rebuild
131 # Did the previous configure attempt fail? If it did restart from scratch
132 if test -d ${dir} -a ! -r ${dir}/Makefile
134 echo ... removing partially configured
138 echo "... ERROR: Unable to remove directory ${dir}"
143 # Create build directory.
148 if test ! -r Makefile
150 # Default SIMOPTS to GDBOPTS.
151 test -z "${simopts}" && simopts="${gdbopts}"
153 # The config options.
154 __build="--enable-targets=all"
155 __enable_gdb_build_warnings=`test -z "${gdbopts}" \
156 || echo "--enable-gdb-build-warnings=${gdbopts}"`
157 __enable_sim_build_warnings=`test -z "${simopts}" \
158 || echo "--enable-sim-build-warnings=${simopts}"`
159 __configure="${srcdir}/configure \
160 ${__build} ${bfd_flag}\
161 ${__enable_gdb_build_warnings} \
162 ${__enable_sim_build_warnings}"
163 echo ... ${__configure}
164 trap "echo Removing partially configured ${dir} directory ...; rm -rf ${dir}; exit 1" 1 2 15
165 ${__configure} > Config.log 2>&1
168 # Without Makefile GDB won't build.
169 if test ! -r Makefile
171 echo "... CONFIG ERROR: GDB couldn't be configured " | tee -a Config.log
172 echo "... CONFIG ERROR: see Config.log for details "
177 # Build GDB, if not built.
179 if test ! -x gdb/gdb -a ! -x gdb/gdb.exe
181 echo ... ${make} ${makejobs}
182 ( ${make} ${makejobs} all-gdb || rm -f gdb/gdb gdb/gdb.exe
185 # If the build fails, exit.
186 if test ! -x gdb/gdb -a ! -x gdb/gdb.exe
188 echo "... BUILD ERROR: GDB couldn't be compiled " | tee -a Build.log
189 echo "... BUILD ERROR: see Build.log for details "
192 if test -x gdb/gdb.exe
194 gdb_bin="gdb/gdb.exe"
199 # Retrieve a list of settable architectures by invoking "set architecture"
200 # without parameters.
205 ./gdb/gdb --batch -nx -x arch 2>&1 | cat > gdb_archs
206 tail -n 1 gdb_archs | sed 's/auto./\n/g' | sed 's/,/\n/g' | sed 's/Requires an argument. Valid arguments are/\n/g' | sed '/^[ ]*$/d' > arch
209 if test "${targexp}" != ""
211 alltarg=`cat gdb_archs | grep ${targexp}`
213 alltarg=`cat gdb_archs`
217 # Test all architectures available in ALLTARG
218 echo "maint print architecture for"
219 echo "$alltarg" | while read target
222 set architecture ${target}
223 maint print architecture
227 log_file=${log_file//:/_}
228 echo -n "... ${target}"
229 ./gdb/gdb -batch -nx -x x 2>&1 | cat > $log_file
231 if test ! -s $log_file
233 echo " ERR: gdb printed no output" | tee -a $log_file
234 elif test `grep -o internal-error $log_file | tail -n 1`
236 echo " ERR: gdb panic" | tee -a $log_file
241 # Create a sed script that cleans up the output from GDB.
243 # Rules to replace <0xNNNN> with the corresponding function's name.
244 sed -n -e '/<0x0*>/d' -e 's/^.*<0x\([0-9a-f]*\)>.*$/0x\1/p' $log_file \
248 func="`addr2line -f -e ./$gdb_bin -s ${addr} | sed -n -e 1p`"
249 echo "s/<${addr}>/<${func}>/g"
251 # Rules to strip the leading paths off of file names.
252 echo 's/"\/.*\/gdb\//"gdb\//g' >> mbuild.sed
254 sed -f mbuild.sed $log_file > Mbuild.log
256 mv Mbuild.log ${builddir}/$log_file
257 rm -rf $log_file x mbuild.sed
261 # Clean up build directory if necessary.
264 echo "cleanning up $dir"