Drop support for BROKEN marker
[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_target
330 {
331         VENDOR=$1
332         MAINBOARD=$2
333         CONFIG=$3
334         TARCH=$( architecture $VENDOR $MAINBOARD )
335
336         # Allow architecture override in an abuild.info file.
337         # This is used for the Motorola Sandpoint, which is not a real target
338         # but a skeleton target for the Sandpoint X3.
339         [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
340                 source $ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
341
342         # default setting
343
344         CC="${CROSS_COMPILE}gcc"
345         CROSS_COMPILE=""
346         found_crosscompiler=false
347         if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
348                 # i386-elf target needs --divide, for i386-linux, that's the default
349                 if [ "$TARCH" = "i386" ]; then
350                         CC="$CC -Wa,--divide"
351                 fi
352                 CROSS_COMPILE="$TARCH-elf-"
353                 CC=gcc
354                 CROSS_TEXT=", using $CROSS_COMPILE$CC"
355                 found_crosscompiler=true
356         fi
357
358         HOSTCC='gcc'
359
360         printf "Building $VENDOR/$MAINBOARD; "
361         XMLFILE=$TOP/$TARGET/${VENDOR}_${MAINBOARD}/abuild.xml
362
363         xml "<mainboard>"
364         xml ""
365         xml "  <vendor>$VENDOR</vendor>"
366         xml "  <device>$MAINBOARD</device>"
367         xml ""
368         xml "  <architecture>$TARCH</architecture>"
369         xml ""
370
371         if [ "$ARCH" = "$TARCH" -o $found_crosscompiler = true ]; then
372                 printf "$TARCH: ok$CROSS_TEXT\n"
373         else
374                 # FIXME this is basically the same as above.
375                 found_crosscompiler=false
376                 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
377                         CC="gcc -m32"
378                         found_crosscompiler=true
379                 fi
380                 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
381                         CC="gcc -m32"
382                         found_crosscompiler=true
383                 fi
384                 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
385                         for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
386                             powerpc-7450-linux-gnu- powerpc-elf-; do
387                                 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
388                                         found_crosscompiler=true
389                                         CROSS_COMPILE=$prefix
390                                 fi
391                         done
392                 fi
393
394
395                 # TBD: look for suitable cross compiler suite
396                 # cross-$TARCH-gcc and cross-$TARCH-ld
397
398                 # Check result:
399                 if [ $found_crosscompiler == "false" ]; then
400                         printf "$TARCH: skipped, we're $ARCH\n\n"
401                         xml "  <status>notbuilt</status>"
402                         xml ""
403                         xml "</mainboard>"
404
405                         junit " <testcase classname='board' name='$TARCH/$VENDOR/$MAINBOARD' >"
406                         junit "<failure type='NoCrossCompiler'>No cross-compiler for $TARCH found</failure>"
407
408                         return 0
409                 else
410                         printf "$TARCH: ok, $ARCH using ${CROSS_COMPILE}gcc\n"
411                         xml "  <compiler>"
412                         xml "    <path>`which ${CROSS_COMPILE}gcc`</path>"
413                         xml "    <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
414                         xml "  </compiler>"
415                         xml ""
416                 fi
417         fi
418
419         CC=${CROSS_COMPILE}$CC
420
421         if  [ "$stackprotect" = "true" ]; then
422                 CC="$CC -fno-stack-protector"
423         fi
424
425         stime=`perl -e 'print time();' 2>/dev/null || date +%s`
426         create_buildenv $VENDOR $MAINBOARD $CONFIG
427         if [ $? -eq 0  -a  $configureonly -eq 0 ]; then
428                 if [ "$scanbuild" = "true" ]; then
429                         rm -rf $TARGET/scan-build-results-tmp
430                 fi
431                 compile_target $VENDOR $MAINBOARD &&
432                         xml "  <status>ok</status>" ||
433                         xml "<status>broken</status>"
434                 if [ "$scanbuild" = "true" ]; then
435                         rm -rf $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
436                         mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
437                 fi
438         fi
439         # Not calculated here because we still print it in compile_target
440         #etime=`perl -e 'print time();' 2>/dev/null || date +%s`
441         #duration=$(( $etime - $stime ))
442         #xml "  <buildtime>${duration}s</buildtime>"
443
444         xml ""
445         xml "</mainboard>"
446         junit "</testcase>"
447
448         printf "\n"
449 }
450
451 function test_target
452 {
453         VENDOR=$1
454         MAINBOARD=$2
455
456         if [ "$hwtest" != "true" ]; then
457                 return 0
458         fi
459
460         # image does not exist. we silently skip the patch.
461         if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
462                 return 0
463         fi
464
465         which curl &> /dev/null
466         if [ $? != 0 ]; then
467                 printf "curl is not installed but required for test submission.  skipping test.\n\n"
468                 return 0
469         fi
470
471         CURR=`pwd`
472         if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
473                 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
474                 return 0
475         fi
476         # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
477
478         printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
479
480         curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
481                 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
482                 "http://qa.coreboot.org/deployment/send.php"
483
484         printf "\n"
485         return 0
486 }
487
488 function remove_target
489 {
490         if [ "$remove" != "true" ]; then
491                 return 0
492         fi
493
494         VENDOR=$1
495         MAINBOARD=$2
496
497         # Save the generated coreboot.rom file of each board.
498         if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
499                 cp $TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom \
500                    ${VENDOR}_${MAINBOARD}_coreboot.rom
501         fi
502
503         printf "Removing build dir for board $VENDOR $MAINBOARD...\n"
504         rm -rf $TARGET/${VENDOR}_${MAINBOARD}
505
506         return 0
507 }
508
509 function myhelp
510 {
511         printf "Usage: $0 [-v] [-a] [-b] [-r] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
512         printf "       $0 [-V|--version]\n"
513         printf "       $0 [-h|--help]\n\n"
514
515         printf "Options:\n"
516         printf "    [-v|--verbose]                print more messages\n"
517         printf "    [-a|--all]                    build previously succeeded ports as well\n"
518         printf "    [-r|--remove]                 remove output dir after build\n"
519         printf "    [-t|--target <vendor/board>]  attempt to build target vendor/board only\n"
520         printf "    [-p|--payloads <dir>]         use payloads in <dir> to build images\n"
521         printf "    [-V|--version]                print version number and exit\n"
522         printf "    [-h|--help]                   print this help and exit\n"
523         printf "    [-x|--xml]                    write xml log file \n"
524         printf "                                  (defaults to $XMLFILE)\n"
525         printf "    [-J|--junit]                  write JUnit formatted xml log file \n"
526         printf "                                  (defaults to $XMLFILE)\n"
527         printf "    [-T|--test]                   submit image(s) to automated test system\n"
528         printf "    [-c|--cpus <numcpus>]         build on <numcpus> at the same time\n"
529         printf "    [-s|--silent]                 omit compiler calls in logs\n"
530         printf "    [-ns|--nostackprotect]        use gcc -fno-stack-protector option\n"
531         printf "    [-sb|--scan-build]            use clang's static analyzer\n"
532         printf "    [-y|--ccache]                 use ccache\n"
533         printf "    [-C|--config]                 configure-only mode\n"
534         printf "    [-l|--loglevel <num>]         set loglevel\n"
535         printf "    [-u|--update]                 update existing image\n"
536         printf "    [-P|--prefix <name>]          file name prefix in CBFS\n"
537         printf "    [lbroot]                      absolute path to coreboot sources\n"
538         printf "                                  (defaults to $ROOT)\n\n"
539 }
540
541 function myversion
542 {
543         cat << EOF
544
545 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
546
547 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
548 Copyright (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
549
550 This program is free software; you may redistribute it under the terms
551 of the GNU General Public License. This program has absolutely no
552 warranty.
553
554 EOF
555 }
556
557 # default options
558 target=""
559 buildall=false
560 verbose=false
561
562 test -f util/sconfig/sconfig.l && ROOT=$( pwd )
563 test -f ../util/sconfig/sconfig.l && ROOT=$( cd ..; pwd )
564 test "$ROOT" = "" && ROOT=$( cd ../..; pwd )
565
566 # parse parameters.. try to find out whether we're running GNU getopt
567 getoptbrand="`getopt -V`"
568 if [ "${getoptbrand:0:6}" == "getopt" ]; then
569         # Detected GNU getopt that supports long options.
570         args=`getopt -l version,verbose,help,all,target:,payloads:,test,cpus:,silent,junit,xml,config,loglevel:,remove,prefix:,update,nostackprotect,scan-build,ccache -o Vvhat:p:Tc:sJxCl:rP:uy -- "$@"`
571         eval set -- $args
572 else
573         # Detected non-GNU getopt
574         args=`getopt Vvhat:bp:Tc:sJxCl:rP:uy $*`
575         set -- $args
576 fi
577
578 if [ $? != 0 ]; then
579         myhelp
580         exit 1
581 fi
582
583 while true ; do
584         case "$1" in
585                 -x|--xml)       shift; mode=xml; rm -f $XMLFILE ;;
586                 -J|--junit)     shift; mode=junit; rm -f $XMLFILE ;;
587                 -t|--target)    shift; target="$1"; shift;;
588                 -a|--all)       shift; buildall=true;;
589                 -r|--remove)    shift; remove=true;;
590                 -v|--verbose)   shift; verbose=true; silent='V=1';;
591                 -V|--version)   shift; myversion; exit 0;;
592                 -h|--help)      shift; myversion; myhelp; exit 0;;
593                 -p|--payloads)  shift; payloads="$1"; shift;;
594                 -T|--test)      shift; hwtest=true;;
595                 -c|--cpus)      shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
596                 -s|--silent)    shift; silent="-s";;
597                 -ns|--nostackprotect) shift; stackprotect=true;;
598                 -sb|--scan-build) shift; scanbuild=true;;
599                 -y|--ccache)    shift; ccache=true;;
600                 -C|--config)    shift; configureonly=1;;
601                 -l|--loglevel)  shift; loglevel="$1"; shift;;
602                 -u|--update)    shift; update="true";;
603                 -P|--prefix)    shift; cbfs_prefix="$1"; shift;;
604                 --)             shift; break;;
605                 -*)             printf "Invalid option\n\n"; myhelp; exit 1;;
606                 *)              break;;
607         esac
608 done
609
610 if [ "$cpus" != "1" ]; then
611         export MAKEFLAGS="-j $cpus"
612 fi
613
614 # /path/to/freebios2/
615 test -z "$1" || ROOT=$1
616
617 debug "ROOT=$ROOT"
618
619 xml '<?xml version="1.0" encoding="utf-8"?>'
620 xml '<abuild>'
621
622 junit '<?xml version="1.0" encoding="utf-8"?>'
623 junit '<testsuite>'
624
625 if [ "$target" != "" ]; then
626         # build a single board
627         VENDOR=`printf $target|cut -f1 -d/`
628         MAINBOARD=`printf $target|cut -f2 -d/`
629         CONFIG=`printf $target|cut -f3 -d/`
630         if [ ! -r $ROOT/src/mainboard/$target ]; then
631                 printf "No such target: $target\n"
632                 xml '</abuild>'
633                 junit '</testsuite>'
634                 exit 1
635         fi
636         build_target $VENDOR $MAINBOARD $CONFIG
637         test_target $VENDOR $MAINBOARD
638         test "$mode" != "text" && cat $TARGET/${VENDOR}_${MAINBOARD}/abuild.xml >> $REAL_XMLFILE
639         XMLFILE=$REAL_XMLFILE
640 else
641         # build all boards per default
642         for VENDOR in $( vendors ); do
643                 for MAINBOARD in $( mainboards $VENDOR ); do
644                         build_target $VENDOR $MAINBOARD
645                         test_target $VENDOR $MAINBOARD
646                         remove_target $VENDOR $MAINBOARD
647                 done
648         done
649         if [ "$mode" != "text" ]; then
650                 for xmlfile in $TARGET/*_*/abuild.xml; do
651                         cat $xmlfile >> $REAL_XMLFILE
652                 done
653         fi
654         XMLFILE=$REAL_XMLFILE
655 fi
656 xml '</abuild>'
657 junit '</testsuite>'
658
659 exit $failed