* gdb_mbuild.sh: New file.
[external/binutils.git] / gdb / gdb_mbuild.sh
1 #!/bin/sh
2
3 #  Multi-build script for testing compilation of all maintained configs of GDB.
4 #  Copyright (C) 2002  Free Software Foundation, Inc.
5 #  Contributed by Richard Earnshaw  (rearnsha@arm.com)
6
7 #  This program is free software; you can redistribute it and/or modify
8 #  it under the terms of the GNU General Public License as published by
9 #  the Free Software Foundation; either version 2 of the License, or
10 #  (at your option) any later version.
11
12 #  This program is distributed in the hope that it will be useful,
13 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #  GNU General Public License for more details.
16
17 #  You should have received a copy of the GNU General Public License
18 #  along with this program; if not, write to the Free Software
19 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 usage() {
22     echo "Usage: gdb_mbuild.sh <srcdir> <builddir> [<parjobs>]"
23     echo " Environment variables examined (with default if not defined):"
24     echo "  AWK (awk) -- must be GNU awk"
25     echo "  MAKE (make)"
26     echo
27     echo " Note: Everything in <builddir>/gdb-allcross will be blown away.
28     exit 1;
29 }
30
31 if [ $# -ne 2 -a $# -ne 3 ] ; then
32     usage
33 fi
34
35 ### COMMAND LINE PARAMETERS
36
37 # Where the sources live
38 srcdir=$1
39
40 # Where the builds occur
41 buildbase=$2
42
43 # Number of parallel make jobs (you probably want about 2 jobs per cpu for
44 # maximum throughput)
45 if [ $# -eq 3 ]; then
46     par=$3
47 else
48     par="1"
49 fi
50
51 ### ENVIRONMENT PARAMETERS
52 # Must be GNU awk
53 awk=${AWK:-awk}
54
55 # Version of make to use
56 make=${MAKE:-make}
57
58
59 # Where builds will live
60 builddir=${buildbase}/gdb-allcross
61
62 # Where logs will go.  NB. Must not be a sub-dir of builddir or you will loose
63 # them.
64 logdir=${buildbase}/gdb-logdir
65
66 # Where to look for the list of targets to test
67 maintainers=${srcdir}/gdb/MAINTAINERS
68
69 # Get the list of targets and the build options
70 alltarg=`${awk} < "${maintainers}" '
71   $2 ~ /--target=.*/ {
72     targets = gensub (/^.*--target=/, "", 1, $2)
73     warnings = gensub (/[)]*$/, "", 1, $3)
74     split (targets, targ, /,/)
75     for (i in targ) {
76         print targ[i], warnings
77     }
78   }'`
79
80 # Back up the log files
81 cd ${logdir}
82
83 if [ -f build.out ]
84 then
85         mv build.out build.old
86 fi
87 if [ -f config.out ]
88 then
89         mv config.out config.old
90 fi
91 if [ -f fail.sum ]
92 then
93         mv fail.sum fail.old
94 fi
95
96 if [ ! -d ${builddir} ]
97 then
98         echo ${builddir} does not exist
99         exit 1
100 fi
101
102 cd ${builddir}
103 rm -rf *
104
105 MAKE=${make}
106 export MAKE
107
108 jobs=1
109 # For each target, configure and build it.
110 while read targ opts
111 do
112         if [ ${opts} != "broken" ]
113         then
114                 trap 'echo cleaning up ...; rm -rf ${builddir}/*; exit 1' 1 2 15
115                 echo ${targ}
116                 mkdir ${targ}
117                 cd ${targ}
118                 ${srcdir}/configure --target=$targ \
119                   --enable-gdb-build-warnings=$opts \
120                   >> ${logdir}/config.tout.$targ 2>&1 &
121                 cd ..
122                 jobs=`expr ${jobs} + 1`
123                 if [ ${jobs} -gt ${par} ]
124                 then
125                         wait
126                         jobs=1
127                 fi
128         fi
129 done << EOF
130 $alltarg
131 EOF
132
133 wait
134
135 cat ${logdir}/config.tout.* > ${logdir}/config.out
136 rm -f ${logdir}/config.tout.*
137
138 for targ in *
139 do
140         cd $targ
141         if  ${make} -j ${par} all-gdb >> ${logdir}/build.out 2>&1
142         then
143                 true
144         else
145                 echo ">>>>>>>>>>>>>" >> ${logdir}/fail.sum
146                 echo "$targ (${opts})" >> ${logdir}/fail.sum 
147                 tail -20 ${logdir}/build.out >> ${logdir}/fail.sum
148                 echo >> ${logdir}/fail.sum
149                 echo $targ build failed
150         fi
151         rm -rf *
152         cd ..
153 done