#!/bin/bash

# Author: Eric Moore<eric.moore@lsi.com>
# Date: January 8, 2008
# Name: compile
# Description: A script compiling the driver source.


# enable scripting debug
# set -x

# add some sed+grep line to add following to kernel .config when not
# already there
# CONFIG_SCSI_MPT2SAS, CONFIG_SCSI_MPT2SAS_MAX_SGE, CONFIG_SCSI_MPT2SAS_LOGGING
KERNEL="`uname -r`"
#KERNEL="2.6.18-8.el5"
#KERNEL="2.6.18-53.el5"
CONFIG_PATH="/lib/modules/${KERNEL}/build/.config"
if [ `grep -c CONFIG_SCSI_MPT2SAS ${CONFIG_PATH}` -eq 0 ]; then
	echo -e \\n >> ${CONFIG_PATH};
	echo "CONFIG_SCSI_MPT2SAS=m" >> ${CONFIG_PATH};
	echo "CONFIG_SCSI_MPT2SAS_MAX_SGE=128"  >> ${CONFIG_PATH};
	echo "CONFIG_SCSI_MPT2SAS_LOGGING=y" >> ${CONFIG_PATH};
fi;

# Sparse - a semantic parser, provides a set of annotations designed to convey
# semantic information about types, such as what address space pointers point
# to, or what locks a function acquires or releases. You can obtain the latest
# sparse code by typing the following command:
# git clone git://git.kernel.org/pub/scm/devel/sparse/sparse.git

# Set SPARSE to non-zero value to enable sparse checking
SPARSE=0

rm -fr output.log
./clean
ctags -R *

if [ ${SPARSE} == 0 ] ; then
	make -j4 CONFIG_DEBUG_INFO=1 -C /lib/modules/${KERNEL}/build \
		M=`pwd` 2>&1 | tee output.log
else
	make C=2 CONFIG_DEBUG_INFO=1 -C /lib/modules/${KERNEL}/build \
		M=`pwd` 2>&1 | tee output.log
fi;
