]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/gdb_buildall.sh
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / gdb_buildall.sh
1 #!/bin/sh
2
3 # Build script to build GDB with all targets enabled.
4
5 # Copyright (C) 2008-2021 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.
10 #
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.
15 #
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/>.
18
19 # Make certain that the script is not running in an internationalized
20 # environment. The script is grepping for GDB's output.
21
22 # Contributed by Markus Deuling <deuling@de.ibm.com>.
23 # Based on gdb_mbuild.sh from Richard Earnshaw.
24
25
26 LANG=c ; export LANG
27 LC_ALL=c ; export LC_ALL
28
29 # Prints a usage message.
30 usage()
31 {
32 cat <<EOF
33 Usage: gdb_buildall.sh [ <options> ... ] <srcdir> <builddir>
34
35 Options:
36
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.
43 Arguments:
44 <srcdir> Source code directory.
45 <builddir> Build directory.
46
47 Environment variables examined (with default if not defined):
48 MAKE (make)"
49 EOF
50 exit 1
51 }
52
53 ### Command line options.
54 makejobs=
55 force=false
56 targexp=""
57 bfd_flag=""
58 clean=false
59 while test $# -gt 0
60 do
61 case "$1" in
62 -j )
63 # Number of parallel make jobs.
64 shift
65 test $# -ge 1 || usage
66 makejobs="-j $1"
67 ;;
68 --clean )
69 # Shall the build directory be deleted after processing?
70 clean=true
71 ;;
72 -e )
73 # A regular expression for selecting targets
74 shift
75 test $# -ge 1 || usage
76 targexp="${targexp} -e ${1}"
77 ;;
78 --force )
79 # Force a rebuild
80 force=true ;
81 ;;
82 --bfd64)
83 # Enable 64-bit BFD
84 bfd_flag="--enable-64-bit-bfd"
85 ;;
86 -* ) usage ;;
87 *) break ;;
88 esac
89 shift
90 done
91
92 if test $# -ne 2
93 then
94 usage
95 fi
96
97 ### Environment.
98
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
103 make=${MAKE:-make}
104 MAKE=${make}
105 export MAKE
106 # We don't want GDB do dump cores.
107 ulimit -c 0
108
109 # Just make sure we're in the right directory.
110 maintainers=${srcdir}/gdb/MAINTAINERS
111 if [ ! -r ${maintainers} ]
112 then
113 echo Maintainers file ${maintainers} not found
114 exit 1
115 fi
116
117
118 # Build GDB with all targets enabled.
119 echo "Starting gdb_buildall.sh ..."
120
121 trap "exit 1" 1 2 15
122 dir=${builddir}/ALL
123
124 # Should a scratch rebuild be forced, for perhaps the entire build be skipped?
125 if ${force}
126 then
127 echo ... forcing rebuild
128 rm -rf ${dir}
129 fi
130
131 # Did the previous configure attempt fail? If it did restart from scratch
132 if test -d ${dir} -a ! -r ${dir}/Makefile
133 then
134 echo ... removing partially configured
135 rm -rf ${dir}
136 if test -d ${dir}
137 then
138 echo "... ERROR: Unable to remove directory ${dir}"
139 exit 1
140 fi
141 fi
142
143 # Create build directory.
144 mkdir -p ${dir}
145 cd ${dir} || exit 1
146
147 # Configure GDB.
148 if test ! -r Makefile
149 then
150 # Default SIMOPTS to GDBOPTS.
151 test -z "${simopts}" && simopts="${gdbopts}"
152
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
166 trap "exit 1" 1 2 15
167
168 # Without Makefile GDB won't build.
169 if test ! -r Makefile
170 then
171 echo "... CONFIG ERROR: GDB couldn't be configured " | tee -a Config.log
172 echo "... CONFIG ERROR: see Config.log for details "
173 exit 1
174 fi
175 fi
176
177 # Build GDB, if not built.
178 gdb_bin="gdb/gdb"
179 if test ! -x gdb/gdb -a ! -x gdb/gdb.exe
180 then
181 echo ... ${make} ${makejobs}
182 ( ${make} ${makejobs} all-gdb || rm -f gdb/gdb gdb/gdb.exe
183 ) > Build.log 2>&1
184
185 # If the build fails, exit.
186 if test ! -x gdb/gdb -a ! -x gdb/gdb.exe
187 then
188 echo "... BUILD ERROR: GDB couldn't be compiled " | tee -a Build.log
189 echo "... BUILD ERROR: see Build.log for details "
190 exit 1
191 fi
192 if test -x gdb/gdb.exe
193 then
194 gdb_bin="gdb/gdb.exe"
195 fi
196 fi
197
198
199 # Retrieve a list of settable architectures by invoking "set architecture"
200 # without parameters.
201 cat <<EOF > arch
202 set architecture
203 quit
204 EOF
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
207 mv arch gdb_archs
208
209 if test "${targexp}" != ""
210 then
211 alltarg=`cat gdb_archs | grep ${targexp}`
212 else
213 alltarg=`cat gdb_archs`
214 fi
215 rm -f gdb_archs
216
217 # Test all architectures available in ALLTARG
218 echo "maint print architecture for"
219 echo "$alltarg" | while read target
220 do
221 cat <<EOF > x
222 set architecture ${target}
223 maint print architecture
224 quit
225 EOF
226 log_file=$target.log
227 log_file=${log_file//:/_}
228 echo -n "... ${target}"
229 ./gdb/gdb -batch -nx -x x 2>&1 | cat > $log_file
230 # Check GDBs results
231 if test ! -s $log_file
232 then
233 echo " ERR: gdb printed no output" | tee -a $log_file
234 elif test `grep -o internal-error $log_file | tail -n 1`
235 then
236 echo " ERR: gdb panic" | tee -a $log_file
237 else
238 echo " OK"
239 fi
240
241 # Create a sed script that cleans up the output from GDB.
242 rm -f mbuild.sed
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 \
245 | sort -u \
246 | while read addr
247 do
248 func="`addr2line -f -e ./$gdb_bin -s ${addr} | sed -n -e 1p`"
249 echo "s/<${addr}>/<${func}>/g"
250 done >> mbuild.sed
251 # Rules to strip the leading paths off of file names.
252 echo 's/"\/.*\/gdb\//"gdb\//g' >> mbuild.sed
253 # Run the script.
254 sed -f mbuild.sed $log_file > Mbuild.log
255
256 mv Mbuild.log ${builddir}/$log_file
257 rm -rf $log_file x mbuild.sed
258 done
259 echo "done."
260
261 # Clean up build directory if necessary.
262 if ${clean}
263 then
264 echo "cleanning up $dir"
265 rm -rf ${dir}
266 fi
267
268 exit 0