Teach abuild to emit JUnit formatted build reports
[coreboot.git] / util / abuild / abuild
1 #!/bin/bash
2 #
3 #  coreboot autobuild
4 #
5 #  This script builds coreboot images for all available targets.
6 #
7 #  (C) 2004 by Stefan Reinauer <stepan@openbios.org>
8 #  (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
9 #
10 #  This file is subject to the terms and conditions of the GNU General
11 #  Public License. See the file COPYING in the main directory of this
12 #  archive for more details.
13 #
14
15 #set -x # Turn echo on....
16
17 ABUILD_DATE="December 10th, 2010"
18 ABUILD_VERSION="0.9.1"
19
20 # Where shall we place all the build trees?
21 TARGET=coreboot-builds
22 XMLFILE=$( pwd )/abuild.xml
23
24 # path to payload. Should be more generic
25 PAYLOAD=/dev/null
26
27 # Lines of error context to be printed in FAILURE case
28 CONTEXT=6
29
30 TESTSUBMISSION="http://qa.coreboot.org/deployment/send.php"
31
32 # Number of CPUs to compile on per default
33 cpus=1
34
35 # Configure-only mode
36 configureonly=0
37
38 # Did any board fail to build?
39 failed=0
40
41 # One might want to adjust these in case of cross compiling
42 for i in make gmake gnumake nonexistant_make; do
43         $i --version 2>/dev/null |grep "GNU Make" >/dev/null && break
44 done
45 if [ "$i" = "nonexistant_make" ]; then
46         echo No GNU Make found.
47         exit 1
48 fi
49 MAKE=$i
50
51 # this can be changed to xml by -x
52 mode=text
53
54 # silent mode.. no compiler calls, only warnings in the log files.
55 # this is disabled per default but can be enabled with -s
56 silent=
57
58 # clang mode enabled by -sb option.
59 scanbuild=false
60
61 # use ccache
62 ccache=false
63
64 # stackprotect mode enabled by -ns option.
65 stackprotect=false
66
67 # loglevel changed with -l / --loglevel option
68 loglevel=default
69
70 # update existing image
71 update=false
72
73 # CBFS prefix
74 cbfs_prefix=fallback
75
76 ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
77         -e s/i86pc/i386/ \
78         -e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
79         -e "s/Power Macintosh/ppc/"`
80
81 trap interrupt INT
82
83 function interrupt
84 {
85         printf "\n$0: execution interrupted manually.\n"
86         if [ "$mode" == "xml" ]; then
87                 printf "$0: deleting incomplete xml output file.\n"
88         fi
89         exit 1
90 }
91
92 function debug
93 {
94         test "$verbose" == "true" && printf "$*\n"
95 }
96
97 function xml
98 {
99         test "$mode" == "xml" && printf "$*\n" >> $XMLFILE
100         return 0
101 }
102
103 function xmlfile
104 {
105         test "$mode" == "xml" && {
106                 printf '<![CDATA[\n'
107                 cat $1
108                 printf ']]>\n'
109         } >> $XMLFILE
110 }
111
112 function junit
113 {
114         test "$mode" == "junit" && printf "$*\n" >> $XMLFILE
115         return 0
116 }
117
118 function junitfile
119 {
120         test "$mode" == "junit" && {
121                 printf '<![CDATA[\n'
122                 cat $1
123                 printf ']]>\n'
124         } >> $XMLFILE
125 }
126
127
128 function vendors
129 {
130         # make this a function so we can easily select
131         # without breaking readability
132         ls -1 "$ROOT/src/mainboard" | grep -v Kconfig | grep -v Makefile
133 }
134
135 function mainboards
136 {
137         # make this a function so we can easily select
138         # without breaking readability
139
140         VENDOR=$1
141
142         ls -1 $ROOT/src/mainboard/$VENDOR | grep -v Kconfig
143 }
144
145 function architecture
146 {
147         VENDOR=$1
148         MAINBOARD=$2
149         ARCH=`cat $ROOT/src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
150                 grep "select ARCH_"|cut -f2- -d_`
151         echo $ARCH | sed s/X86/i386/
152 }
153
154 function create_config
155 {
156         VENDOR=$1
157         MAINBOARD=$2
158         CONFIG=$3
159
160         build_dir=$TARGET/${VENDOR}_${MAINBOARD}
161
162         # get a working payload for the board if we have one.
163         # the --payload option expects a directory containing
164         # a shell script payload.sh
165         #   Usage: payload.sh [VENDOR] [DEVICE]
166         # the script returns an absolute path to the payload binary.
167
168         if [ -f $payloads/payload.sh ]; then
169                 PAYLOAD=`sh $payloads/payload.sh $VENDOR $MAINBOARD`
170                 printf "Using payload $PAYLOAD\n"
171         fi
172
173         [ "$update" = "true" ] && mv ${build_dir}/coreboot.rom coreboot.rom.tmp
174         mkdir -p ${build_dir}
175         mkdir -p $TARGET/sharedutils
176         [ "$update" = "true" ] && mv coreboot.rom.tmp ${build_dir}/coreboot.rom
177
178         if [ "$CONFIG" != "" ]; then
179                 printf "  Using existing configuration $CONFIG ... "
180                 xml "  <config>$CONFIG</config>"
181                 cp src/mainboard/$VENDOR/$MAINBOARD/$CONFIG ${build_dir}/config.build
182         else
183                 printf "  Creating config file... "
184                 xml "  <config>autogenerated</config>"
185                 grep "if[\t ]*VENDOR" src/mainboard/$VENDOR/$MAINBOARD/../Kconfig | \
186                         sed "s,^.*\(VENDOR_.*\)[^A-Z0-9_]*,CONFIG_\1=y," > ${build_dir}/config.build
187                 grep "if[\t ]*BOARD" src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
188                         sed "s,^.*\(BOARD_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> ${build_dir}/config.build
189                 grep "select[\t ]*ARCH" src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
190                         sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> ${build_dir}/config.build
191                 echo "CONFIG_MAINBOARD_DIR=\"$VENDOR/$MAINBOARD\"" >> ${build_dir}/config.build
192                 echo "CONFIG_CBFS_PREFIX=\"$cbfs_prefix\"" >> ${build_dir}/config.build
193                 if [ "$PAYLOAD" != "/dev/null" ]; then
194                         echo "# CONFIG_PAYLOAD_NONE is not set" >> ${build_dir}/config.build
195                         echo "# CONFIG_PAYLOAD_SEABIOS is not set" >> ${build_dir}/config.build
196                         echo "CONFIG_PAYLOAD_ELF=y" >> ${build_dir}/config.build
197                         echo "CONFIG_PAYLOAD_FILE=\"$PAYLOAD\"" >> ${build_dir}/config.build
198                 fi
199
200                 if [ "$loglevel" != "default" ]; then
201                         printf "(loglevel override) "
202                         echo "CONFIG_MAXIMUM_CONSOLE_LOGLEVEL_$loglevel=y" >> ${build_dir}/config.build
203                         echo "CONFIG_MAXIMUM_CONSOLE_LOGLEVEL=$loglevel" >> ${build_dir}/config.build
204                         echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL_$loglevel=y" >> ${build_dir}/config.build
205                         echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$loglevel" >> ${build_dir}/config.build
206                 fi
207
208                 if [ "$update" != "false" ]; then
209                         printf "(update) "
210                         echo "CONFIG_UPDATE_IMAGE=y" >> ${build_dir}/config.build
211                 fi
212
213                 if [ "$ccache" = "true" ]; then
214                         printf "(ccache enabled) "
215                         echo "CONFIG_CCACHE=y" >> ${build_dir}/config.build
216                 fi
217
218                 if [ "$scanbuild" = "true" ]; then
219                         printf "(scan-build enabled) "
220                         echo "CONFIG_SCANBUILD_ENABLE=y" >> ${build_dir}/config.build
221                         echo "CONFIG_SCANBUILD_REPORT_LOCATION=\"$TARGET/scan-build-results-tmp\"" >> ${build_dir}/config.build
222                 fi
223         fi
224
225         #yes "" | $MAKE oldconfig -j $cpus obj=${build_dir} objutil=$TARGET/sharedutils &> ${build_dir}/config.log
226         yes "" | $MAKE oldconfig DOTCONFIG=${build_dir}/config.build obj=${build_dir} objutil=$TARGET/sharedutils &> ${build_dir}/config.log
227         ret=$?
228         if [ $ret -eq 0 ]; then
229                 printf "ok; "
230                 xml "  <builddir>ok</builddir>"
231                 xml "  <log>"
232                 xmlfile $build_dir/config.log
233                 xml "  </log>"
234                 xml ""
235                 return 0
236         else
237                 # Does this ever happen?
238                 printf "FAILED!\nLog excerpt:\n"
239                 xml "  <builddir>failed</builddir>"
240                 xml "  <log>"
241                 xmlfile $build_dir/config.log
242                 xml "  </log>"
243                 xml ""
244                 tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log
245                 return 1
246         fi
247 }
248
249 function create_buildenv
250 {
251         VENDOR=$1
252         MAINBOARD=$2
253         CONFIG=$3
254
255         create_config $VENDOR $MAINBOARD $CONFIG
256         ret=$?
257
258         # Allow simple "make" in the target directory
259         MAKEFILE=$TARGET/${VENDOR}_${MAINBOARD}/Makefile
260         echo "# autogenerated" > $MAKEFILE
261         echo "TOP=$ROOT" >> $MAKEFILE
262         echo "BUILD=$TARGET" >> $MAKEFILE
263         echo "OBJ=\$(BUILD)/${VENDOR}_${MAINBOARD}" >> $MAKEFILE
264         echo "OBJUTIL=\$(BUILD)/sharedutils" >> $MAKEFILE
265         echo "all:" >> $MAKEFILE
266         echo "  @cp -a config.h config.h.bak" >> $MAKEFILE
267         echo "  @cd \$(TOP); \$(MAKE) oldconfig DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> $MAKEFILE
268         echo "  @tail -n+6 config.h > config.new; tail -n+6 config.h.bak > config.old" >> $MAKEFILE
269         echo "  @cmp -s config.new config.old && cp -a config.h.bak config.h || echo \"Config file changed\"" >> $MAKEFILE
270         echo "  @rm config.h.bak config.new config.old" >> $MAKEFILE
271         echo "  @cd \$(TOP); \$(MAKE) DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> $MAKEFILE
272
273         return $ret
274 }
275
276 function compile_target
277 {
278         VENDOR=$1
279         MAINBOARD=$2
280
281         printf " Compiling image "
282         test "$cpus" == "" && printf "in parallel .. "
283         test "$cpus" == "1" && printf "on 1 cpu .. "
284         test 0$cpus -gt 1 && printf "on %d cpus in parallel .. " $cpus
285
286         CURR=$( pwd )
287         #stime=`perl -e 'print time();' 2>/dev/null || date +%s`
288         build_dir=$TARGET/${VENDOR}_${MAINBOARD}
289         eval $MAKE $silent -j $cpus DOTCONFIG=${build_dir}/config.build obj=${build_dir} objutil=$TARGET/sharedutils \
290                 &> ${build_dir}/make.log
291         ret=$?
292         mv .xcompile ${build_dir}/xcompile.build
293         cd $TARGET/${VENDOR}_${MAINBOARD}
294
295         etime=`perl -e 'print time();' 2>/dev/null || date +%s`
296         duration=$(( $etime - $stime ))
297         xml "  <buildtime>${duration}s</buildtime>"
298         junit " <testcase classname='board' name='$TARCH/$VENDOR/$MAINBOARD' time='$duration' >"
299
300         xml "  <log>"
301         xmlfile make.log
302         xml "  </log>"
303
304         if [ $ret -eq 0 ]; then
305                 xml "  <compile>ok</compile>"
306                 junit "<system-out>"
307                 junitfile make.log
308                 junit "</system-out>"
309                 printf "ok\n" > compile.status
310                 printf "ok. (took ${duration}s)\n"
311                 cd $CURR
312                 return 0
313         else
314                 xml "  <compile>failed</compile>"
315                 junit "<failure type='BuildFailed'>"
316                 junitfile make.log
317                 junit "</failure>"
318                 printf "FAILED after ${duration}s!\nLog excerpt:\n"
319                 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
320                 cd $CURR
321                 failed=1
322                 return 1
323         fi
324 }
325
326 function build_broken
327 {
328         CURR=`pwd`
329         status="yes"
330         [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
331         [ "$buildbroken" == "true" -o "$status" == "yes" ]
332 }
333
334 function build_target
335 {
336         VENDOR=$1
337         MAINBOARD=$2
338         CONFIG=$3
339         TARCH=$( architecture $VENDOR $MAINBOARD )
340
341         # Allow architecture override in an abuild.info file.
342         # This is used for the Motorola Sandpoint, which is not a real target
343         # but a skeleton target for the Sandpoint X3.
344         [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
345                 source $ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
346
347         # default setting
348
349         CC="${CROSS_COMPILE}gcc"
350         CROSS_COMPILE=""
351         found_crosscompiler=false
352         if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
353                 # i386-elf target needs --divide, for i386-linux, that's the default
354                 if [ "$TARCH" = "i386" ]; then
355                         CC="$CC -Wa,--divide"
356                 fi
357                 CROSS_COMPILE="$TARCH-elf-"
358                 CC=gcc
359                 CROSS_TEXT=", using $CROSS_COMPILE$CC"
360                 found_crosscompiler=true
361         fi
362
363         HOSTCC='gcc'
364
365         printf "Building $VENDOR/$MAINBOARD; "
366
367         xml "<mainboard>"
368         xml ""
369         xml "  <vendor>$VENDOR</vendor>"
370         xml "  <device>$MAINBOARD</device>"
371         xml ""
372         xml "  <architecture>$TARCH</architecture>"
373         xml ""
374
375         if [ "$ARCH" = "$TARCH" -o $found_crosscompiler = true ]; then
376                 printf "$TARCH: ok$CROSS_TEXT\n"
377         else
378                 # FIXME this is basically the same as above.
379                 found_crosscompiler=false
380                 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
381                         CC="gcc -m32"
382                         found_crosscompiler=true
383                 fi
384                 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
385                         CC="gcc -m32"
386                         found_crosscompiler=true
387                 fi
388                 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
389                         for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
390                             powerpc-7450-linux-gnu- powerpc-elf-; do
391                                 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
392                                         found_crosscompiler=true
393                                         CROSS_COMPILE=$prefix
394                                 fi
395                         done
396                 fi
397
398
399                 # TBD: look for suitable cross compiler suite
400                 # cross-$TARCH-gcc and cross-$TARCH-ld
401
402                 # Check result:
403                 if [ $found_crosscompiler == "false" ]; then
404                         printf "$TARCH: skipped, we're $ARCH\n\n"
405                         xml "  <status>notbuilt</status>"
406                         xml ""
407                         xml "</mainboard>"
408
409                         junit " <testcase classname='board' name='$TARCH/$VENDOR/$MAINBOARD' >"
410                         junit "<failure type='NoCrossCompiler'>No cross-compiler for $TARCH found</failure>"
411
412                         return 0
413                 else
414                         printf "$TARCH: ok, $ARCH using ${CROSS_COMPILE}gcc\n"
415                         xml "  <compiler>"
416                         xml "    <path>`which ${CROSS_COMPILE}gcc`</path>"
417                         xml "    <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
418                         xml "  </compiler>"
419                         xml ""
420                 fi
421         fi
422
423         CC=${CROSS_COMPILE}$CC
424
425         if  [ "$stackprotect" = "true" ]; then
426                 CC="$CC -fno-stack-protector"
427         fi
428
429         build_broken $VENDOR $MAINBOARD || \
430         {
431                 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
432                 xml "  <status>knownbroken</status>"
433                 xml ""
434                 xml "</mainboard>"
435                 junit " <testcase classname='board' name='$TARCH/$VENDOR/$MAINBOARD' >"
436                 junit "<failure type='KnownBroken'>Board is marked as broken</failure>"
437                 return 0
438         }
439
440         stime=`perl -e 'print time();' 2>/dev/null || date +%s`
441         create_buildenv $VENDOR $MAINBOARD $CONFIG
442         if [ $? -eq 0  -a  $configureonly -eq 0 ]; then
443                 if [ "$scanbuild" = "true" ]; then
444                         rm -rf $TARGET/scan-build-results-tmp
445                 fi
446                 compile_target $VENDOR $MAINBOARD &&
447                         xml "  <status>ok</status>" ||
448                         xml "<status>broken</status>"
449                 if [ "$scanbuild" = "true" ]; then
450                         rm -rf $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
451                         mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
452                 fi
453         fi
454         # Not calculated here because we still print it in compile_target
455         #etime=`perl -e 'print time();' 2>/dev/null || date +%s`
456         #duration=$(( $etime - $stime ))
457         #xml "  <buildtime>${duration}s</buildtime>"
458
459         xml ""
460         xml "</mainboard>"
461         junit "</testcase>"
462
463         printf "\n"
464 }
465
466 function test_target
467 {
468         VENDOR=$1
469         MAINBOARD=$2
470
471         if [ "$hwtest" != "true" ]; then
472                 return 0
473         fi
474
475         # image does not exist. we silently skip the patch.
476         if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
477                 return 0
478         fi
479
480         which curl &> /dev/null
481         if [ $? != 0 ]; then
482                 printf "curl is not installed but required for test submission.  skipping test.\n\n"
483                 return 0
484         fi
485
486         CURR=`pwd`
487         if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
488                 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
489                 return 0
490         fi
491         # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
492
493         printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
494
495         curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
496                 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
497                 "http://qa.coreboot.org/deployment/send.php"
498
499         printf "\n"
500         return 0
501 }
502
503 function remove_target
504 {
505         if [ "$remove" != "true" ]; then
506                 return 0
507         fi
508
509         VENDOR=$1
510         MAINBOARD=$2
511
512         # Save the generated coreboot.rom file of each board.
513         if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
514                 cp $TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom \
515                    ${VENDOR}_${MAINBOARD}_coreboot.rom
516         fi
517
518         printf "Removing build dir for board $VENDOR $MAINBOARD...\n"
519         rm -rf $TARGET/${VENDOR}_${MAINBOARD}
520
521         return 0
522 }
523
524 function myhelp
525 {
526         printf "Usage: $0 [-v] [-a] [-b] [-r] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
527         printf "       $0 [-V|--version]\n"
528         printf "       $0 [-h|--help]\n\n"
529
530         printf "Options:\n"
531         printf "    [-v|--verbose]                print more messages\n"
532         printf "    [-a|--all]                    build previously succeeded ports as well\n"
533         printf "    [-b|--broken]                 attempt to build ports that are known broken\n"
534         printf "    [-r|--remove]                 remove output dir after build\n"
535         printf "    [-t|--target <vendor/board>]  attempt to build target vendor/board only\n"
536         printf "    [-p|--payloads <dir>]         use payloads in <dir> to build images\n"
537         printf "    [-V|--version]                print version number and exit\n"
538         printf "    [-h|--help]                   print this help and exit\n"
539         printf "    [-x|--xml]                    write xml log file \n"
540         printf "                                  (defaults to $XMLFILE)\n"
541         printf "    [-J|--junit]                  write JUnit formatted xml log file \n"
542         printf "                                  (defaults to $XMLFILE)\n"
543         printf "    [-T|--test]                   submit image(s) to automated test system\n"
544         printf "    [-c|--cpus <numcpus>]         build on <numcpus> at the same time\n"
545         printf "    [-s|--silent]                 omit compiler calls in logs\n"
546         printf "    [-ns|--nostackprotect]        use gcc -fno-stack-protector option\n"
547         printf "    [-sb|--scan-build]            use clang's static analyzer\n"
548         printf "    [-y|--ccache]                 use ccache\n"
549         printf "    [-C|--config]                 configure-only mode\n"
550         printf "    [-l|--loglevel <num>]         set loglevel\n"
551         printf "    [-u|--update]                 update existing image\n"
552         printf "    [-P|--prefix <name>]          file name prefix in CBFS\n"
553         printf "    [lbroot]                      absolute path to coreboot sources\n"
554         printf "                                  (defaults to $ROOT)\n\n"
555 }
556
557 function myversion
558 {
559         cat << EOF
560
561 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
562
563 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
564 Copyright (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
565
566 This program is free software; you may redistribute it under the terms
567 of the GNU General Public License. This program has absolutely no
568 warranty.
569
570 EOF
571 }
572
573 # default options
574 target=""
575 buildall=false
576 verbose=false
577
578 test -f util/sconfig/sconfig.l && ROOT=$( pwd )
579 test -f ../util/sconfig/sconfig.l && ROOT=$( cd ..; pwd )
580 test "$ROOT" = "" && ROOT=$( cd ../..; pwd )
581
582 # parse parameters.. try to find out whether we're running GNU getopt
583 getoptbrand="`getopt -V`"
584 if [ "${getoptbrand:0:6}" == "getopt" ]; then
585         # Detected GNU getopt that supports long options.
586         args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,junit,xml,config,loglevel:,remove,prefix:,update,nostackprotect,scan-build,ccache -o Vvhat:bp:Tc:sJxCl:rP:uy -- "$@"`
587         eval set -- $args
588 else
589         # Detected non-GNU getopt
590         args=`getopt Vvhat:bp:Tc:sJxCl:rP:uy $*`
591         set -- $args
592 fi
593
594 if [ $? != 0 ]; then
595         myhelp
596         exit 1
597 fi
598
599 while true ; do
600         case "$1" in
601                 -x|--xml)       shift; mode=xml; rm -f $XMLFILE ;;
602                 -J|--junit)     shift; mode=junit; rm -f $XMLFILE ;;
603                 -t|--target)    shift; target="$1"; shift;;
604                 -a|--all)       shift; buildall=true;;
605                 -b|--broken)    shift; buildbroken=true;;
606                 -r|--remove)    shift; remove=true;;
607                 -v|--verbose)   shift; verbose=true; silent='V=1';;
608                 -V|--version)   shift; myversion; exit 0;;
609                 -h|--help)      shift; myversion; myhelp; exit 0;;
610                 -p|--payloads)  shift; payloads="$1"; shift;;
611                 -T|--test)      shift; hwtest=true;;
612                 -c|--cpus)      shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
613                 -s|--silent)    shift; silent="-s";;
614                 -ns|--nostackprotect) shift; stackprotect=true;;
615                 -sb|--scan-build) shift; scanbuild=true;;
616                 -y|--ccache)    shift; ccache=true;;
617                 -C|--config)    shift; configureonly=1;;
618                 -l|--loglevel)  shift; loglevel="$1"; shift;;
619                 -u|--update)    shift; update="true";;
620                 -P|--prefix)    shift; cbfs_prefix="$1"; shift;;
621                 --)             shift; break;;
622                 -*)             printf "Invalid option\n\n"; myhelp; exit 1;;
623                 *)              break;;
624         esac
625 done
626
627 # /path/to/freebios2/
628 test -z "$1" || ROOT=$1
629
630 debug "ROOT=$ROOT"
631
632 xml '<?xml version="1.0" encoding="utf-8"?>'
633 xml '<abuild>'
634
635 junit '<?xml version="1.0" encoding="utf-8"?>'
636 junit '<testsuite>'
637
638 if [ "$target" != "" ]; then
639         # build a single board
640         VENDOR=`printf $target|cut -f1 -d/`
641         MAINBOARD=`printf $target|cut -f2 -d/`
642         CONFIG=`printf $target|cut -f3 -d/`
643         if [ ! -r $ROOT/src/mainboard/$target ]; then
644                 printf "No such target: $target\n"
645                 xml '</abuild>'
646                 junit '</testsuite>'
647                 exit 1
648         fi
649         build_target $VENDOR $MAINBOARD $CONFIG
650         test_target $VENDOR $MAINBOARD
651 else
652         # build all boards per default
653         for VENDOR in $( vendors ); do
654                 for MAINBOARD in $( mainboards $VENDOR ); do
655                         build_target $VENDOR $MAINBOARD
656                         test_target $VENDOR $MAINBOARD
657                         remove_target $VENDOR $MAINBOARD
658                 done
659         done
660 fi
661 xml '</abuild>'
662 junit '</testsuite>'
663
664 exit $failed