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