#!/bin/sh

set -e

if [ $# -ne 1 ] ; then
	echo "Usage $(basename $0) <config-file>" 1>&2
	exit 1
fi

CONFIG=$1

setopt()
{
	OPTION=$1
	VALUE=$2

	# First remove any existing instances of this option
	sed -e "s/^# ${OPTION} is not set$//g ; s/^^{OPTION}=.$//g" -i "${CONFIG}"

	# Then append the new value
	case ${VALUE} in
	    n)     echo "# ${OPTION} is not set" >> "${CONFIG}" ;;
	    y|m|*) echo "${OPTION}=${VALUE}" >> "${CONFIG}" ;;
	esac
}

setopt CONFIG_PARAVIRT y
setopt CONFIG_PARAVIRT_DEBUG y
setopt CONFIG_PARAVIRT_GUEST y

setopt CONFIG_XEN y
setopt CONFIG_XEN_BLKDEV_FRONTEND y
setopt CONFIG_XEN_NETDEV_FRONTEND y
setopt CONFIG_XEN_KBDDEV_FRONTEND y
setopt CONFIG_XEN_FBDEV_FRONTEND y
setopt CONFIG_XEN_BALLOON y
setopt CONFIG_XEN_SCRUB_PAGES y
setopt CONFIG_XEN_DEV_EVTCHN y
setopt CONFIG_XEN_BACKEND y
setopt CONFIG_XEN_BLKDEV_BACKEND y
setopt CONFIG_XEN_NETDEV_BACKEND y
setopt CONFIG_XENFS y
setopt CONFIG_XEN_COMPAT_XENFS y
setopt CONFIG_HVC_XEN y
setopt CONFIG_XEN_MAX_DOMAIN_MEMORY 32
setopt CONFIG_XEN_DEBUG_FS y
setopt CONFIG_XEN_DOM0 y
setopt CONFIG_XEN_SYS_HYPERVISOR y
setopt CONFIG_XEN_GNTDEV y
setopt CONFIG_VMI y

setopt CONFIG_KVM y
setopt CONFIG_KVM_INTEL y
setopt CONFIG_KVM_AMD y
setopt CONFIG_KVM_CLOCK y
setopt CONFIG_KVM_GUEST n
setopt CONFIG_KVM_TRACE n

setopt CONFIG_LGUEST n

setopt CONFIG_LOCALVERSION_AUTO n

setopt CONFIG_BRIDGE y

setopt CONFIG_DEBUG_STACK_USAGE n

# Should all be set one way or another in defconfig but aren't
setopt CONFIG_NUMA n
setopt CONFIG_X86_VSMP n
setopt CONFIG_X86_UV n
setopt CONFIG_CALGARY_IOMMU n
setopt CONFIG_AMD_IOMMU n
setopt CONFIG_MAXSMP n
setopt CONFIG_SPARSEMEM_VMEMMAP n
setopt CONFIG_I7300_IDLE n
setopt CONFIG_DMAR n
setopt CONFIG_INTR_REMAP n
setopt CONFIG_GFS2_FS n
setopt CONFIG_IOMMU_DEBUG n
setopt CONFIG_X86_MCE_INTEL n
setopt CONFIG_X86_MCE_AMD n
setopt CONFIG_CRYPTO_AES_NI_INTEL n

setopt CONFIG_FUSION y
setopt CONFIG_FUSION_SPI m
setopt CONFIG_FUSION_SAS m
setopt CONFIG_BLK_CPQ_CISS_DA m

case ${XEN_TARGET_ARCH} in
    x86_32) setopt CONFIG_64BIT n ;;
    x86_64)
	setopt CONFIG_64BIT y
	setopt CONFIG_IA32_EMULATION y
	setopt CONFIG_IA32_AOUT n
	setopt CONFIG_CRYPTO_AES_X86_64 n
	setopt CONFIG_CRYPTO_SALSA20_X86_64 n
	setopt CONFIG_CRYPTO_TWOFISH_X86_64 n
	;;
    *) ;;
esac

exit 0
