Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 211 lines (172 sloc) 3.37 KB
#!/bin/bash
basedir=$(cd ${0%/*} && pwd)
topdir=$(cd ${0%/*}/.. && pwd)
. $topdir/lib/cross-compile.sh
configdir="${basedir}/configs"
outputdir="build/$(git describe)/drm"
verbose=no
check=no
color=no
force=no
JOBS=1
function usage()
{
echo "usage: $1 [options] [config...]"
echo ""
echo "options:"
echo " -c, --color colorize output"
echo " -C, --check run static checker while building"
echo " -f, --force force build from scratch"
echo " -h, --help display help screen and exit"
echo " -j, --jobs N set number of parallel make jobs"
echo " -o, --output DIR set output directory"
echo " -v, --verbose increase verbosity"
}
while test $# -ne 0; do
if test -n "$prev"; then
eval "$prev=$1"
shift; prev=
continue
fi
case $1 in
-c | --color)
color=yes
shift
;;
-C | --check)
check=yes
shift
;;
-f | --force)
force=yes
shift
;;
-h | --help)
usage $0
exit 0
;;
-j | --jobs)
prev=JOBS
shift
;;
-o | --output)
prev=outputdir
shift
;;
-v | --verbose)
verbose=yes
shift
;;
-*)
usage $0
exit 1
;;
*)
configs="$configs $1"
shift
;;
esac
done
if test "x$color" = "xyes"; then
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
MAGENTA="\033[0;35m"
CYAN="\033[0;36m"
RESET="\033[0m"
fi
function make()
{
(
command make "$@" 3>&1 1>&2 2>&3 | tee -a "$KBUILD_OUTPUT/error.log"
exit $PIPESTATUS
) &>> "$KBUILD_OUTPUT/build.log"
}
function include()
{
source "${configdir}/$1"
}
function kconfig()
{
case $1 in
architecture)
cross_compile_prepare $2
;;
*config)
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE \
O=$KBUILD_OUTPUT -j $JOBS $1
;;
enable)
scripts/config --file $KBUILD_OUTPUT/.config \
--enable $2
;;
module)
scripts/config --file $KBUILD_OUTPUT/.config \
--module $2
;;
disable)
scripts/config --file $KBUILD_OUTPUT/.config \
--disable $2
;;
esac
}
function kbuild()
{
ARGS="ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE O=$KBUILD_OUTPUT"
if test "x$check" = "xyes"; then
ARGS="$ARGS C=1"
fi
make $ARGS -j $JOBS -k
}
if test -z "$configs"; then
for config in "${configdir}"/*; do
configs="$configs ${config##${configdir}/}"
done
fi
function log_action()
{
echo -en "${CYAN}$@${RESET} ${MAGENTA}${config}${RESET}..."
}
function log_status()
{
if test "x$1" != "x0"; then
echo -e "${RED}failed ($1)${RESET}"
else
if test -s "$KBUILD_OUTPUT/error.log"; then
echo -e "${YELLOW}done ($1)${RESET}"
else
echo -e "${GREEN}done${RESET}"
fi
fi
}
for config in $configs; do
# configuration files ending in .include are templates included in
# other configurations, so they should not be built themselves
if test "${config%.include}" != "${config}"; then
continue
fi
KBUILD_OUTPUT="${outputdir}/$config"
CONFIG_FILE="${configdir}/${config}"
if test "x$force" = "xyes"; then
if test "x$verbose" = "xyes"; then
log_action "removing"
fi
rm -rf "$KBUILD_OUTPUT"
if test "x$verbose" = "xyes"; then
log_status $?
fi
fi
if ! test -d "$KBUILD_OUTPUT"; then
mkdir -p "$KBUILD_OUTPUT"
fi
if test -f "$KBUILD_OUTPUT/build.log"; then
rm "$KBUILD_OUTPUT/build.log"
fi
if test -f "$KBUILD_OUTPUT/error.log"; then
rm "$KBUILD_OUTPUT/error.log"
fi
log_action "building"
source "$CONFIG_FILE"; rc=$?
cross_compile_cleanup
log_status $rc
done