#
# This Makefile is intended to be used when the iSCSI driver is
# built on a Linux 2.6.0 Platform. Copy it to Makefile.
#
#   vi: set autoindent tabstop=8 shiftwidth=4 :
#
# Makefile for the Linux UNH iSCSI driver in 2.6 Environment
# 09/10/03 Matt Wilcox. Original draft.
# 09/25/03 John Donnelly At HP dott Com.
#
# Misc notes.
# To Make
# - Within a kernel tree :  Copy the unh_iscsi/src to Linux Kernel
#			under drivers/scsi/unh_iscsi/ . then execute:
#			make V=1 drivers/scsi/unh_iscsi/
# - Standalone: make 
#
# To Clean :  make clean 
# To create a RPM :  make rpm 
#

# use of KERNEL_VER contributed by Charles Coffing, ccoffing@novell.com
ifndef KERNEL_VER
KERNEL_VER := `uname -r`
endif

ifndef KERNEL_DIR
KERNEL_DIR = /lib/modules/$(KERNEL_VER)/build
endif

EXTRA_CFLAGS += -Idrivers/scsi
EXTRA_CFLAGS += -I../common
EXTRA_CFLAGS += -I../security/chap
EXTRA_CFLAGS += -I../security/srp
EXTRA_CFLAGS += -I../security/hash

EXTRA_CFLAGS += -fsigned-char

# define ISCSI_STATS in order to compile in code that dynamically accumulates
# statistics about the number of pdus of each type send and received, etc.
# also need to define this to display those statistics via /proc
# you probably always want this defined
EXTRA_CFLAGS += -DISCSI_STATS

# define ISCSI_CHECK_MEMORY in order to compile in code that
# tracks all calls to kmalloc and kfree to ensure that something is not
# freed if it has not been previously allocated, and, at the end, prints
# any allocated but unfreed memory and gives the maximum number of
# allocated memory slots -- see common/my_memory.h and common/my_memory.c.
# you want this defined during all development and testing
# undefine it when you are confident there are no memory leaks in the code!
#EXTRA_CFLAGS += -DISCSI_CHECK_MEMORY

# define CONFIG_ISCSI_DEBUG in order to compile in code that enables dynamic
# tracing and printing -- see common/debug.h and common/debug.c for details.
# this code enables tracing to be dynamically and selectively enabled/disabled.
# you want this defined during all development and testing
# undefine it when you want top performance and have completely debugged
# both the target and the initiator.
EXTRA_CFLAGS += -DCONFIG_ISCSI_DEBUG

# define ISCSI_CHECK_PDU_FORMAT in order to compile in code that checks
# the unused/reserved fields of every received pdu to ensure that they have
# been set to the proper value (normally 0, but sometimes 0xffffffff).
# Also checks for other inconsistencies between fields within a pdu,
# and other violations of the standard (such as sequences that are too
# long) which can safely be ignored without damage under the philosopy
# "conservative in what you send, liberal in what you receive".
# see initiator/initiator_rx.c for most uses of this symbol.
# you want this defined during all development and testing
# undefine it when you are sure the other side always builds pdus correctly.
EXTRA_CFLAGS += -DISCSI_CHECK_PDU_FORMAT

# define UNH_LOCK_DEBUG in order to compile in code that checks the usage
# of the UNH_LOCK and UNH_UNLOCK macros, on both uniprocessors and smp
# machines (this helps detect lock/unlock mismatches even on uniprocessor
# machines where spinlocks are normally nops.
# you want this defined during all development, especially on SMP machines
# undefine it when all the locks have been thoroughly debugged.
#EXTRA_CFLAGS += -DUNH_LOCK_DEBUG

# define K26 in order to compile in code for the 2.6 kernels (and to compile
# out code for the 2.4 kernels).  When defining this you should MUST be
# using this version of the Makefile (Makefile-26) -- see README.
# you ALWAYS want this defined when using this Makefile!
EXTRA_CFLAGS += -DK26

# define FC2 in order to compile in code for the 2.6 kernels in Fedora Core 2.
# For some reason, RedHat has added an extra (5th) parameter to the
# kernel function sock_create()!  The standard kernel has only 4 parameters.
# This symbol is referenced in only 2 files: initiator/iscsi_initiator.c and
# target/iscsi_target.c (because those are the only 2 places where
# sock_create() is called).
# undefine it ONLY when you are compiling for Fedore Core 2 and the 2.6 kernel.
#EXTRA_CFLAGS += -DFC2

EXTRA_LDFLAGS += -t

SECURITY_OBJS := $(addprefix security/, chap/chap.o hash/sha1.o hash/md5.o \
	math/bigint.o misc/misc_func.o srp/srp.o)

ICOMMON_OBJS := $(addprefix common/, iscsi_common.o my_memory.o range.o \
	debug.o crc.o tcp_utilities.o text_param.o initiator_negotiate.o)

TCOMMON_OBJS := $(addprefix common/, iscsi_common.o my_memory.o range.o \
	debug.o crc.o tcp_utilities.o text_param.o target_negotiate.o)

COMMON_OBJS := $(addprefix common/, lun_packing.o)

INITIATOR_OBJS := $(addprefix initiator/,iscsi_initiator.o \
	initiator_utilities.o initiator_error_rec.o initiator_proc_iface.o \
	initiator_rx.o initiator_tx.o iscsi_device.o)

ITARGET_OBJS := $(addprefix target/, iscsi_target.o target_error_rec.o \
	iscsi_portal_group.o )

SCSI_OBJS := $(addprefix target/, scsi_target.o )

unh_iscsi_initiator-objs   := $(SECURITY_OBJS) $(ICOMMON_OBJS) $(COMMON_OBJS) \
         $(INITIATOR_OBJS)

unh_iscsi_target-objs   := $(SECURITY_OBJS) $(TCOMMON_OBJS) $(COMMON_OBJS) \
         $(ITARGET_OBJS)

unh_scsi_target-objs   := $(COMMON_OBJS) $(SCSI_OBJS)

ifeq ($(CONFIG_USERMODE),)
obj-m += unh_iscsi_initiator.o unh_iscsi_target.o unh_scsi_target.o
endif

all: iscsi cmd

modules: version
	$(MAKE) -C $(KERNEL_SOURCE) KERNEL_SOURCE=$(KERNEL_SOURCE) SUBDIRS=$(CURDIR)
install:
	$(MAKE) -C $(KERNEL_SOURCE) modules_add KERNEL_SOURCE=$(KERNEL_SOURCE) SUBDIRS=$(CURDIR)

# use of KERNEL_VER contributed by Charles Coffing, ccoffing@novell.com
version:
	$(shell /bin/echo "#define OUR_NAME \"UNH-IOL iSCSI Initiator. RPM: `cat initiator/RPM | grep -v ^#`. Kernel: $(KERNEL_VER). Built on `date`. \"" > initiator/version.h)

cscope:
	find . -name "*.[csh]" -print > cscope.files 
	 cscope -b
iscsi: version
	make -C $(KERNEL_DIR) SUBDIRS=`pwd` 
	make -C cmd
cmd:
	make -C cmd

.PHONY: clean

#
# Standard clean 
#
clean:

	@for i in ` find . -name "*.ko" -o -name ".*.o.*" -o  -name "*.o"`; do \
	(if [ -f $$i ] ; \
		then \
			echo $$i; \
			rm $$i ; \
			else \
		: ;\
	fi); \
	done
	rm -rf .tmp_versions
	rm -f initiator/version.h
	make -C cmd clean
	rm -f *.mod.c .*cmd

rpm: clean
	tar cf /usr/src/redhat/SOURCES/unh_iscsi.tar  .
	gzip -f /usr/src/redhat/SOURCES/unh_iscsi.tar
	rpmbuild -ba unh_iscsi.specfile

# For SuSE && UnitedLinux - Note pathname differences
suse_rpm: clean
	tar cf /usr/src/packages/SOURCES/unh_iscsi.tar  .
	gzip -f /usr/src/packages/SOURCES/unh_iscsi.tar
	rpm -ba unh_iscsi.specfile


tarball: clean
#
# Generate a tarball named from the spec file (unh_iscsi-1.5.03.tar.gz)
#
	cmd/tar.sh

















