1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0+
3#
4# Build a kvm-ready Linux kernel from the tree in the current directory.
5#
6# Usage: kvm-build.sh config-template build-dir resdir
7#
8# Copyright (C) IBM Corporation, 2011
9#
10# Authors: Paul E. McKenney <paulmck@linux.ibm.com>
11
12config_template=${1}
13if test -z "$config_template" -o ! -f "$config_template" -o ! -r "$config_template"
14then
15	echo "kvm-build.sh :$config_template: Not a readable file"
16	exit 1
17fi
18builddir=${2}
19resdir=${3}
20
21T=${TMPDIR-/tmp}/test-linux.sh.$$
22trap 'rm -rf $T' 0
23mkdir $T
24
25cp ${config_template} $T/config
26cat << ___EOF___ >> $T/config
27CONFIG_INITRAMFS_SOURCE="$TORTURE_INITRD"
28CONFIG_VIRTIO_PCI=y
29CONFIG_VIRTIO_CONSOLE=y
30___EOF___
31
32configinit.sh $T/config O=$builddir $resdir
33retval=$?
34if test $retval -gt 1
35then
36	exit 2
37fi
38ncpus=`cpus2use.sh`
39make O=$builddir -j$ncpus $TORTURE_KMAKE_ARG > $resdir/Make.out 2>&1
40retval=$?
41if test $retval -ne 0 || grep "rcu[^/]*": < $resdir/Make.out | egrep -q "Stop|Error|error:|warning:" || egrep -q "Stop|Error|error:" < $resdir/Make.out
42then
43	echo Kernel build error
44	egrep "Stop|Error|error:|warning:" < $resdir/Make.out
45	echo Run aborted.
46	exit 3
47fi
48