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