#
# Copyright (c) 2011-2015, Emulex
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
#    this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

KMOD = ocs_iscsi_ramd
OS		= ../common
OCS		= ../../common/ocs
HAL		= ../../common/ihal
XPORT		= ../../common/ocs_iscsi
TARGET		= ../../common/ocs_ramd
INITIATOR	= ../../common/ocs_template
OCS_OPENISCSI	= ../ocs_openiscsi/

# include ocs_template to get the template structures, and the template back-end
# initiator driver
#INITIATOR = ../../common/ocs_template

ifndef KERN_VERS
       KERN_VERS=$(shell uname -r)
endif
ifndef VERSION
        VERSION=$(shell pwd|cut -f5 -d/)
endif

EXTRA_CFLAGS += -g -Werror -DOCS_INCLUDE_DEBUG -DOCS_QUEUE_LIMIT=256
EXTRA_CFLAGS += -Wextra -Wno-missing-field-initializers -Wall -Wno-unused-parameter -Wno-ignored-qualifiers
EXTRA_CFLAGS += -Wframe-larger-than=2048

SRC_TAR = $(KMOD)-src.tgz
DOC_TAR = $(KMOD)-doc.tgz

obj-m := $(KMOD).o

ccflags-y :=	-I$(src) -I$(src)/$(HAL) -I$(src)/$(OCS) -I$(src)/$(XPORT) -I$(src)/$(TARGET) -I$(src)/$(OS) \
		-I$(src)/$(INITIATOR)

$(KMOD)-y := \
	$(OS)/ocs_lnx.o \
	$(OS)/ocs_os.o \
	$(XPORT)/ocs_driver.o \
	$(XPORT)/ocs_debug.o \
	$(XPORT)/ocs_iscsi.o \
	$(XPORT)/ocs_iscsi_api.o \
	$(XPORT)/ocs_cxn.o \
	$(XPORT)/ocs_login.o \
	$(XPORT)/ocs_elxu.o \
	$(XPORT)/ocs_scsi.o \
	$(XPORT)/ocs_session.o \
	$(XPORT)/ocs_ddump.o \
	$(XPORT)/ocs_domain.o \
	$(XPORT)/ocs_sport.o \
	$(XPORT)/ocs_io.o \
	$(XPORT)/ocs_mgmt.o \
	$(XPORT)/ocs_md5.o \
	$(XPORT)/ocs_xport.o \
	$(XPORT)/ocs_isns.o \
	$(HAL)/ocs_hal.o \
	$(HAL)/ocs_sm.o \
	$(HAL)/sli4.o \
	$(HAL)/sli4_iscsi.o \
	$(HAL)/sli4_be3_iscsi.o \
	$(HAL)/sli4_skh_iscsi.o \
	$(HAL)/ocs_hal_workaround.o \
	$(TARGET)/ocs_ramdisc.o \
	$(TARGET)/ocs_ramd.o \
	$(TARGET)/ocs_ramd_thread.o \
	$(TARGET)/mode_sense.o \
	$(INITIATOR)/ocs_ini_template.o \
	$(OCS)/ocs_textbuf.o \
	$(OCS)/ocs_mgmt_common.o \
	$(OCS)/ocs_ramlog.o \
	$(OCS)/ocs_dif.o \
	$(OCS)/t10crc16.o \
	$(OCS)/ocs_list.o \
	$(OCS)/ocs_ioctl.o \
	$(OCS)/ocs_ioctl_iscsi.o \
	$(OCS)/ocs_ddumplib.o \
	$(OCS)/ocs_pm.o \
	$(OCS)/ocs_cbuf.o \
	$(OCS)/ocs_array.o \
        $(OCS)/ocs_pool.o

clean-files := $($(KMOD)-y)

# files from this directory to include in a release
RELEASE_FILES = \
	Doxyfile \
	DoxygenLayout.xml \
	main.doxygen \
	Makefile \
	ocs.h \
	ocs_iscsi_ramd-doc.tgz \
	README \
	version.h

all:
	make -C /lib/modules/$(KERN_VERS)/build M=$(PWD) modules
	@sh $(OCS_OPENISCSI)/ocs_gen_incl.sh $(OCS_OPENISCSI) "$(TARGET)" "$(PWD)/Module.symvers"

clean:
	make -C /lib/modules/$(KERN_VERS)/build M=$(PWD) $@
	@rm -f $(SRC_TAR) $(DOC_TAR)
	@rm -rf doc doxygen.log

list_release_files:
	@echo $(RELEASE_FILES)

docdist:
	@echo "Creating document tar file: ${KMOD}-doc.tgz"
	@doxygen > doxygen.log 2>&1
	@cp ../../common/doxy/images/linux_ocs_iscsi_ramd/*.jpg doc/html
	@cp ../../common/doxy/images/common/*.png doc/html
	@tar cfz ${DOC_TAR} doc

install:
	@echo "Installing $(KMOD).ko"
	@cp $(KMOD).ko /lib/modules/$(KERN_VERS)/extra
	@/sbin/depmod -a

uninstall:
	@echo "Removing $(KMOD).ko"
	@rm -I /lib/modules/$(KERN_VERS)/extra/$(KMOD).ko
	@/sbin/depmod -a

