2004-10-19 09:00:47 +02:00
#!/bin/bash
#
2008-01-18 16:08:58 +01:00
# coreboot autobuild
2004-10-19 09:00:47 +02:00
#
2008-01-18 16:08:58 +01:00
# This script builds coreboot images for all available targets.
2004-10-19 09:00:47 +02:00
#
# (C) 2004 by Stefan Reinauer <stepan@openbios.org>
2010-01-30 11:44:28 +01:00
# (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
2014-12-08 09:57:52 +01:00
# (C) 2013-2014 Sage Electronic Engineering, LLC
2014-05-21 22:48:35 +02:00
# (C) 2014 Patrick Georgi <patrick@georgi-clan.de>
2004-10-19 09:00:47 +02:00
#
# This file is subject to the terms and conditions of the GNU General
# Public License. See the file COPYING in the main directory of this
# archive for more details.
2010-04-27 08:56:47 +02:00
#
2004-10-19 09:00:47 +02:00
2004-11-05 09:50:54 +01:00
#set -x # Turn echo on....
2004-10-21 23:41:57 +02:00
2015-10-13 20:27:56 +02:00
ABUILD_DATE="Oct 13, 2015"
ABUILD_VERSION="0.9.4"
2006-10-25 21:02:34 +02:00
2011-11-05 13:21:14 +01:00
TOP=$PWD
2004-10-21 23:41:57 +02:00
# Where shall we place all the build trees?
2013-12-19 20:43:29 +01:00
TARGET=${COREBOOT_BUILD_DIR:-coreboot-builds}
2011-11-05 13:21:14 +01:00
XMLFILE=$TOP/abuild.xml
REAL_XMLFILE=$XMLFILE
2004-10-19 09:00:47 +02:00
2013-12-19 20:13:23 +01:00
export KCONFIG_OVERWRITECONFIG=1
2004-10-21 23:41:57 +02:00
# path to payload. Should be more generic
2004-11-04 12:04:33 +01:00
PAYLOAD=/dev/null
2004-10-21 23:41:57 +02:00
2013-05-31 21:33:30 +02:00
# path to coreboot XGCC
XGCCPATH="`pwd`/util/crossgcc/xgcc/bin/"
# Add XGCC to the path.
if [ -d "$XGCCPATH" ] && [[ ":$PATH:" != *":$XGCCPATH:"* ]]; then
PATH="$XGCCPATH:$PATH"
fi
2004-10-21 23:41:57 +02:00
# Lines of error context to be printed in FAILURE case
2010-03-30 16:02:19 +02:00
CONTEXT=6
2004-10-21 23:41:57 +02:00
2009-03-11 16:00:50 +01:00
# Configure-only mode
configureonly=0
2011-06-01 21:29:48 +02:00
# Did any board fail to build?
failed=0
2013-12-05 19:53:04 +01:00
# default: single CPU build
cpus=1
2004-10-21 23:41:57 +02:00
# One might want to adjust these in case of cross compiling
2009-05-26 16:03:51 +02:00
for i in make gmake gnumake nonexistant_make; do
$i --version 2>/dev/null |grep "GNU Make" >/dev/null && break
done
if [ "$i" = "nonexistant_make" ]; then
echo No GNU Make found.
exit 1
fi
MAKE=$i
2004-10-19 09:00:47 +02:00
2013-12-05 19:36:31 +01:00
# this can be changed to junit by -J
2006-05-27 02:22:02 +02:00
mode=text
2008-05-27 20:29:26 +02:00
# silent mode.. no compiler calls, only warnings in the log files.
# this is disabled per default but can be enabled with -s
silent=
2014-12-08 09:57:52 +01:00
# quiet mode: only print pass, failure, and 'skipped' messages
quiet=false
2009-03-11 16:43:02 +01:00
# clang mode enabled by -sb option.
scanbuild=false
2004-10-19 09:00:47 +02:00
ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
2009-03-11 16:00:50 +01:00
-e s/i86pc/i386/ \
2004-10-19 09:00:47 +02:00
-e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
-e "s/Power Macintosh/ppc/"`
2006-10-25 21:02:34 +02:00
trap interrupt INT
function interrupt
{
printf "\n$0: execution interrupted manually.\n"
2013-12-05 19:36:31 +01:00
if [ "$mode" == "junit" ]; then
2006-10-25 21:02:34 +02:00
printf "$0: deleting incomplete xml output file.\n"
fi
exit 1
}
2004-11-05 12:57:00 +01:00
function debug
{
2006-10-25 21:02:34 +02:00
test "$verbose" == "true" && printf "$*\n"
2004-11-05 12:57:00 +01:00
}
2004-11-05 20:55:06 +01:00
2011-06-03 21:56:13 +02:00
function junit
{
test "$mode" == "junit" && printf "$*\n" >> $XMLFILE
return 0
}
function junitfile
{
test "$mode" == "junit" && {
printf '<![CDATA[\n'
cat $1
printf ']]>\n'
} >> $XMLFILE
}
2006-05-27 02:22:02 +02:00
2015-10-31 00:35:44 +01:00
# Return mainboard descriptors.
# By default all mainboards are listed, but when passing a two-level path
# below src/mainboard, such as emulation/qemu-i440fx, or emulation/*, it
# returns all board descriptors in that hierarchy.
function get_mainboards
{
local search_space=${1-*/*}
grep -h "^[[:space:]]*config\>[[:space:]]*\<BOARD_" \
2015-10-31 09:13:26 +01:00
${ROOT}/src/mainboard/${search_space}/Kconfig.name 2>/dev/null | \
2015-10-31 00:35:44 +01:00
sed "s,^.*\<BOARD_\([A-Z0-9_]*\)\>.*$,\1,"
}
2006-05-27 02:22:02 +02:00
2015-10-31 00:35:44 +01:00
# Given a mainboard descriptor, return its directory below src/mainboard
function mainboard_directory
2004-10-19 09:00:47 +02:00
{
2015-10-31 00:35:44 +01:00
local MAINBOARD=$1
grep -l "^[[:space:]]*config\>[[:space:]]*\<BOARD_${MAINBOARD}\>" \
${ROOT}/src/mainboard/*/*/Kconfig.name | \
sed "s:^$ROOT/src/mainboard/\(.*\)/Kconfig.name$:\1:"
2004-10-19 09:00:47 +02:00
}
2015-10-31 00:35:44 +01:00
# Given a mainboard descriptor, return its vendor (CONFIG_VENDOR_*)
function mainboard_vendor
2004-10-19 09:00:47 +02:00
{
2015-10-31 00:35:44 +01:00
local MAINBOARD=$1
2010-04-27 08:56:47 +02:00
2015-10-31 00:35:44 +01:00
local kconfig_file=$( \
grep -l "^[[:space:]]*config\>[[:space:]]*\<BOARD_${MAINBOARD}\>" \
${ROOT}/src/mainboard/*/*/Kconfig.name | \
sed "s:^\(${ROOT}/src/mainboard/.*\)/.*/\(Kconfig.name\)$:\1/\2:" )
if [ ! -f "$kconfig_file" ]; then
exit 1
fi
grep "^[[:space:]]*config\>[[:space:]]*\<VENDOR_" $kconfig_file | \
sed "s,^.*\<VENDOR_\([A-Z0-9_]*\)\>.*$,\1,"
}
2010-04-27 08:56:47 +02:00
2015-10-31 00:35:44 +01:00
# Accepts directory names (eg. emulation/qemu-i440fx) and mainboard
# descriptors (eg. EMULATION_QEMU_X86_I440F} and returns the latter
# format.
# If a directory contains multiple boards, returns them all.
function normalize_target
{
2015-10-31 09:13:26 +01:00
local targets=$(get_mainboards $1)
if [ -n "$targets" ]; then
echo $targets
return
2015-10-31 00:35:44 +01:00
fi
2015-10-31 09:13:26 +01:00
local targets=$(echo $1 | tr ',' ' ')
for i in $targets; do
if [ -n "$(mainboard_directory $i)" ]; then
echo $i
else
echo "$i is not a valid target" >&2
exit 1
fi
done
2004-10-19 09:00:47 +02:00
}
2010-01-30 11:44:28 +01:00
function create_config
{
2015-10-31 00:35:44 +01:00
local MAINBOARD=$1
2010-01-30 11:44:28 +01:00
2015-10-31 00:35:44 +01:00
local build_dir=$TARGET/${MAINBOARD}
local config_file=${build_dir}/config.build
local board_srcdir=$(mainboard_directory ${MAINBOARD})
2010-01-30 11:44:28 +01:00
# get a working payload for the board if we have one.
2010-04-27 08:56:47 +02:00
# the --payload option expects a directory containing
2010-01-30 11:44:28 +01:00
# a shell script payload.sh
2015-10-31 00:35:44 +01:00
# Usage: payload.sh [BOARD]
2010-01-30 11:44:28 +01:00
# the script returns an absolute path to the payload binary.
if [ -f $payloads/payload.sh ]; then
2015-10-31 00:35:44 +01:00
local PAYLOAD=`sh $payloads/payload.sh $MAINBOARD`
2012-09-24 20:52:42 +02:00
if [ $? -gt 0 ]; then
echo "problem with payload"
exit 1
fi
2014-12-10 23:49:23 +01:00
if [ "$quiet" == "false" ]; then printf "Using payload $PAYLOAD\n"; fi
2012-10-07 15:05:42 +02:00
elif [ "$payloads" = "none" ]; then
2015-10-31 00:35:44 +01:00
local PAYLOAD=none
2010-01-30 11:44:28 +01:00
fi
mkdir -p ${build_dir}
2010-04-17 00:48:57 +02:00
mkdir -p $TARGET/sharedutils
2010-01-30 11:44:28 +01:00
2015-10-31 00:35:44 +01:00
if [ "$quiet" == "false" ]; then printf " Creating config file for $MAINBOARD... \n"; fi
printf "CONFIG_VENDOR_$(mainboard_vendor ${MAINBOARD})=y\n" > ${config_file}
printf "CONFIG_BOARD_${MAINBOARD}=y\n" >> ${config_file}
grep "select[\t ]*ARCH" ${ROOT}/src/mainboard/${board_srcdir}/Kconfig | \
sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> ${config_file}
printf "CONFIG_MAINBOARD_DIR=\"${board_srcdir}\"\n" >> ${config_file}
2015-10-30 22:59:30 +01:00
if [ "$PAYLOAD" = "none" ]; then
2015-10-31 00:35:44 +01:00
printf "CONFIG_PAYLOAD_NONE=y\n" >> ${config_file}
2015-10-30 22:59:30 +01:00
elif [ "$PAYLOAD" != "/dev/null" ]; then
2015-10-31 00:35:44 +01:00
printf "# CONFIG_PAYLOAD_NONE is not set\n" >> ${config_file}
printf "# CONFIG_PAYLOAD_SEABIOS is not set\n" >> ${config_file}
printf "CONFIG_PAYLOAD_ELF=y\n" >> ${config_file}
printf "CONFIG_PAYLOAD_FILE=\"$PAYLOAD\"\n" >> ${config_file}
2010-01-30 11:44:28 +01:00
fi
2015-10-31 00:35:44 +01:00
if [ "$quiet" == "false" ]; then printf " $MAINBOARD ($customizing)\n"; fi
printf "$configoptions" >> ${config_file}
2015-10-30 22:59:30 +01:00
2015-10-31 00:35:44 +01:00
yes "" 2>/dev/null | $MAKE oldconfig $silent DOTCONFIG=${config_file} obj=${build_dir} objutil=$TARGET/sharedutils &> ${build_dir}/config.log
2010-01-30 11:44:28 +01:00
ret=$?
if [ $ret -eq 0 ]; then
2015-10-31 00:35:44 +01:00
if [ "$quiet" == "false" ]; then printf " $MAINBOARD config created.\n"; fi
2010-01-30 11:44:28 +01:00
return 0
else
2010-03-30 16:02:19 +02:00
# Does this ever happen?
2015-10-31 00:35:44 +01:00
if [ "$quiet" == "false" ]; then printf "$MAINBOARD config creation FAILED!\nLog excerpt:\n"; fi
2010-01-30 11:44:28 +01:00
tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log
return 1
fi
}
2004-10-19 09:00:47 +02:00
function create_buildenv
{
2015-10-31 00:35:44 +01:00
local MAINBOARD=$1
2010-03-30 17:49:14 +02:00
2015-10-31 00:35:44 +01:00
create_config $MAINBOARD
2010-03-30 17:49:14 +02:00
ret=$?
2010-03-25 15:18:57 +01:00
# Allow simple "make" in the target directory
2015-10-31 00:35:44 +01:00
local MAKEFILE=$TARGET/${MAINBOARD}/Makefile
2010-12-11 23:07:07 +01:00
echo "# autogenerated" > $MAKEFILE
2010-03-25 15:18:57 +01:00
echo "TOP=$ROOT" >> $MAKEFILE
2010-12-11 23:07:07 +01:00
echo "BUILD=$TARGET" >> $MAKEFILE
2015-10-31 00:35:44 +01:00
echo "OBJ=\$(BUILD)/${MAINBOARD}" >> $MAKEFILE
2010-12-11 23:07:07 +01:00
echo "OBJUTIL=\$(BUILD)/sharedutils" >> $MAKEFILE
2010-03-30 16:02:19 +02:00
echo "all:" >> $MAKEFILE
2010-12-11 23:07:07 +01:00
echo " @cp -a config.h config.h.bak" >> $MAKEFILE
echo " @cd \$(TOP); \$(MAKE) oldconfig DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> $MAKEFILE
echo " @tail -n+6 config.h > config.new; tail -n+6 config.h.bak > config.old" >> $MAKEFILE
echo " @cmp -s config.new config.old && cp -a config.h.bak config.h || echo \"Config file changed\"" >> $MAKEFILE
echo " @rm config.h.bak config.new config.old" >> $MAKEFILE
echo " @cd \$(TOP); \$(MAKE) DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> $MAKEFILE
2010-03-30 17:49:14 +02:00
return $ret
2004-10-19 09:00:47 +02:00
}
function compile_target
2010-04-27 08:56:47 +02:00
{
2015-10-30 23:49:32 +01:00
local MAINBOARD=$1
2004-10-19 09:00:47 +02:00
2015-10-30 23:49:32 +01:00
if [ "$quiet" == "false" ]; then printf " Compiling $MAINBOARD image$cpuconfig...\n"; fi
2008-05-27 20:29:26 +02:00
2004-10-19 09:00:47 +02:00
CURR=$( pwd )
2010-03-30 16:02:19 +02:00
#stime=`perl -e 'print time();' 2>/dev/null || date +%s`
2015-10-30 23:49:32 +01:00
build_dir=$TARGET/${MAINBOARD}
2014-05-17 18:26:38 +02:00
eval $BUILDPREFIX $MAKE $silent DOTCONFIG=${build_dir}/config.build obj=${build_dir} objutil=$TARGET/sharedutils \
2010-02-07 22:43:48 +01:00
&> ${build_dir}/make.log
ret=$?
2011-11-05 12:47:13 +01:00
cp .xcompile ${build_dir}/xcompile.build
2015-10-30 23:49:32 +01:00
cd $TARGET/${MAINBOARD}
2010-03-30 16:02:19 +02:00
2010-02-10 19:08:22 +01:00
etime=`perl -e 'print time();' 2>/dev/null || date +%s`
2005-12-04 21:35:56 +01:00
duration=$(( $etime - $stime ))
2015-10-30 23:49:32 +01:00
junit " <testcase classname='board${testclass/#/.}' name='$MAINBOARD' time='$duration' >"
2010-03-30 16:02:19 +02:00
2005-12-04 21:42:37 +01:00
if [ $ret -eq 0 ]; then
2011-06-03 21:56:13 +02:00
junit "<system-out>"
junitfile make.log
junit "</system-out>"
2006-10-25 21:02:34 +02:00
printf "ok\n" > compile.status
2015-10-30 23:49:32 +01:00
printf "$MAINBOARD built successfully. (took ${duration}s)\n"
2004-10-19 09:00:47 +02:00
else
2014-05-21 22:47:05 +02:00
ret=1
2011-06-03 21:56:13 +02:00
junit "<failure type='BuildFailed'>"
junitfile make.log
junit "</failure>"
2015-04-22 18:24:01 +02:00
printf "failed\n" > compile.status
2015-10-30 23:49:32 +01:00
printf "$MAINBOARD build FAILED after ${duration}s!\nLog excerpt:\n"
2009-05-26 16:03:51 +02:00
tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
2011-06-01 21:29:48 +02:00
failed=1
2004-10-19 09:00:47 +02:00
fi
2014-05-21 22:47:05 +02:00
cd $CURR
if [ $clean_work = "true" ]; then
2015-10-30 23:49:32 +01:00
rm -rf $TARGET/${MAINBOARD}
2014-05-21 22:47:05 +02:00
fi
return $ret
2004-10-19 09:00:47 +02:00
}
function build_target
{
2015-10-31 00:35:44 +01:00
local MAINBOARD=$1
local board_srcdir=$(mainboard_directory ${MAINBOARD})
2004-11-05 01:25:19 +01:00
2015-10-31 00:35:44 +01:00
if [ "`cat $TARGET/${MAINBOARD}/compile.status 2>/dev/null`" = "ok" -a \
2012-11-22 14:19:43 +01:00
"$buildall" = "false" ]; then
2015-10-31 00:35:44 +01:00
printf "Skipping $MAINBOARD; (already successful)\n"
2012-11-22 14:19:43 +01:00
return
fi
2009-03-11 16:00:50 +01:00
HOSTCC='gcc'
2004-11-05 11:48:04 +01:00
2015-10-31 00:35:44 +01:00
if [ $chromeos = true -a `grep -c "^[[:space:]]*select[[:space:]]*MAINBOARD_HAS_CHROMEOS\>" ${ROOT}/src/mainboard/${board_srcdir}/Kconfig` -eq 0 ]; then
echo "${MAINBOARD} doesn't support Chrome OS, skipping."
2015-07-31 16:26:19 +02:00
return
fi
2015-10-31 00:35:44 +01:00
if [ -f src/mainboard/${board_srcdir}/abuild.disabled ]; then
echo "${MAINBOARD} disabled:"
cat src/mainboard/${board_srcdir}/abuild.disabled
2015-07-14 20:20:13 +02:00
return
fi
2015-10-31 00:35:44 +01:00
if [ "$quiet" == "false" ]; then printf "Building $MAINBOARD\n"; fi
mkdir -p $TARGET/${MAINBOARD} $TARGET/abuild
2014-05-21 23:00:32 +02:00
ABSPATH=`cd $TARGET/abuild; pwd`
2015-10-31 00:35:44 +01:00
XMLFILE=$ABSPATH/${MAINBOARD}.xml
2015-10-31 08:53:30 +01:00
rm -f ${XMLFILE}
2006-05-27 02:22:02 +02:00
2009-03-11 16:43:02 +01:00
2010-03-30 16:02:19 +02:00
stime=`perl -e 'print time();' 2>/dev/null || date +%s`
2015-10-31 00:35:44 +01:00
create_buildenv $MAINBOARD
2014-10-18 11:57:11 +02:00
2015-10-31 00:35:44 +01:00
required_arches=`egrep "^CONFIG_ARCH_(BOOTBLOCK|R.MSTAGE|VERSTAGE)" $TARGET/${MAINBOARD}/config.build | \
2014-10-31 16:48:00 +01:00
sed "s,^CONFIG_ARCH_[^_]*_\([^=]*\)=.*$,\1," |sort -u |tr 'A-Z\n\r' 'a-z '`
2014-12-29 15:06:16 +01:00
missing_arches=`printf 'include .xcompile\nall: ; @echo $(foreach arch,'"$required_arches"',$(if $(filter $(arch),$(SUBARCH_SUPPORTED)),,$(arch)))' | make --no-print-directory -f -`
2014-10-18 11:57:11 +02:00
if [ -n "$missing_arches" ]; then
2015-10-31 00:35:44 +01:00
printf "skipping $MAINBOARD because we're missing compilers for ($missing_arches)\n"
2014-10-18 11:57:11 +02:00
return
fi
2009-03-11 16:00:50 +01:00
if [ $? -eq 0 -a $configureonly -eq 0 ]; then
2014-05-17 18:26:38 +02:00
BUILDPREFIX=
2010-04-19 22:39:22 +02:00
if [ "$scanbuild" = "true" ]; then
2015-10-31 00:35:44 +01:00
scanbuild_out=$TARGET/${MAINBOARD}-scanbuild
2014-05-17 18:26:38 +02:00
rm -rf ${scanbuild_out}
BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
2010-04-19 22:39:22 +02:00
fi
2015-10-31 00:35:44 +01:00
compile_target ${MAINBOARD}
2009-03-11 16:43:02 +01:00
if [ "$scanbuild" = "true" ]; then
2014-05-17 18:26:38 +02:00
mv ${scanbuild_out}tmp/* ${scanbuild_out}
rmdir ${scanbuild_out}tmp
2009-03-11 16:43:02 +01:00
fi
2004-10-19 09:00:47 +02:00
fi
2010-03-30 16:02:19 +02:00
# Not calculated here because we still print it in compile_target
#etime=`perl -e 'print time();' 2>/dev/null || date +%s`
#duration=$(( $etime - $stime ))
2004-11-05 15:06:24 +01:00
2011-06-03 21:56:13 +02:00
junit "</testcase>"
2006-10-25 21:02:34 +02:00
}
2009-04-15 18:07:27 +02:00
function remove_target
{
if [ "$remove" != "true" ]; then
return 0
fi
2015-10-30 23:25:23 +01:00
local MAINBOARD=$1
2009-04-15 18:07:27 +02:00
# Save the generated coreboot.rom file of each board.
2015-10-30 23:25:23 +01:00
if [ -r "$TARGET/${MAINBOARD}/coreboot.rom" ]; then
cp $TARGET/${MAINBOARD}/coreboot.rom \
${MAINBOARD}_coreboot.rom
2009-04-15 18:07:27 +02:00
fi
2015-10-30 23:25:23 +01:00
printf "Removing build dir for board $MAINBOARD...\n"
rm -rf $TARGET/${MAINBOARD}
2009-04-15 18:07:27 +02:00
return 0
}
2004-11-05 01:25:19 +01:00
function myhelp
{
2015-07-31 16:14:43 +02:00
cat << __END_OF_HELP
Usage: $0 [-v] [-a] [-b] [-r] [-t <vendor/board>] [-p <dir>] [lbroot]
$0 [-V|--version]
$0 [-h|--help]
Options:\n"
[-v|--verbose] print more messages
[-q|--quiet] print fewer messages
[-a|--all] build previously succeeded ports as well
[-r|--remove] remove output dir after build
[-t|--target <vendor/board>] attempt to build target vendor/board only
[-p|--payloads <dir>] use payloads in <dir> to build images
[-V|--version] print version number and exit
[-h|--help] print this help and exit
[-J|--junit] write JUnit formatted xml log file
(defaults to $XMLFILE)
[-T|--test] submit image(s) to automated test system
[-c|--cpus <numcpus>] build on <numcpus> at the same time
[-s|--silent] omit compiler calls in logs
[-y|--ccache] use ccache
[-C|--config] configure-only mode
[-l|--loglevel <num>] set loglevel
[-u|--update] update existing image
[-P|--prefix <name>] file name prefix in CBFS
[-B|--blobs] Allow using binary files
[-z|--clean] Remove build results when finished
[-o|--outdir <path>] store build results in path
(defaults to $TARGET)
[-L|--clang] Use clang
[-x|--chromeos] Build with CHROMEOS enabled
2015-07-31 16:26:19 +02:00
Skip boards without Chrome OS support
2015-10-13 20:27:56 +02:00
[-X|--xmlfile <name>] set JUnit XML log file filename
2015-07-31 16:14:43 +02:00
[--scan-build] use clang's static analyzer
[cbroot] absolute path to coreboot sources
(defaults to $ROOT)
__END_OF_HELP
2004-11-05 01:25:19 +01:00
}
2010-04-27 08:56:47 +02:00
function myversion
2004-11-05 01:25:19 +01:00
{
cat << EOF
2008-01-18 16:08:58 +01:00
coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
2004-11-05 01:25:19 +01:00
2006-05-27 02:22:02 +02:00
Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
2010-01-30 11:44:28 +01:00
Copyright (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
2006-10-25 21:02:34 +02:00
2004-11-05 01:25:19 +01:00
This program is free software; you may redistribute it under the terms
of the GNU General Public License. This program has absolutely no
warranty.
EOF
}
# default options
target=""
buildall=false
2004-11-05 12:57:00 +01:00
verbose=false
2004-11-05 01:25:19 +01:00
2010-04-08 13:37:43 +02:00
test -f util/sconfig/sconfig.l && ROOT=$( pwd )
test -f ../util/sconfig/sconfig.l && ROOT=$( cd ..; pwd )
2010-01-30 11:44:28 +01:00
test "$ROOT" = "" && ROOT=$( cd ../..; pwd )
2009-07-01 14:26:11 +02:00
2012-04-05 11:17:01 +02:00
# Look if we have getopt. If not, build it.
export PATH=$PATH:util/abuild
getopt - > /dev/null 2>/dev/null || gcc -o util/abuild/getopt util/abuild/getopt.c
2011-11-05 14:44:41 +01:00
# command line for xargs parallelization. Thus overwrite -c X
cmdline="$* -c 1"
2008-05-27 20:29:26 +02:00
# parse parameters.. try to find out whether we're running GNU getopt
2008-05-28 10:40:23 +02:00
getoptbrand="`getopt -V`"
if [ "${getoptbrand:0:6}" == "getopt" ]; then
# Detected GNU getopt that supports long options.
2015-10-30 23:05:56 +01:00
args=`getopt -l version,verbose,quiet,help,all,target:,payloads:,cpus:,silent,junit,config,loglevel:,remove,prefix:,update,scan-build,ccache,blobs,clang,clean,outdir:,chromeos,xmlfile: -o Vvqhat:p:c:sJCl:rP:uyBLzo:xX: -- "$@"` || exit 1
2010-09-27 23:14:19 +02:00
eval set -- $args
2008-05-27 20:29:26 +02:00
else
# Detected non-GNU getopt
2015-10-30 23:05:56 +01:00
args=`getopt Vvqhat:p:c:sJCl:rP:uyBLzo:xX: $*`
2008-05-27 20:29:26 +02:00
set -- $args
fi
2004-11-05 01:25:19 +01:00
if [ $? != 0 ]; then
myhelp
exit 1
fi
2015-07-31 16:26:19 +02:00
chromeos=false
2014-05-21 22:47:05 +02:00
clean_work=false
2012-05-01 15:14:46 +02:00
customizing=""
configoptions=""
2015-09-15 16:57:04 +02:00
# testclass needs to be undefined if not used for variable expansion to work
unset testclass
2004-11-05 09:50:54 +01:00
while true ; do
2004-11-05 12:24:57 +01:00
case "$1" in
2011-06-03 21:56:13 +02:00
-J|--junit) shift; mode=junit; rm -f $XMLFILE ;;
2004-11-05 15:06:24 +01:00
-t|--target) shift; target="$1"; shift;;
2004-11-05 09:50:54 +01:00
-a|--all) shift; buildall=true;;
2010-09-27 23:14:19 +02:00
-r|--remove) shift; remove=true;;
2010-03-25 20:01:27 +01:00
-v|--verbose) shift; verbose=true; silent='V=1';;
2014-12-08 09:57:52 +01:00
-q|--quiet) shift; quiet=true;;
2004-11-05 12:47:41 +01:00
-V|--version) shift; myversion; exit 0;;
2006-10-25 21:02:34 +02:00
-h|--help) shift; myversion; myhelp; exit 0;;
2006-09-15 19:00:11 +02:00
-p|--payloads) shift; payloads="$1"; shift;;
2012-05-01 15:14:46 +02:00
-c|--cpus) shift
export MAKEFLAGS="-j $1"
2013-12-05 19:53:04 +01:00
cpus=$1
2014-12-08 09:57:52 +01:00
test "$MAKEFLAGS" == "-j max" && export MAKEFLAGS="-j" && cpuconfig=" in parallel"
test "$1" == "1" && cpuconfig=" on 1 cpu"
expr "$1" : '-\?[0-9]\+$' > /dev/null && test 0$1 -gt 1 && cpuconfig=" on $1 cpus in parallel"
2012-05-01 15:14:46 +02:00
shift;;
2008-05-27 20:29:26 +02:00
-s|--silent) shift; silent="-s";;
2014-05-17 18:26:38 +02:00
--scan-build) shift
2012-05-01 15:14:46 +02:00
scanbuild=true
customizing="${customizing}, scan-build"
;;
-y|--ccache) shift
customizing="${customizing}, ccache"
configoptions="${configoptions}CONFIG_CCACHE=y\n"
;;
2009-03-11 16:00:50 +01:00
-C|--config) shift; configureonly=1;;
2012-05-01 15:14:46 +02:00
-l|--loglevel) shift
customizing="${customizing}, loglevel $1"
configoptions="${configoptions}CONFIG_DEFAULT_CONSOLE_LOGLEVEL_$1=y\n"
configoptions="${configoptions}CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$1\n"
shift;;
-u|--update) shift
customizing="${customizing}, update"
configoptions="${configoptions}CONFIG_UPDATE_IMAGE=y\n"
;;
-P|--prefix) shift
customizing="${customizing}, cbfs prefix $1"
configoptions="${configoptions}CONFIG_CBFS_PREFIX=\"$1\""
shift;;
-B|--blobs) shift
customizing="${customizing}, blobs"
configoptions="${configoptions}CONFIG_USE_BLOBS=y\n"
;;
2014-05-14 13:43:58 +02:00
-L|--clang) shift
customizing="${customizing}, clang"
2014-11-28 23:08:51 +01:00
configoptions="${configoptions}CONFIG_COMPILER_LLVM_CLANG=y\n# CONFIG_COMPILER_GCC is not set\n"
2014-05-14 13:43:58 +02:00
;;
2014-05-21 22:47:05 +02:00
-z|--clean) shift
customizing="${customizing}, clean"
clean_work=true
;;
2014-05-21 23:00:32 +02:00
-o|--outdir) shift
TARGET=$1; shift
;;
2015-04-22 18:38:10 +02:00
-x|--chromeos) shift
2015-07-31 16:26:19 +02:00
chromeos=true
2015-07-31 16:30:04 +02:00
testclass=chromeos
2015-07-31 16:26:19 +02:00
customizing="${customizing}, chrome os"
2015-04-22 18:38:10 +02:00
configoptions="${configoptions}CONFIG_CHROMEOS=y\n"
;;
2015-10-13 20:27:56 +02:00
-X|--xmlfile) shift; XMLFILE=$1; REAL_XMLFILE=$1; shift;;
2004-11-05 09:50:54 +01:00
--) shift; break;;
2006-10-25 21:02:34 +02:00
-*) printf "Invalid option\n\n"; myhelp; exit 1;;
2004-11-05 12:24:57 +01:00
*) break;;
2004-11-05 09:50:54 +01:00
esac
2004-11-05 01:25:19 +01:00
done
2014-05-21 23:00:32 +02:00
if [ -z "$TARGET" -o "$TARGET" = "/" ]; then
echo "Please specify a valid, non-root build directory."
exit 1
fi
2012-05-01 15:14:46 +02:00
customizing=`echo $customizing |cut -c3-`
if [ "$customizing" = "" ]; then
customizing="default configuration"
fi
2011-11-05 14:44:41 +01:00
USE_XARGS=0
2011-11-05 12:55:18 +01:00
if [ "$cpus" != "1" ]; then
2013-12-05 19:53:04 +01:00
# Limit to 32 parallel builds for now.
# Thrashing all caches because we run
# 160 abuilds in parallel is no fun.
if [ "$cpus" = "max" ]; then
cpus=32
fi
2015-10-31 00:42:50 +01:00
# Test if xargs supports the non-standard -P flag
# FIXME: disabled until we managed to eliminate all the make(1) quirks
echo | xargs -P ${cpus:-0} -n 1 echo 2>/dev/null >/dev/null && USE_XARGS=1
2011-11-05 14:44:41 +01:00
fi
if [ "$USE_XARGS" = "0" ]; then
2012-05-31 00:03:48 +02:00
test "$MAKEFLAGS" == "" && test "$cpus" != "" && export MAKEFLAGS="-j $cpus"
2015-10-31 00:42:50 +01:00
build_targets()
2011-11-05 14:44:41 +01:00
{
2015-10-31 00:42:50 +01:00
local targets=${*-$(get_mainboards)}
for MAINBOARD in $targets; do
build_target ${MAINBOARD}
2015-10-31 00:35:44 +01:00
remove_target ${MAINBOARD}
2011-11-05 14:44:41 +01:00
done
}
else
2015-10-31 00:42:50 +01:00
build_targets()
2011-11-05 14:44:41 +01:00
{
2015-10-31 00:42:50 +01:00
local targets=${*-$(get_mainboards)}
2011-11-05 14:44:41 +01:00
# seed shared utils
TMPCFG=`mktemp`
2014-11-28 23:08:51 +01:00
printf "$configoptions" > $TMPCFG
2014-05-17 18:24:45 +02:00
$MAKE -j $cpus DOTCONFIG=$TMPCFG obj=$TARGET/temp objutil=$TARGET/sharedutils allnoconfig
2014-11-28 23:08:51 +01:00
printf "$configoptions" >> $TMPCFG
2015-07-31 16:46:55 +02:00
yes "" 2>/dev/null | $MAKE -j $cpus DOTCONFIG=$TMPCFG obj=$TARGET/temp objutil=$TARGET/sharedutils oldconfig 2>/dev/null |head > /dev/null
2014-05-17 18:26:38 +02:00
BUILDPREFIX=
if [ "$scanbuild" = "true" ]; then
scanbuild_out=$TARGET/sharedutils-scanbuild
rm -rf ${scanbuild_out}
BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
fi
2015-09-15 17:30:52 +02:00
mkdir -p $TARGET/abuild
local ABSPATH=`cd $TARGET/abuild; pwd`
local XMLFILE=$ABSPATH/__util.xml
2015-10-31 08:53:30 +01:00
rm -f ${XMLFILE}
2015-09-15 17:30:52 +02:00
local stime=`perl -e 'print time();' 2>/dev/null || date +%s`
$BUILDPREFIX $MAKE -j $cpus DOTCONFIG=$TMPCFG obj=$TARGET/temp objutil=$TARGET/sharedutils tools > $TARGET/sharedutils/make.log 2>&1
local ret=$?
local etime=`perl -e 'print time();' 2>/dev/null || date +%s`
local duration=$(( $etime - $stime ))
junit " <testcase classname='util' name='all' time='$duration' >"
if [ $ret -eq 0 ]; then
junit "<system-out>"
junitfile $TARGET/sharedutils/make.log
junit "</system-out>"
junit "</testcase>"
else
junit "<failure type='BuildFailed'>"
junitfile $TARGET/sharedutils/make.log
junit "</failure>"
junit "</testcase>"
return
fi
if [ $ret -eq 1 ]; then
return
fi
2014-05-17 18:26:38 +02:00
if [ "$scanbuild" = "true" ]; then
mv ${scanbuild_out}tmp/* ${scanbuild_out}
rmdir ${scanbuild_out}tmp
fi
2014-05-17 18:24:45 +02:00
rm -rf $TARGET/temp $TMPCFG
2015-10-31 00:42:50 +01:00
echo $targets | xargs -P ${cpus:-0} -n 1 $0 $cmdline -t
2011-11-05 14:44:41 +01:00
}
2011-11-05 12:55:18 +01:00
fi
2010-01-30 11:44:28 +01:00
test -z "$1" || ROOT=$1
2004-11-05 01:25:19 +01:00
2010-01-30 11:44:28 +01:00
debug "ROOT=$ROOT"
2004-11-05 01:25:19 +01:00
2011-06-03 21:56:13 +02:00
junit '<?xml version="1.0" encoding="utf-8"?>'
junit '<testsuite>'
2004-11-05 01:26:31 +01:00
if [ "$target" != "" ]; then
2004-11-05 11:48:04 +01:00
# build a single board
2015-10-31 00:35:44 +01:00
MAINBOARD=$(normalize_target ${target})
if [ -z "${MAINBOARD}" ]; then
2010-03-29 18:23:42 +02:00
printf "No such target: $target\n"
2015-10-31 00:35:44 +01:00
exit 1
fi
build_srcdir=$(mainboard_directory ${MAINBOARD})
2015-10-31 00:42:50 +01:00
if [ "$(echo ${MAINBOARD} | wc -w)" -gt 1 ]; then
build_targets ${MAINBOARD}
elif [ ! -r $ROOT/src/mainboard/${build_srcdir} ]; then
2015-10-31 00:35:44 +01:00
printf "No such target: ${MAINBOARD}\n"
exit 1
2011-11-05 14:44:41 +01:00
else
2015-10-31 00:35:44 +01:00
build_target ${MAINBOARD}
remove_target ${MAINBOARD}
2015-09-15 19:32:28 +02:00
test "$mode" != "text" && \
2015-10-31 00:35:44 +01:00
test -f $TARGET/abuild/${MAINBOARD}.xml && \
cat $TARGET/abuild/${MAINBOARD}.xml >> $REAL_XMLFILE
2011-11-05 14:44:41 +01:00
XMLFILE=$REAL_XMLFILE
2010-03-29 18:23:42 +02:00
fi
2004-11-05 01:25:19 +01:00
else
2015-10-31 00:42:50 +01:00
build_targets
2011-11-05 14:44:41 +01:00
rm -f $REAL_XMLFILE
2012-05-21 20:10:04 +02:00
XMLFILE=$REAL_XMLFILE
2011-11-05 14:44:41 +01:00
junit '<?xml version="1.0" encoding="utf-8"?>'
junit '<testsuite>'
2011-11-07 19:01:54 +01:00
if [ "$mode" != "text" ]; then
2013-12-19 20:13:23 +01:00
for xmlfile in $TARGET/abuild/*_*.xml; do
2011-11-07 19:01:54 +01:00
cat $xmlfile >> $REAL_XMLFILE
done
fi
2011-11-05 13:21:14 +01:00
XMLFILE=$REAL_XMLFILE
2004-11-05 01:25:19 +01:00
fi
2011-06-03 21:56:13 +02:00
junit '</testsuite>'
2004-10-19 09:00:47 +02:00
2011-06-01 21:29:48 +02:00
exit $failed