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