#!/bin/bash
#
# Copyright (c) 2006 Mellanox Technologies. All rights reserved.
#
# This Software is licensed under one of the following licenses:
#
# 1) under the terms of the "Common Public License 1.0" a copy of which is
#    available from the Open Source Initiative, see
#    http://www.opensource.org/licenses/cpl.php.
#
# 2) under the terms of the "The BSD License" a copy of which is
#    available from the Open Source Initiative, see
#    http://www.opensource.org/licenses/bsd-license.php.
#
# 3) under the terms of the "GNU General Public License (GPL) Version 2" a
#    copy of which is available from the Open Source Initiative, see
#    http://www.opensource.org/licenses/gpl-license.php.
#
# Licensee has the right to choose one of the above licenses.
#
# Redistributions of source code must retain the above copyright
# notice and one of the license notices.
#
# Redistributions in binary form must reproduce both the above copyright
# notice, one of the license notices in the documentation
# and/or other materials provided with the distribution.
#
#  $Id: configure 9097 2006-08-24 06:39:09Z vlad $
#

usage()
{
cat << EOF
\`configure' configures variables for kernel modules compilation

Usage:  `basename $0` [options]

    --prefix=PREFIX  for userspace components []
    --build_root=BUILD_ROOT  root directory to build RPM packages
    --kernel-version=VERSION  make for this kernel [$(uname -r)]
    --modules-dir=DIR  modules directory [/lib/modules/$(uname -r)]
    --kernel-sources=DIR  make for this kernel [/lib/modules/$(uname -r)/build]

    Kernel modules configuration:

    --with-core-mod    make CONFIG_INFINIBAND=m [no]
    --without-core-mod   [yes]

    --with-ipoib-mod    make CONFIG_INFINIBAND_IPOIB=m [no]
    --without-ipoib-mod   [yes]

    --with-ipoib-cm    make CONFIG_INFINIBAND_IPOIB_CM=y [yes]
    --without-ipoib-cm   [no]

    --with-ipoib_debug-mod    make CONFIG_INFINIBAND_IPOIB_DEBUG=y [yes]
    --without-ipoib_debug-mod    [no]

    --with-ipoib_debug_data-mod    make CONFIG_INFINIBAND_IPOIB_DEBUG_DATA=y [no]
    --without-ipoib_debug_data-mod    [yes]

    --with-sdp-mod    make CONFIG_INFINIBAND_SDP=m [no]
    --without-sdp-mod    [yes]

    --with-sdp_debug-mod    make CONFIG_INFINIBAND_SDP_DEBUG=y [yes]
    --without-sdp_debug-mod   [no]

    --with-sdp_debug_data-mod    make CONFIG_INFINIBAND_SDP_DEBUG_DATA=y [no]
    --without-sdp_debug_data-mod    [yes]

    --with-srp-mod    make CONFIG_INFINIBAND_SRP=m [no]
    --without-srp-mod    [yes]

    --with-srp-target-mod    make CONFIG_INFINIBAND_SRPT=m [no]
    --without-srp-target-mod    [yes]

    --with-user_mad-mod    make CONFIG_INFINIBAND_USER_MAD=m [no]
    --without-user_mad-mod    [yes]

    --with-user_access-mod    make CONFIG_INFINIBAND_USER_ACCESS=m [no]
    --without-user_access-mod    [yes]

    --with-addr_trans-mod    make CONFIG_INFINIBAND_ADDR_TRANS=y [no]
    --without-addr_trans-mod    [yes]

    --with-mthca-mod    make CONFIG_INFINIBAND_MTHCA=m [no]
    --without-mthca-mod    [yes]

    --with-mthca_debug-mod    make CONFIG_INFINIBAND_MTHCA_DEBUG=y [yes]
    --without-mthca_debug-mod    [no]

    --with-mlx4-mod         make CONFIG_MLX4_CORE=y CONFIG_MLX4_INFINIBAND=y [no]
    --without-mlx4-mod      [yes]

    --with-mlx4_core-mod         make CONFIG_MLX4_CORE=y [no]
    --without-mlx4_core-mod      [yes]

    --with-mlx4_en-mod         make CONFIG_MLX4_EN=y [no]
    --without-mlx4_en-mod      [yes]

    --with-mlx4_inf-mod         make CONFIG_MLX4_INFINIBAND=y [no]
    --without-mlx4_inf-mod      [yes]

    --with-mlx4_debug-mod         make CONFIG_MLX4_DEBUG=y [yes]
    --without-mlx4_debug-mod      [no]

    --with-ipath_inf-mod    make CONFIG_INFINIBAND_IPATH=m [no]
    --without-ipath_inf-mod    [yes]

    --with-iser-mod    make CONFIG_INFINIBAND_ISER=m [no]
    --without-iser-mod    [yes]

    --with-ehca-mod    make CONFIG_INFINIBAND_EHCA=m [no]
    --without-ehca-mod    [yes]

    --with-rds-mod    make CONFIG_RDS=m [no]
    --without-rds-mod   [no]

    --with-rds_debug-mod    make CONFIG_RDS_DEBUG=y [no]
    --without-rds_debug-mod    [yes]

    --with-madeye-mod   make CONFIG_INFINIBAND_MADEYE=m [no]
    --without-madeye-mod    [yes]

    --with-qlgc_vnic-mod    make CONFIG_INFINIBAND_QLGC_VNIC=m [no]
    --without-qlgc_vnic-mod    [yes]

    --with-qlgc_vnic_stats-mod    make CONFIG_INFINIBAND_QLGC_VNIC_STATS=y [no]
    --without-qlgc_vnic_stats-mod    [yes]

    --with-cxgb3-mod    make CONFIG_INFINIBAND_CXGB3=m [no]
    --without-cxgb3-mod    [yes]

    --with-cxgb3_debug-mod    make CONFIG_INFINIBAND_CXGB3_DEBUG=y [no]
    --without-cxgb3_debug-mod    [yes]

    --with-nes-mod    make CONFIG_INFINIBAND_NES=m [no]
    --without-nes-mod    [yes]

    --with-nes_debug-mod    make CONFIG_INFINIBAND_NES_DEBUG=y [no]
    --without-nes_debug-mod    [yes]

    --with-memtrack  enable momory tracking [no]
    --without-memtrack disable memory tracking [yes]

    --with-debug-info  make CONFIG_DEBUG_INFO=y [yes]
    --without-debug-info [no]

    --with-nfsrdma-mod    make CONFIG_SUNRPC_XPRT_RDMA=m [no]
    --without-nfsrdma-mod    [yes]

    --help - print out options


EOF

#   Currently not supported options
#    --with-sdp-zcopy  make CONFIG_INFINIBAND_SDP_SEND_ZCOPY=y CONFIG_INFINIBAND_SDP_RECV_ZCOPY=y [no]
#    --without-sdp-zcopy [yes]
}

# Execute command w/ echo and exit if it fail
ex()
{
        echo "$@"
        if ! "$@"; then
                printf "\nFailed executing $@\n\n"
                exit 1
        fi
}

# Compare 2 kernel versions
check_kerver()
{
        local kver=$1
        local min_kver=$2
        shift 2

        kver_a=$(echo -n ${kver} | cut -d '.' -f 1)
        kver_b=$(echo -n ${kver} | cut -d '.' -f 2)
        kver_c=$(echo -n ${kver} | cut -d '.' -f 3 | cut -d '-' -f 1 | tr -d [:alpha:][:punct:])

        min_kver_a=$(echo -n ${min_kver} | cut -d '.' -f 1)
        min_kver_b=$(echo -n ${min_kver} | cut -d '.' -f 2)
        min_kver_c=$(echo -n ${min_kver} | cut -d '.' -f 3 | cut -d '-' -f 1 | tr -d [:alpha:][:punct:])

        if [ ${kver_a} -lt ${min_kver_a} ] ||
                [[ ${kver_a} -eq ${min_kver_a} && ${kver_b} -lt ${min_kver_b} ]] ||
                [[ ${kver_a} -eq ${min_kver_a} && ${kver_b} -eq ${min_kver_b} && ${kver_c} -lt ${min_kver_c} ]]; then
                return 1
        fi

        return 0
}

main()
{
        ofed_patch_params=
        # Parsing parameters
        while [ ! -z "$1" ]
        do
                case $1 in
                        -prefix | --prefix | --prefi | --pref | --pre | --pr | --p | -p)
                                shift
                                prefix=$1
                                PREFIX="--prefix ${prefix}"
                        ;;
                        -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=* | -p=*)
                                prefix=`expr "x$1" : 'x[^=]*=\(.*\)'`
                                PREFIX="--prefix ${prefix}"
                        ;;
                        -kernel-version | --kernel-version | --kern-ver | --ker-ver)
                                ofed_patch_params="$ofed_patch_params $1"
                                shift
                                ofed_patch_params="$ofed_patch_params $1"
                                KVERSION=$1
                        ;;
                        -kernel-version=* | --kernel-version=* | --kern-ver=* | --ker-ver=*)
                                ofed_patch_params="$ofed_patch_params $1"
                                KVERSION=`expr "x$1" : 'x[^=]*=\(.*\)'`
                        ;;
                        -modules-dir | --modules-dir | --mod-dir)
                                shift
                                MODULES_DIR=$1
                        ;;
                        -modules-dir=* | --modules-dir=* | --mod-dir=*)
                                MODULES_DIR=`expr "x$1" : 'x[^=]*=\(.*\)'`
                        ;;
                        -kernel-sources | --kernel-sources | --kernel-src | --kern-src | --ker-src)
                                shift
                                KSRC=$1
                        ;;
                        -kernel-sources=* | --kernel-sources=* | --kernel-src=* | --kern-src=* | --ker-src=*)
                                KSRC=`expr "x$1" : 'x[^=]*=\(.*\)'`
                        ;;
                        -with-quilt | --with-quilt)
                                ofed_patch_params="$ofed_patch_params $1"
                                if [ ! -z "$2" ] && [ "`echo -n $2 | cut -c 1`" != '-' ]; then
                                        shift
                                        ofed_patch_params="$ofed_patch_params $1"
                                fi
                        ;;
                        -with-quilt=* | --with-quilt=*)
                                ofed_patch_params="$ofed_patch_params $1"
                        ;;
                        --without-quilt)
                                ofed_patch_params="$ofed_patch_params $1"
                        ;;
                        -with-patchdir | --with-patchdir)
                                ofed_patch_params="$ofed_patch_params $1"
                                shift
                                ofed_patch_params="$ofed_patch_params $1"
                        ;;
                        -with-patchdir=* | --with-patchdir=*)
                                ofed_patch_params="$ofed_patch_params $1"
                        ;;
                        --without-patch)
                                ofed_patch_params="$ofed_patch_params $1"
                        ;;
                        --with-kernel-fixes)
                                ofed_patch_params="$ofed_patch_params $1"
                        ;;
                        --without-kernel-fixes)
                                ofed_patch_params="$ofed_patch_params $1"
                        ;;
                        --with-hpage-patch)
                                ofed_patch_params="$ofed_patch_params $1"
                        ;;
                        --without-hpage-patch)
                                ofed_patch_params="$ofed_patch_params $1"
                        ;;
                        --with-backport-patches)
                                ofed_patch_params="$ofed_patch_params $1"
                        ;;
                        --without-backport-patches)
                                ofed_patch_params="$ofed_patch_params $1"
                        ;;
                        --with-memtrack)
                            CONFIG_MEMTRACK="m"
                        ;;
                        --without-memtrack)
                            CONFIG_MEMTRACK=
                        ;;
                        --with-debug-info)
                            CONFIG_DEBUG_INFO="y"
                        ;;
                        --without-debug-info)
                            CONFIG_DEBUG_INFO=
                        ;;
                        --with-core-mod)
                            CONFIG_INFINIBAND="m"
                        ;;
                        --without-core-mod)
                            CONFIG_INFINIBAND=
                        ;;
                        --with-ipoib-mod)
                            CONFIG_INFINIBAND_IPOIB="m"
                            CONFIG_INFINIBAND_IPOIB_CM="y"
                            CONFIG_INFINIBAND_IPOIB_DEBUG="y"
                        ;;
                        --without-ipoib-mod)
                            CONFIG_INFINIBAND_IPOIB=
                        ;;
                        --with-ipoib-cm)
                            CONFIG_INFINIBAND_IPOIB_CM="y"
                        ;;
                        --without-ipoib-cm)
                            CONFIG_INFINIBAND_IPOIB_CM=
                        ;;
                        --with-ipoib_debug-mod)
                            CONFIG_INFINIBAND_IPOIB_DEBUG="y"
                        ;;
                        --without-ipoib_debug-mod)
                            CONFIG_INFINIBAND_IPOIB_DEBUG=
                        ;;
                        --with-ipoib_debug_data-mod)
                            CONFIG_INFINIBAND_IPOIB_DEBUG_DATA="y"
                        ;;
                        --without-ipoib_debug_data-mod)
                            CONFIG_INFINIBAND_IPOIB_DEBUG_DATA=
                        ;;
                        --with-sdp-mod)
                            CONFIG_INFINIBAND_SDP="m"
                            CONFIG_INFINIBAND_SDP_DEBUG="y"
                        ;;
                        --without-sdp-mod)
                            CONFIG_INFINIBAND_SDP=
                        ;;
                        --with-sdp-zcopy)
                            CONFIG_INFINIBAND_SDP_SEND_ZCOPY="y"
                            CONFIG_INFINIBAND_SDP_RECV_ZCOPY="y"
                        ;;
                        --without-sdp-zcopy)
                            CONFIG_INFINIBAND_SDP_SEND_ZCOPY=
                            CONFIG_INFINIBAND_SDP_RECV_ZCOPY=
                        ;;
                        --with-sdp_debug-mod)
                            CONFIG_INFINIBAND_SDP_DEBUG="y"
                        ;;
                        --without-sdp_debug-mod)
                            CONFIG_INFINIBAND_SDP_DEBUG=
                        ;;
                        --with-sdp_debug_data-mod)
                            CONFIG_INFINIBAND_SDP_DEBUG_DATA="y"
                        ;;
                        --without-sdp_debug_data-mod)
                            CONFIG_INFINIBAND_SDP_DEBUG_DATA=
                        ;;
                        --with-srp-mod)
                            CONFIG_INFINIBAND_SRP="m"
                        ;;
                        --without-srp-mod)
                            CONFIG_INFINIBAND_SRP=
                        ;;
                        --with-srp-target-mod)
                            CONFIG_INFINIBAND_SRPT="m"
                        ;;
                        --without-srp-target-mod)
                            CONFIG_INFINIBAND_SRPT=
                        ;;
                        --with-user_mad-mod)
                            CONFIG_INFINIBAND_USER_MAD="m"
                        ;;
                        --without-user_mad-mod)
                            CONFIG_INFINIBAND_USER_MAD=
                        ;;
                        --with-user_access-mod)
                            CONFIG_INFINIBAND_USER_ACCESS="m"
                            CONFIG_INFINIBAND_USER_MEM=y
                        ;;
                        --without-user_access-mod)
                            CONFIG_INFINIBAND_USER_ACCESS=
                            CONFIG_INFINIBAND_USER_MEM=
                        ;;
                        --with-addr_trans-mod)
                            CONFIG_INFINIBAND_ADDR_TRANS=y
                        ;;
                        --without-addr_trans-mod)
                            CONFIG_INFINIBAND_ADDR_TRANS=
                        ;;
                        --with-mthca-mod)
                            CONFIG_INFINIBAND_MTHCA="m"
                            CONFIG_INFINIBAND_MTHCA_DEBUG="y"
                        ;;
                        --without-mthca-mod)
                            CONFIG_INFINIBAND_MTHCA=
                        ;;
                        --with-mthca_debug-mod)
                            CONFIG_INFINIBAND_MTHCA_DEBUG="y"
                        ;;
                        --without-mthca_debug-mod)
                            CONFIG_INFINIBAND_MTHCA_DEBUG=
                        ;;
                        --with-mlx4-mod)
                            CONFIG_MLX4_CORE="m"
                            CONFIG_MLX4_INFINIBAND="m"
                            CONFIG_MLX4_DEBUG="y"
                        ;;
                        --with-mlx4_core-mod)
                            CONFIG_MLX4_CORE="m"
                        ;;
                        --without-mlx4_core-mod)
                            CONFIG_MLX4_CORE=
                        ;;
			-without-mlx4-mod)
                            CONFIG_MLX4_CORE=
                            CONFIG_MLX4_INFINIBAND=
                            CONFIG_MLX4_DEBUG=
                        ;;
                        --with-mlx4_en-mod)
  			    CONFIG_MLX4_CORE="m"
                            CONFIG_MLX4_EN="m"
                        ;;
                        --without-mlx4_en-mod)
                            CONFIG_MLX4_EN=
                        ;;
                        --with-mlx4_inf-mod)
                            CONFIG_MLX4_CORE="m"
                            CONFIG_MLX4_INFINIBAND="m"
                        ;;
                        --without-mlx4_inf-mod)
                            CONFIG_MLX4_INFINIBAND=
                        ;;
                        --with-mlx4_debug-mod)
                            CONFIG_MLX4_DEBUG="y"
                        ;;
                        --without-mlx4_debug-mod)
                            CONFIG_MLX4_DEBUG=
                        ;;
                        --with-ipath_inf-mod)
                            CONFIG_INFINIBAND_IPATH="m"
                        ;;
                        --without-ipath_inf-mod)
                            CONFIG_INFINIBAND_IPATH=
                        ;;
                        --with-iser-mod)
                            CONFIG_INFINIBAND_ISER="m"
                            CONFIG_SCSI_ISCSI_ATTRS="m"
                            CONFIG_ISCSI_TCP="m"
                        ;;
                        --without-iser-mod)
                            CONFIG_INFINIBAND_ISER=
                            CONFIG_SCSI_ISCSI_ATTRS=
                            CONFIG_ISCSI_TCP=
                        ;;
                        --with-ehca-mod)
                            CONFIG_INFINIBAND_EHCA="m"
                            CONFIG_INFINIBAND_EHCA_SCALING="y"
                        ;;
                        --without-ehca-mod)
                            CONFIG_INFINIBAND_EHCA=
                            CONFIG_INFINIBAND_EHCA_SCALING=
                        ;;
                        --with-rds-mod)
                            CONFIG_RDS="m"
                            CONFIG_RDS_IB="m"
                            CONFIG_RDS_IWARP="m"
                        ;;
                        --without-rds-mod)
                            CONFIG_RDS=
                            CONFIG_RDS_IB=
                            CONFIG_RDS_IWARP=
                        ;;
                        --with-rds_debug-mod)
                            CONFIG_RDS_DEBUG="y"
                        ;;
                        --without-rds_debug-mod)
                            CONFIG_RDS_DEBUG=
                        ;;
                        --with-madeye-mod)
                            CONFIG_INFINIBAND_MADEYE=m
                        ;;
                        --without-madeye-mod)
                            CONFIG_INFINIBAND_MADEYE=
                        ;;
                        --with-qlgc_vnic-mod)
                            CONFIG_INFINIBAND_QLGC_VNIC="m"
                        ;;
                        --without-qlgc_vnic-mod)
                            CONFIG_INFINIBAND_QLGC_VNIC=
                        ;;
                        --with-qlgc_vnic_stats-mod)
                            CONFIG_INFINIBAND_QLGC_VNIC_STATS="y"
                        ;;
                        --without-qlgc_vnic_stats-mod)
                            CONFIG_INFINIBAND_QLGC_VNIC_STATS=
                        ;;
                        --with-cxgb3-mod)
                            CONFIG_INFINIBAND_CXGB3="m"
                            CONFIG_CHELSIO_T3="m"
                        ;;
                        --without-cxgb3-mod)
                            CONFIG_INFINIBAND_CXGB3=
                            CONFIG_CHELSIO_T3=
                        ;;
                        --with-cxgb3_debug-mod)
                            CONFIG_INFINIBAND_CXGB3_DEBUG="y"
                        ;;
                        --without-cxgb3_debug-mod)
                            CONFIG_INFINIBAND_CXGB3_DEBUG=
                        ;;
                        --with-nes-mod)
                            CONFIG_INFINIBAND_NES="m"
                        ;;
                        --without-nes-mod)
                            CONFIG_INFINIBAND_NES=
                        ;;
                        --with-nes_debug-mod)
                            CONFIG_INFINIBAND_NES_DEBUG="y"
                        ;;
                        --without-nes_debug-mod)
                            CONFIG_INFINIBAND_NES_DEBUG=
                        ;;
                        --with-nfsrdma-mod)
                            CONFIG_SUNRPC="m"
                            CONFIG_SUNRPC_GSS="m"
                            CONFIG_RPCSEC_GSS_KRB5="m"
                            CONFIG_RPCSEC_GSS_SPKM3="m"
                            CONFIG_SUNRPC_XPRT_RDMA="m"
                            CONFIG_NFS_FS="m"
                            CONFIG_NFS_V3="y"
                            CONFIG_NFS_V3_ACL="y"
			    CONFIG_NFS_V4="y"
                            CONFIG_NFS_ACL_SUPPORT="m"
                            CONFIG_NFS_DIRECTIO="y"
                            CONFIG_SYSCTL="y"
			    CONFIG_EXPORTFS="m"
                            CONFIG_LOCKD="m"
                            CONFIG_LOCKD_V4="y"
                            CONFIG_NFSD="m"
                            CONFIG_NFSD_V2_ACL="y"
                            CONFIG_NFSD_V3="y"
                            CONFIG_NFSD_V3_ACL="y"
                            CONFIG_NFSD_V4="y"
                            CONFIG_NFSD_RDMA="y"
                        ;;
                        --without-nfsrdma-mod)
                            CONFIG_SUNRPC=
                            CONFIG_SUNRPC_GSS=
                            CONFIG_RPCSEC_GSS_KRB5=
                            CONFIG_RPCSEC_GSS_SPKM3=
                            CONFIG_SUNRPC_XPRT_RDMA=
                            CONFIG_NFS_FS=
                            CONFIG_NFS_V3=
			    CONFIG_NFS_V4=
                            CONFIG_NFS_V3_ACL=
                            CONFIG_NFS_ACL_SUPPORT=
                            CONFIG_NFS_DIRECTIO=
                            CONFIG_SYSCTL=
			    CONFIG_EXPORTFS=
                            CONFIG_LOCKD=
                            CONFIG_LOCKD_V4=
                            CONFIG_NFSD=
                            CONFIG_NFSD_V2_ACL=
                            CONFIG_NFSD_V3=
                            CONFIG_NFSD_V3_ACL=
                            CONFIG_NFSD_V4=
                            CONFIG_NFSD_RDMA=
                        ;;
                        --with-modprobe|--without-modprobe)
                        ;;
                        -h | --help)
                                usage
                                exit 0
                        ;;
                        --with*)
                                echo
                                echo "Unsupported or unused parameter: $1"
                                echo
                        ;;
                        *)
                                echo
                                echo "Wrong parameter $1"
                                echo
                                usage
                                exit 1
                        ;;
                esac
                shift

        done

#Set default values
KVERSION=${KVERSION:-$(uname -r)}
MIN_KVERSION="2.6.5"
MODULES_DIR=${MODULES_DIR:-/lib/modules/${KVERSION}/updates}
KSRC=${KSRC:-/lib/modules/${KVERSION}/build}

ARCH=${ARCH:-$(uname -m)}

# Additional parameters to be passed to configure command
CWD=$(pwd)
CONFIG="configure.mk.kernel"

mkdir -p ${CWD}/include/linux
AUTOCONF_H="${CWD}/include/linux/autoconf.h"

CONFIG_MEMTRACK=${CONFIG_MEMTRACK:-''}
CONFIG_DEBUG_INFO=${CONFIG_DEBUG_INFO:-'y'}
CONFIG_INFINIBAND=${CONFIG_INFINIBAND:-''}
CONFIG_INFINIBAND_IPOIB=${CONFIG_INFINIBAND_IPOIB:-''}
CONFIG_INFINIBAND_IPOIB_CM=${CONFIG_INFINIBAND_IPOIB_CM:-''}
CONFIG_INFINIBAND_SDP=${CONFIG_INFINIBAND_SDP:-''}
CONFIG_INFINIBAND_SRP=${CONFIG_INFINIBAND_SRP:-''}
CONFIG_INFINIBAND_SRPT=${CONFIG_INFINIBAND_SRPT:-''}

CONFIG_INFINIBAND_USER_MAD=${CONFIG_INFINIBAND_USER_MAD:-''}
CONFIG_INFINIBAND_USER_ACCESS=${CONFIG_INFINIBAND_USER_ACCESS:-''}
CONFIG_INFINIBAND_ADDR_TRANS=${CONFIG_INFINIBAND_ADDR_TRANS:-''}
CONFIG_INFINIBAND_USER_MEM=${CONFIG_INFINIBAND_USER_MEM:-''}
CONFIG_INFINIBAND_MTHCA=${CONFIG_INFINIBAND_MTHCA:-''}

CONFIG_MLX4_CORE=${CONFIG_MLX4_CORE:-''}
CONFIG_MLX4_EN=${CONFIG_MLX4_EN:-''}
CONFIG_MLX4_INFINIBAND=${CONFIG_MLX4_INFINIBAND:-''}
CONFIG_MLX4_DEBUG=${CONFIG_MLX4_DEBUG:-''}

CONFIG_INFINIBAND_IPOIB_DEBUG=${CONFIG_INFINIBAND_IPOIB_DEBUG:-''}
CONFIG_INFINIBAND_ISER=${CONFIG_INFINIBAND_ISER:-''}
CONFIG_SCSI_ISCSI_ATTRS=${CONFIG_SCSI_ISCSI_ATTRS:-''}
CONFIG_ISCSI_TCP=${CONFIG_ISCSI_TCP:-''}
CONFIG_INFINIBAND_EHCA=${CONFIG_INFINIBAND_EHCA:-''}
CONFIG_INFINIBAND_EHCA_SCALING=${CONFIG_INFINIBAND_EHCA_SCALING:-''}
CONFIG_RDS=${CONFIG_RDS:-''}
CONFIG_RDS_IB=${CONFIG_RDS_IB:-''}
CONFIG_RDS_IWARP=${CONFIG_RDS_IWARP:-''}
CONFIG_RDS_DEBUG=${CONFIG_RDS_DEBUG:-''}
CONFIG_INFINIBAND_MADEYE=${CONFIG_INFINIBAND_MADEYE:-''}
CONFIG_INFINIBAND_QLGC_VNIC=${CONFIG_INFINIBAND_QLGC_VNIC:-''}
CONFIG_INFINIBAND_CXGB3=${CONFIG_INFINIBAND_CXGB3:-''}
CONFIG_CHELSIO_T3=${CONFIG_CHELSIO_T3:-''}
CONFIG_INFINIBAND_NES=${CONFIG_INFINIBAND_NES:-''}

CONFIG_SUNRPC_XPRT_RDMA=${CONFIG_SUNRPC_XPRT_RDMA:-''} 
CONFIG_SUNRPC=${CONFIG_SUNRPC:-''} 
CONFIG_SUNRPC_GSS=${CONFIG_SUNRPC_GSS:-''} 
CONFIG_RPCSEC_GSS_KRB5=${CONFIG_RPCSEC_GSS_KRB5:-''} 
CONFIG_RPCSEC_GSS_SPKM3=${CONFIG_RPCSEC_GSS_SPKM3:-''} 

CONFIG_NFS_FS=${CONFIG_NFS_FS:-''}
CONFIG_NFS_V3=${CONFIG_NFS_V3:-''}
CONFIG_NFS_V3_ACL=${CONFIG_NFS_V3_ACL:-''}
CONFIG_NFS_V4=${CONFIG_NFS_V4:-''}
CONFIG_NFS_ACL_SUPPORT=${CONFIG_NFS_ACL_SUPPORT:-''}
CONFIG_NFS_DIRECTIO=${CONFIG_NFS_DIRECTIO:-''}
CONFIG_SYSCTL=${CONFIG_SYSCTL:-''}

CONFIG_EXPORTFS=${CONFIG_EXPORTFS:-''}

CONFIG_LOCKD=${CONFIG_LOCKD:-''}
CONFIG_LOCKD_V4=${CONFIG_LOCKD_V4:-''}

CONFIG_NFSD=${CONFIG_NFSD:-''}
CONFIG_NFSD_V2_ACL=${CONFIG_NFSD_V2_ACL:-''}
CONFIG_NFSD_V3=${CONFIG_NFSD_V3:-''}
CONFIG_NFSD_V3_ACL=${CONFIG_NFSD_V3_ACL:-''}
CONFIG_NFSD_V4=${CONFIG_NFSD_V4:-''}
CONFIG_NFSD_RDMA=${CONFIG_NFSD_RDMA:-''}

CONFIG_INFINIBAND_IPOIB_DEBUG_DATA=${CONFIG_INFINIBAND_IPOIB_DEBUG_DATA:-''}
CONFIG_INFINIBAND_SDP_SEND_ZCOPY=${CONFIG_INFINIBAND_SDP_SEND_ZCOPY:-''}
CONFIG_INFINIBAND_SDP_RECV_ZCOPY=${CONFIG_INFINIBAND_SDP_RECV_ZCOPY:-''}
CONFIG_INFINIBAND_SDP_DEBUG=${CONFIG_INFINIBAND_SDP_DEBUG:-''}
CONFIG_INFINIBAND_SDP_DEBUG_DATA=${CONFIG_INFINIBAND_SDP_DEBUG_DATA:-''}
CONFIG_INFINIBAND_IPATH=${CONFIG_INFINIBAND_IPATH:-''}
CONFIG_INFINIBAND_MTHCA_DEBUG=${CONFIG_INFINIBAND_MTHCA_DEBUG:-''}
CONFIG_INFINIBAND_QLGC_VNIC_STATS=${CONFIG_INFINIBAND_QLGC_VNIC_STATS:-''}
CONFIG_INFINIBAND_CXGB3_DEBUG=${CONFIG_INFINIBAND_CXGB3_DEBUG:-''}
CONFIG_INFINIBAND_NES_DEBUG=${CONFIG_INFINIBAND_NES_DEBUG:-''}
CONFIG_INFINIBAND_AMSO1100=${CONFIG_INFINIBAND_AMSO1100:-''}

        # Check for minimal supported kernel version
        if ! check_kerver ${KVERSION} ${MIN_KVERSION}; then
                echo "Kernel version ${KVERSION} is less then supported kernel ${MIN_KVERSION}. Exiting..."
                exit 1
        fi

	if [ ! -e config.mk ]; then
		echo "config.mk does not exist. running ofed_patch.sh"
		ex ${CWD}/ofed_scripts/ofed_patch.sh ${ofed_patch_params}
	fi

        # Create configure.mk
        /bin/rm -f ${CWD}/${CONFIG}
        cat >> ${CWD}/${CONFIG} << EOFCONFIG
# Current working directory
CWD=${CWD}

# Kernel level
KVERSION=${KVERSION}
ARCH=${ARCH}
MODULES_DIR=${MODULES_DIR}
KSRC=${KSRC}

AUTOCONF_H=${AUTOCONF_H}

WITH_MAKE_PARAMS=${WITH_MAKE_PARAMS}

CONFIG_MEMTRACK=${CONFIG_MEMTRACK}
CONFIG_DEBUG_INFO=${CONFIG_DEBUG_INFO}
CONFIG_INFINIBAND=${CONFIG_INFINIBAND}
CONFIG_INFINIBAND_IPOIB=${CONFIG_INFINIBAND_IPOIB}
CONFIG_INFINIBAND_IPOIB_CM=${CONFIG_INFINIBAND_IPOIB_CM}
CONFIG_INFINIBAND_SDP=${CONFIG_INFINIBAND_SDP}
CONFIG_INFINIBAND_SRP=${CONFIG_INFINIBAND_SRP}
CONFIG_INFINIBAND_SRPT=${CONFIG_INFINIBAND_SRPT}

CONFIG_INFINIBAND_USER_MAD=${CONFIG_INFINIBAND_USER_MAD}
CONFIG_INFINIBAND_USER_ACCESS=${CONFIG_INFINIBAND_USER_ACCESS}
CONFIG_INFINIBAND_ADDR_TRANS=${CONFIG_INFINIBAND_ADDR_TRANS}
CONFIG_INFINIBAND_USER_MEM=${CONFIG_INFINIBAND_USER_MEM}
CONFIG_INFINIBAND_MTHCA=${CONFIG_INFINIBAND_MTHCA}

CONFIG_MLX4_CORE=${CONFIG_MLX4_CORE}
CONFIG_MLX4_EN=${CONFIG_MLX4_EN}
CONFIG_MLX4_INFINIBAND=${CONFIG_MLX4_INFINIBAND}
CONFIG_MLX4_DEBUG=${CONFIG_MLX4_DEBUG}

CONFIG_INFINIBAND_IPOIB_DEBUG=${CONFIG_INFINIBAND_IPOIB_DEBUG}
CONFIG_INFINIBAND_ISER=${CONFIG_INFINIBAND_ISER}
CONFIG_SCSI_ISCSI_ATTRS=${CONFIG_SCSI_ISCSI_ATTRS}
CONFIG_ISCSI_TCP=${CONFIG_ISCSI_TCP}
CONFIG_INFINIBAND_EHCA=${CONFIG_INFINIBAND_EHCA}
CONFIG_INFINIBAND_EHCA_SCALING=${CONFIG_INFINIBAND_EHCA_SCALING}
CONFIG_RDS=${CONFIG_RDS}
CONFIG_RDS_IB=${CONFIG_RDS_IB}
CONFIG_RDS_IWARP=${CONFIG_RDS_IWARP}
CONFIG_RDS_DEBUG=${CONFIG_RDS_DEBUG}
CONFIG_INFINIBAND_MADEYE=${CONFIG_INFINIBAND_MADEYE}
CONFIG_INFINIBAND_QLGC_VNIC=${CONFIG_INFINIBAND_QLGC_VNIC}
CONFIG_INFINIBAND_CXGB3=${CONFIG_INFINIBAND_CXGB3}
CONFIG_CHELSIO_T3=${CONFIG_CHELSIO_T3}
CONFIG_INFINIBAND_NES=${CONFIG_INFINIBAND_NES}

CONFIG_SUNRPC_XPRT_RDMA=${CONFIG_SUNRPC_XPRT_RDMA}
CONFIG_SUNRPC=${CONFIG_SUNRPC}
CONFIG_SUNRPC_GSS=${CONFIG_SUNRPC_GSS}
CONFIG_RPCSEC_GSS_KRB5=${CONFIG_RPCSEC_GSS_KRB5}
CONFIG_RPCSEC_GSS_SPKM3=${CONFIG_RPCSEC_GSS_SPKM3}

CONFIG_NFS_FS=${CONFIG_NFS_FS}
CONFIG_NFS_V3=${CONFIG_NFS_V3}
CONFIG_NFS_V3_ACL=${CONFIG_NFS_V3_ACL}
CONFIG_NFS_V4=${CONFIG_NFS_V4}
CONFIG_NFS_ACL_SUPPORT=${CONFIG_NFS_ACL_SUPPORT}
CONFIG_NFS_DIRECTIO=${CONFIG_NFS_DIRECTIO}
CONFIG_SYSCTL=${CONFIG_SYSCTL}
CONFIG_EXPORTFS=${CONFIG_EXPORTFS}
CONFIG_LOCKD=${CONFIG_LOCKD}
CONFIG_LOCKD_V4=${CONFIG_LOCKD_V4}
CONFIG_NFSD=${CONFIG_NFSD}
CONFIG_NFSD_V2_ACL=${CONFIG_NFSD_V2_ACL}
CONFIG_NFSD_V3=${CONFIG_NFSD_V3}
CONFIG_NFSD_V3_ACL=${CONFIG_NFSD_V3_ACL}
CONFIG_NFSD_V4=${CONFIG_NFSD_V4}
CONFIG_NFSD_RDMA=${CONFIG_NFSD_RDMA}

CONFIG_INFINIBAND_IPOIB_DEBUG_DATA=${CONFIG_INFINIBAND_IPOIB_DEBUG_DATA}
CONFIG_INFINIBAND_SDP_SEND_ZCOPY=${CONFIG_INFINIBAND_SDP_SEND_ZCOPY}
CONFIG_INFINIBAND_SDP_RECV_ZCOPY=${CONFIG_INFINIBAND_SDP_RECV_ZCOPY}
CONFIG_INFINIBAND_SDP_DEBUG=${CONFIG_INFINIBAND_SDP_DEBUG}
CONFIG_INFINIBAND_SDP_DEBUG_DATA=${CONFIG_INFINIBAND_SDP_DEBUG_DATA}
CONFIG_INFINIBAND_IPATH=${CONFIG_INFINIBAND_IPATH}
CONFIG_INFINIBAND_MTHCA_DEBUG=${CONFIG_INFINIBAND_MTHCA_DEBUG}
CONFIG_INFINIBAND_QLGC_VNIC_STATS=${CONFIG_INFINIBAND_QLGC_VNIC_STATS}
CONFIG_INFINIBAND_CXGB3_DEBUG=${CONFIG_INFINIBAND_CXGB3_DEBUG}
CONFIG_INFINIBAND_NES_DEBUG=${CONFIG_INFINIBAND_NES_DEBUG}
CONFIG_INFINIBAND_AMSO1100=${CONFIG_INFINIBAND_AMSO1100}

EOFCONFIG
        echo "Created ${CONFIG}:"
        cat ${CWD}/${CONFIG}

# Create autoconf.h
if [ "X${CONFIG_MEMTRACK}" == "Xm" ]; then
        DEFINE_MEMTRACK="#undef CONFIG_MEMTRACK\n#define CONFIG_MEMTRACK 1"
else
        DEFINE_MEMTRACK="/* CONFIG_MEMTRACK is not set */"
fi
if [ "X${CONFIG_DEBUG_INFO}" == "Xy" ]; then
        DEFINE_DEBUG_INFO="#undef CONFIG_DEBUG_INFO\n#define CONFIG_DEBUG_INFO 1"
else
        DEFINE_DEBUG_INFO="/* CONFIG_DEBUG_INFO is not set */"
fi
if [ "X${CONFIG_INFINIBAND}" == "Xm" ]; then
        DEFINE_INFINIBAND="#undef CONFIG_INFINIBAND\n#define CONFIG_INFINIBAND 1"
else
        DEFINE_INFINIBAND="/* CONFIG_INFINIBAND is not set */"
fi
if [ "X${CONFIG_INFINIBAND_IPOIB}" == "Xm" ]; then
        DEFINE_INFINIBAND_IPOIB="#undef CONFIG_INFINIBAND_IPOIB\n#define CONFIG_INFINIBAND_IPOIB 1"
else
        DEFINE_INFINIBAND_IPOIB="/* CONFIG_INFINIBAND_IPOIB is not set */"
fi
if [ "X${CONFIG_INFINIBAND_IPOIB_CM}" == "Xy" ]; then
        DEFINE_INFINIBAND_IPOIB_CM="#undef CONFIG_INFINIBAND_IPOIB_CM\n#define CONFIG_INFINIBAND_IPOIB_CM 1"
else
        DEFINE_INFINIBAND_IPOIB_CM="/* CONFIG_INFINIBAND_IPOIB_CM is not set */"
fi
if [ "X${CONFIG_INFINIBAND_SDP}" == "Xm" ]; then
        DEFINE_INFINIBAND_SDP="#undef CONFIG_INFINIBAND_SDP\n#define CONFIG_INFINIBAND_SDP 1"
else
        DEFINE_INFINIBAND_SDP="/* CONFIG_INFINIBAND_SDP is not set */"
fi
if [ "X${CONFIG_INFINIBAND_SRP}" == "Xm" ]; then
        DEFINE_INFINIBAND_SRP="#undef CONFIG_INFINIBAND_SRP\n#define CONFIG_INFINIBAND_SRP 1"
else
        DEFINE_INFINIBAND_SRP="/* CONFIG_INFINIBAND_SRP is not set */"
fi
if [ "X${CONFIG_INFINIBAND_SRPT}" == "Xm" ]; then
        DEFINE_INFINIBAND_SRPT="#undef CONFIG_INFINIBAND_SRPT\n#define CONFIG_INFINIBAND_SRPT 1"
else
        DEFINE_INFINIBAND_SRPT="/* CONFIG_INFINIBAND_SRPT is not set */"
fi
if [ "X${CONFIG_INFINIBAND_USER_MAD}" == "Xm" ]; then
        DEFINE_INFINIBAND_USER_MAD="#undef CONFIG_INFINIBAND_USER_MAD\n#define CONFIG_INFINIBAND_USER_MAD 1"
else
        DEFINE_INFINIBAND_USER_MAD="/* CONFIG_INFINIBAND_USER_MAD is not set */"
fi
if [ "X${CONFIG_INFINIBAND_USER_ACCESS}" == "Xm" ]; then
        DEFINE_INFINIBAND_USER_ACCESS="#undef CONFIG_INFINIBAND_USER_ACCESS\n#define CONFIG_INFINIBAND_USER_ACCESS 1"
else
        DEFINE_INFINIBAND_USER_ACCESS="/* CONFIG_INFINIBAND_USER_ACCESS is not set */"
fi
if [ "X${CONFIG_INFINIBAND_ADDR_TRANS}" == "Xy" ]; then
        DEFINE_INFINIBAND_ADDR_TRANS="#undef CONFIG_INFINIBAND_ADDR_TRANS\n#define CONFIG_INFINIBAND_ADDR_TRANS 1"
else
        DEFINE_INFINIBAND_ADDR_TRANS="/* CONFIG_INFINIBAND_ADDR_TRANS is not set */"
fi
if [ "X${CONFIG_INFINIBAND_USER_MEM}" == "Xy" ]; then
        DEFINE_INFINIBAND_USER_MEM="#undef CONFIG_INFINIBAND_USER_MEM\n#define CONFIG_INFINIBAND_USER_MEM 1"
else
        DEFINE_INFINIBAND_USER_MEM="/* CONFIG_INFINIBAND_USER_MEM is not set */"
fi
if [ "X${CONFIG_INFINIBAND_MTHCA}" == "Xm" ]; then
        DEFINE_INFINIBAND_MTHCA="#undef CONFIG_INFINIBAND_MTHCA\n#define CONFIG_INFINIBAND_MTHCA 1"
else
        DEFINE_INFINIBAND_MTHCA="/* CONFIG_INFINIBAND_MTHCA is not set */"
fi
if [ "X${CONFIG_MLX4_CORE}" == "Xm" ]; then
        DEFINE_MLX4_CORE="#undef CONFIG_MLX4_CORE\n#define CONFIG_MLX4_CORE 1"
else
        DEFINE_MLX4_CORE="/* CONFIG_MLX4_CORE is not set */"
fi
if [ "X${CONFIG_MLX4_EN}" == "Xm" ]; then
        DEFINE_MLX4_EN="#undef CONFIG_MLX4_EN\n#define CONFIG_MLX4_EN 1"
else
        DEFINE_MLX4_EN="/* CONFIG_MLX4_EN is not set */"
fi
if [ "X${CONFIG_MLX4_INFINIBAND}" == "Xm" ]; then
        DEFINE_MLX4_INFINIBAND="#undef CONFIG_MLX4_INFINIBAND\n#define CONFIG_MLX4_INFINIBAND 1"
else
        DEFINE_MLX4_INFINIBAND="/* CONFIG_MLX4_INFINIBAND is not set */"
fi
if [ "X${CONFIG_MLX4_DEBUG}" == "Xy" ]; then
        DEFINE_MLX4_DEBUG="#undef CONFIG_MLX4_DEBUG\n#define CONFIG_MLX4_DEBUG 1"
else
        DEFINE_MLX4_DEBUG="/* CONFIG_MLX4_DEBUG is not set */"
fi
if [ "X${CONFIG_INFINIBAND_IPOIB_DEBUG}" == "Xy" ]; then
        DEFINE_INFINIBAND_IPOIB_DEBUG="#undef CONFIG_INFINIBAND_IPOIB_DEBUG\n#define CONFIG_INFINIBAND_IPOIB_DEBUG 1"
else
        DEFINE_INFINIBAND_IPOIB_DEBUG="/* CONFIG_INFINIBAND_IPOIB_DEBUG is not set */"
fi
if [ "X${CONFIG_INFINIBAND_ISER}" == "Xm" ]; then
        DEFINE_INFINIBAND_ISER="#undef CONFIG_INFINIBAND_ISER\n#define CONFIG_INFINIBAND_ISER 1"
        DEFINE_SCSI_ISCSI_ATTRS="#undef CONFIG_SCSI_ISCSI_ATTRS\n#define CONFIG_SCSI_ISCSI_ATTRS 1"
        DEFINE_ISCSI_TCP="#undef CONFIG_ISCSI_TCP\n#define CONFIG_ISCSI_TCP 1"
else
        DEFINE_INFINIBAND_ISER="/* CONFIG_INFINIBAND_ISER is not set */"
        DEFINE_SCSI_ISCSI_ATTRS="/* CONFIG_SCSI_ISCSI_ATTRS is not set */"
        DEFINE_ISCSI_TCP="/* CONFIG_ISCSI_TCP is not set */"
fi
if [ "X${CONFIG_INFINIBAND_EHCA}" == "Xm" ]; then
        DEFINE_INFINIBAND_EHCA="#undef CONFIG_INFINIBAND_EHCA\n#define CONFIG_INFINIBAND_EHCA 1"
else
        DEFINE_INFINIBAND_EHCA="/* CONFIG_INFINIBAND_EHCA is not set */"
fi
if [ "X${CONFIG_INFINIBAND_EHCA_SCALING}" == "Xy" ]; then
        DEFINE_INFINIBAND_EHCA_SCALING="#undef CONFIG_INFINIBAND_EHCA_SCALING\n#define CONFIG_INFINIBAND_EHCA_SCALING 1"
else
        DEFINE_INFINIBAND_EHCA_SCALING="/* CONFIG_INFINIBAND_EHCA_SCALING is not set */"
fi
if [ "X${CONFIG_RDS}" == "Xm" ]; then
        DEFINE_RDS="#undef CONFIG_RDS\n#define CONFIG_RDS 1"
        DEFINE_RDS_IB="#undef CONFIG_RDS_IB\n#define CONFIG_RDS_IB 1"
        DEFINE_RDS_IWARP="#undef CONFIG_RDS_IWARP\n#define CONFIG_RDS_IWARP 1"
else
        DEFINE_RDS="/* CONFIG_RDS is not set */"
        DEFINE_RDS_IB="/* CONFIG_RDS_IB is not set */"
        DEFINE_RDS_IWARP="/* CONFIG_RDS_IWARP is not set */"
fi
if [ "X${CONFIG_RDS_DEBUG}" == "Xy" ]; then
        DEFINE_RDS_DEBUG="#undef CONFIG_RDS_DEBUG\n#define CONFIG_RDS_DEBUG 1"
else
        DEFINE_RDS_DEBUG="/* CONFIG_RDS_DEBUG is not set */"
fi
if [ "X${CONFIG_INFINIBAND_MADEYE}" == "Xm" ]; then
        DEFINE_INFINIBAND_MADEYE="#undef CONFIG_INFINIBAND_MADEYE\n#define CONFIG_INFINIBAND_MADEYE 1"
else
        DEFINE_INFINIBAND_MADEYE="/* CONFIG_INFINIBAND_MADEYE is not set */"
fi
if [ "X${CONFIG_INFINIBAND_IPOIB_DEBUG_DATA}" == "Xy" ]; then
        DEFINE_INFINIBAND_IPOIB_DEBUG_DATA="#undef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA\n#define CONFIG_INFINIBAND_IPOIB_DEBUG_DATA 1"
else
        DEFINE_INFINIBAND_IPOIB_DEBUG_DATA="/* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA is not set */"
fi
if [ "X${CONFIG_INFINIBAND_SDP_SEND_ZCOPY}" == "Xy" ]; then
        DEFINE_INFINIBAND_SDP_SEND_ZCOPY="#undef CONFIG_INFINIBAND_SDP_SEND_ZCOPY\n#define CONFIG_INFINIBAND_SDP_SEND_ZCOPY 1"
else
        DEFINE_INFINIBAND_SDP_SEND_ZCOPY="/* CONFIG_INFINIBAND_SDP_SEND_ZCOPY is not set */"
fi
if [ "X${CONFIG_INFINIBAND_SDP_RECV_ZCOPY}" == "Xy" ]; then
        DEFINE_INFINIBAND_SDP_RECV_ZCOPY="#undef CONFIG_INFINIBAND_SDP_RECV_ZCOPY\n#define CONFIG_INFINIBAND_SDP_RECV_ZCOPY 1"
else
        DEFINE_INFINIBAND_SDP_RECV_ZCOPY="/* CONFIG_INFINIBAND_SDP_RECV_ZCOPY is not set */"
fi
if [ "X${CONFIG_INFINIBAND_SDP_DEBUG}" == "Xy" ]; then
        DEFINE_INFINIBAND_SDP_DEBUG="#undef CONFIG_INFINIBAND_SDP_DEBUG\n#define CONFIG_INFINIBAND_SDP_DEBUG 1"
else
        DEFINE_INFINIBAND_SDP_DEBUG="/* CONFIG_INFINIBAND_SDP_DEBUG is not set */"
fi
if [ "X${CONFIG_INFINIBAND_SDP_DEBUG_DATA}" == "Xy" ]; then
        DEFINE_INFINIBAND_SDP_DEBUG_DATA="#undef CONFIG_INFINIBAND_SDP_DEBUG_DATA\n#define CONFIG_INFINIBAND_SDP_DEBUG_DATA 1"
else
        DEFINE_INFINIBAND_SDP_DEBUG_DATA="/* CONFIG_INFINIBAND_SDP_DEBUG_DATA is not set */"
fi
if [ "X${CONFIG_INFINIBAND_IPATH}" == "Xm" ]; then
        DEFINE_INFINIBAND_IPATH="#undef CONFIG_INFINIBAND_IPATH\n#define CONFIG_INFINIBAND_IPATH 1"
else
        DEFINE_INFINIBAND_IPATH="/* CONFIG_INFINIBAND_IPATH is not set */"
fi
if [ "X${CONFIG_INFINIBAND_MTHCA_DEBUG}" == "Xy" ]; then
        DEFINE_INFINIBAND_MTHCA_DEBUG="#undef CONFIG_INFINIBAND_MTHCA_DEBUG\n#define CONFIG_INFINIBAND_MTHCA_DEBUG 1"
else
        DEFINE_INFINIBAND_MTHCA_DEBUG="/* CONFIG_INFINIBAND_MTHCA_DEBUG is not set */"
fi
if [ "X${CONFIG_INFINIBAND_QLGC_VNIC}" == "Xm" ]; then
        DEFINE_INFINIBAND_QLGC_VNIC="#undef CONFIG_INFINIBAND_QLGC_VNIC\n#define CONFIG_INFINIBAND_QLGC_VNIC 1"
else
        DEFINE_INFINIBAND_QLGC_VNIC="/* CONFIG_INFINIBAND_QLGC_VNIC is not set */"
fi
if [ "X${CONFIG_INFINIBAND_QLGC_VNIC_STATS}" == "Xy" ]; then
        DEFINE_INFINIBAND_QLGC_VNIC_STATS="#undef CONFIG_INFINIBAND_QLGC_VNIC_STATS\n#define CONFIG_INFINIBAND_QLGC_VNIC_STATS 1"
else
        DEFINE_INFINIBAND_QLGC_VNIC_STATS="/* CONFIG_INFINIBAND_QLGC_VNIC_STATS is not set */"
fi
if [ "X${CONFIG_INFINIBAND_CXGB3}" == "Xm" ]; then
        DEFINE_INFINIBAND_CXGB3="#undef CONFIG_INFINIBAND_CXGB3\n#define CONFIG_INFINIBAND_CXGB3 1"
else
        DEFINE_INFINIBAND_CXGB3="/* CONFIG_INFINIBAND_CXGB3 is not set */"
fi
if [ "X${CONFIG_INFINIBAND_CXGB3_DEBUG}" == "Xy" ]; then
        DEFINE_INFINIBAND_CXGB3_DEBUG="#undef CONFIG_INFINIBAND_CXGB3_DEBUG\n#define CONFIG_INFINIBAND_CXGB3_DEBUG 1"
else
        DEFINE_INFINIBAND_CXGB3_DEBUG="/* CONFIG_INFINIBAND_CXGB3_DEBUG is not set */"
fi
if [ "X${CONFIG_CHELSIO_T3}" == "Xm" ]; then
        DEFINE_CHELSIO_T3="#undef CONFIG_CHELSIO_T3\n#define CONFIG_CHELSIO_T3 1"
else
        DEFINE_CHELSIO_T3="/* CONFIG_CHELSIO_T3 is not set */"
fi
if [ "X${CONFIG_INFINIBAND_NES}" == "Xm" ]; then
        DEFINE_INFINIBAND_NES="#undef CONFIG_INFINIBAND_NES\n#define CONFIG_INFINIBAND_NES 1"
else
        DEFINE_INFINIBAND_NES="/* CONFIG_INFINIBAND_NES is not set */"
fi
if [ "X${CONFIG_INFINIBAND_NES_DEBUG}" == "Xy" ]; then
        DEFINE_INFINIBAND_NES_DEBUG="#undef CONFIG_INFINIBAND_NES_DEBUG\n#define CONFIG_INFINIBAND_NES_DEBUG 1"
else
        DEFINE_INFINIBAND_NES_DEBUG="/* CONFIG_INFINIBAND_NES_DEBUG is not set */"
fi
if [ "X${CONFIG_INFINIBAND_AMSO1100}" == "Xm" ]; then
        DEFINE_INFINIBAND_AMSO1100="#undef CONFIG_INFINIBAND_AMSO1100\n#define CONFIG_INFINIBAND_AMSO1100 1"
else
        DEFINE_INFINIBAND_AMSO1100="/* CONFIG_INFINIBAND_AMSO1100 is not set */"
fi
if [ "X${CONFIG_SUNRPC_XPRT_RDMA}" == "Xm" ]; then
        DEFINE_SUNRPC_XPRT_RDMA="#undef CONFIG_SUNRPC_XPRT_RDMA\n#define CONFIG_SUNRPC_XPRT_RDMA 1"
        DEFINE_SUNRPC="#undef CONFIG_SUNRPC\n#define CONFIG_SUNRPC 1"
        DEFINE_SUNRPC_GSS="#undef CONFIG_SUNRPC_GSS\n#define CONFIG_SUNRPC_GSS 1"
        DEFINE_RPCSEC_GSS_KRB5="#undef CONFIG_RPCSEC_GSS_KRB5\n#define CONFIG_RPCSEC_GSS_KRB5 1"
        DEFINE_RPCSEC_GSS_SPKM3="#undef CONFIG_RPCSEC_GSS_SPKM3\n#define CONFIG_RPCSEC_GSS_SPKM3 1"
        DEFINE_NFS_FS="#undef CONFIG_NFS_FS\n#define CONFIG_NFS_FS 1"
        DEFINE_NFS_V3="#undef CONFIG_NFS_V3\n#define CONFIG_NFS_V3 1"
        DEFINE_NFS_V3_ACL="#undef CONFIG_NFS_V3_ACL\n#define CONFIG_NFS_V3_ACL 1"
        DEFINE_NFS_V4="#undef CONFIG_NFS_V4\n#define CONFIG_NFS_V4 1"
        DEFINE_NFS_ACL_SUPPORT="#undef CONFIG_NFS_ACL_SUPPORT\n#define CONFIG_NFS_ACL_SUPPORT 1"
        DEFINE_NFS_DIRECTIO="#undef CONFIG_NFS_DIRECTIO\n#define CONFIG_NFS_DIRECTIO 1"
        DEFINE_SYSCTL="#undef CONFIG_SYSCTL\n#define CONFIG_SYSCTL 1"
        DEFINE_EXPORTFS="#undef CONFIG_EXPORTFS\n#define CONFIG_EXPORTFS 1"
        DEFINE_LOCKD="#undef CONFIG_LOCKD\n#define CONFIG_LOCKD 1"
        DEFINE_LOCKD_V4="#undef CONFIG_LOCKD_V4\n#define CONFIG_LOCKD_V4 1"
        DEFINE_NFSD="#undef CONFIG_NFSD\n#define CONFIG_NFSD 1"
        DEFINE_NFSD_V2_ACL="#undef CONFIG_NFSD_V2_ACL\n#define CONFIG_NFSD_V2_ACL 1"
        DEFINE_NFSD_V3="#undef CONFIG_NFSD_V3\n#define CONFIG_NFSD_V3 1"
        DEFINE_NFSD_V3_ACL="#undef CONFIG_NFSD_V3_ACL\n#define CONFIG_NFSD_V3_ACL 1"
        DEFINE_NFSD_V4="#undef CONFIG_NFSD_V4\n#define CONFIG_NFSD_V4 1"
        DEFINE_NFSD_RDMA="#undef CONFIG_NFSD_RDMA\n#define CONFIG_NFSD_RDMA 1"
else
        DEFINE_SUNRPC_XPRT_RDMA="/* CONFIG_SUNRPC_XPRT_RDMA is not set */"
        DEFINE_SUNRPC="/* CONFIG_SUNRPC is not set */"
        DEFINE_SUNRPC_GSS="/* CONFIG_SUNRPC_GSS is not set */"
        DEFINE_RPCSEC_GSS_KRB5="/* CONFIG_RPCSEC_GSS_KRB5 is not set */"
        DEFINE_RPCSEC_GSS_SPKM3="/* CONFIG_RPCSEC_GSS_SPKM3 is not set */"
        DEFINE_NFS_FS="/* CONFIG_NFS_FS is not set */"
        DEFINE_NFS_V3="/* CONFIG_NFS_V3 is not set */"
        DEFINE_NFS_V3_ACL="/* CONFIG_NFS_V3_ACL is not set */"
        DEFINE_NFS_V4="/* CONFIG_NFS_V4 is not set */"
        DEFINE_NFS_ACL_SUPPORT="/* CONFIG_NFS_ACL_SUPPORT is not set */"
        DEFINE_NFS_DIRECTIO="/* CONFIG_NFS_DIRECTIO is not set */"
        DEFINE_SYSCTL="/* CONFIG_SYSCTL is not set */"
        DEFINE_EXPORTFS="/* CONFIG_EXPORTFS is not set */"
        DEFINE_LOCKD="/* CONFIG_LOCKD is not set */"
        DEFINE_LOCKD_V4="/* CONFIG_LOCKD_V4 is not set */"
        DEFINE_NFSD="/* CONFIG_NFSD is not set */"
        DEFINE_NFSD_V2_ACL="/* CONFIG_NFSD_V2_ACL is not set */"
        DEFINE_NFSD_V3="/* CONFIG_NFSD_V3 is not set */"
        DEFINE_NFSD_V3_ACL="/* CONFIG_NFSD_V3_ACL is not set */"
        DEFINE_NFSD_V4="/* CONFIG_NFSD_V4 is not set */"
        DEFINE_NFSD_RDMA="/* CONFIG_NFSD_RDMA is not set */"
fi
cat >> ${AUTOCONF_H} << EOFAUTOCONF
#ifndef __OFED_BUILD__
#include_next <linux/autoconf.h>
#else
#undef CONFIG_MEMTRACK
#undef CONFIG_DEBUG_INFO
#undef CONFIG_INFINIBAND
#undef CONFIG_INFINIBAND_IPOIB
#undef CONFIG_INFINIBAND_IPOIB_CM
#undef CONFIG_INFINIBAND_SDP
#undef CONFIG_INFINIBAND_SRP
#undef CONFIG_INFINIBAND_SRPT

#undef CONFIG_INFINIBAND_USER_MAD
#undef CONFIG_INFINIBAND_USER_ACCESS
#undef CONFIG_INFINIBAND_ADDR_TRANS
#undef CONFIG_INFINIBAND_USER_MEM
#undef CONFIG_INFINIBAND_MTHCA

#undef CONFIG_MLX4_CORE
#undef CONFIG_MLX4_DEBUG
#undef CONFIG_MLX4_EN
#undef CONFIG_MLX4_INFINIBAND

#undef CONFIG_INFINIBAND_IPOIB_DEBUG
#undef CONFIG_INFINIBAND_ISER
#undef CONFIG_INFINIBAND_EHCA
#undef CONFIG_INFINIBAND_EHCA_SCALING
#undef CONFIG_RDS
#undef CONFIG_RDS_IB
#undef CONFIG_RDS_IWARP
#undef CONFIG_RDS_DEBUG
#undef CONFIG_INFINIBAND_MADEYE
#undef CONFIG_INFINIBAND_QLGC_VNIC
#undef CONFIG_INFINIBAND_QLGC_VNIC_STATS
#undef CONFIG_INFINIBAND_CXGB3
#undef CONFIG_INFINIBAND_CXGB3_DEBUG
#undef CONFIG_CHELSIO_T3
#undef CONFIG_INFINIBAND_NES
#undef CONFIG_INFINIBAND_NES_DEBUG

#undef CONFIG_SUNRPC_XPRT_RDMA
#undef CONFIG_SUNRPC
#undef CONFIG_SUNRPC_GSS
#undef CONFIG_RPCSEC_GSS_KRB5
#undef CONFIG_RPCSEC_GSS_SPKM3
#undef CONFIG_NFS_FS
#undef CONFIG_NFS_V3
#undef CONFIG_NFS_V3_ACL
#undef CONFIG_NFS_V4
#undef CONFIG_NFS_ACL_SUPPORT
#undef CONFIG_NFS_DIRECTIO
#undef CONFIG_SYSCTL
#undef CONFIG_EXPORTFS
#undef CONFIG_LOCKD
#undef CONFIG_LOCKD_V4
#undef CONFIG_NFSD
#undef CONFIG_NFSD_V2_ACL
#undef CONFIG_NFSD_V3
#undef CONFIG_NFSD_V3_ACL
#undef CONFIG_NFSD_V4
#undef CONFIG_NFSD_RDMA

#undef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
#undef CONFIG_INFINIBAND_SDP_SEND_ZCOPY
#undef CONFIG_INFINIBAND_SDP_RECV_ZCOPY
#undef CONFIG_INFINIBAND_SDP_DEBUG
#undef CONFIG_INFINIBAND_SDP_DEBUG_DATA
#undef CONFIG_INFINIBAND_IPATH
#undef CONFIG_INFINIBAND_MTHCA_DEBUG
#undef CONFIG_INFINIBAND_AMSO1100
#endif

$(echo -e "${DEFINE_INFINIBAND}")
$(echo -e "${DEFINE_INFINIBAND_IPOIB}")
$(echo -e "${DEFINE_INFINIBAND_IPOIB_CM}")
$(echo -e "${DEFINE_INFINIBAND_SDP}")
$(echo -e "${DEFINE_INFINIBAND_SRP}")
$(echo -e "${DEFINE_INFINIBAND_SRPT}")

$(echo -e "${DEFINE_INFINIBAND_USER_MAD}")
$(echo -e "${DEFINE_INFINIBAND_USER_ACCESS}")
$(echo -e "${DEFINE_INFINIBAND_ADDR_TRANS}")
$(echo -e "${DEFINE_INFINIBAND_USER_MEM}")
$(echo -e "${DEFINE_INFINIBAND_MTHCA}")
$(echo -e "${DEFINE_INFINIBAND_QLGC_VNIC}")
$(echo -e "${DEFINE_INFINIBAND_CXGB3}")
$(echo -e "${DEFINE_CHELSIO_T3}")
$(echo -e "${DEFINE_INFINIBAND_NES}")

$(echo -e "${DEFINE_SUNRPC_XPRT_RDMA}")
$(echo -e "${DEFINE_SUNRPC}")
$(echo -e "${DEFINE_SUNRPC_GSS}")
$(echo -e "${DEFINE_RPCSEC_GSS_KRB5}")
$(echo -e "${DEFINE_RPCSEC_GSS_SPKM3}")
$(echo -e "${DEFINE_NFS_FS}")
$(echo -e "${DEFINE_NFS_V3}")
$(echo -e "${DEFINE_NFS_V3_ACL}")
$(echo -e "${DEFINE_NFS_V4}")
$(echo -e "${DEFINE_NFS_ACL_SUPPORT}")
$(echo -e "${DEFINE_NFS_DIRECTIO}")
$(echo -e "${DEFINE_SYSCTL}")
$(echo -e "${DEFINE_EXPORTFS}")
$(echo -e "${DEFINE_LOCKD}")
$(echo -e "${DEFINE_LOCKD_V4}")
$(echo -e "${DEFINE_NFSD}")
$(echo -e "${DEFINE_NFSD_V2_ACL}")
$(echo -e "${DEFINE_NFSD_V3}")
$(echo -e "${DEFINE_NFSD_V3_ACL}")
$(echo -e "${DEFINE_NFSD_V4}")
$(echo -e "${DEFINE_NFSD_RDMA}")

$(echo -e "${DEFINE_INFINIBAND_IPOIB_DEBUG}")
$(echo -e "${DEFINE_INFINIBAND_ISER}")
$(echo -e "${DEFINE_SCSI_ISCSI_ATTRS}")
$(echo -e "${DEFINE_ISCSI_TCP}")
$(echo -e "${DEFINE_INFINIBAND_EHCA}")
$(echo -e "${DEFINE_RDS}")
$(echo -e "${DEFINE_RDS_IB}")
$(echo -e "${DEFINE_RDS_IWARP}")
$(echo -e "${DEFINE_RDS_DEBUG}")
$(echo -e "${DEFINE_INFINIBAND_QLGC_VNIC_STATS}")
$(echo -e "${DEFINE_INFINIBAND_CXGB3_DEBUG}")
$(echo -e "${DEFINE_INFINIBAND_NES_DEBUG}")

$(echo -e "${DEFINE_MLX4_CORE}")
$(echo -e "${DEFINE_MLX4_EN}")
$(echo -e "${DEFINE_MLX4_INFINIBAND}")
$(echo -e "${DEFINE_MLX4_ETHERNET}")
$(echo -e "${DEFINE_MLX4_DEBUG}")

$(echo -e "${DEFINE_INFINIBAND_IPOIB_DEBUG_DATA}")
$(echo -e "${DEFINE_INFINIBAND_SDP_SEND_ZCOPY}")
$(echo -e "${DEFINE_INFINIBAND_SDP_RECV_ZCOPY}")
$(echo -e "${DEFINE_INFINIBAND_SDP_DEBUG}")
$(echo -e "${DEFINE_INFINIBAND_SDP_DEBUG_DATA}")
$(echo -e "${DEFINE_INFINIBAND_IPATH}")
$(echo -e "${DEFINE_INFINIBAND_MTHCA_DEBUG}")
$(echo -e "${DEFINE_INFINIBAND_MADEYE}")
$(echo -e "${DEFINE_INFINIBAND_AMSO1100}")

EOFAUTOCONF

        echo "Created ${AUTOCONF_H}:"
        cat ${AUTOCONF_H}
}

main $@
