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