#/*******************************************************************
# * This file is part of the Emulex Linux Device Driver for         *
# * Fibre Channel Host Bus Adapters.                                *
# * Refer to the README file included with this package for         *
# * driver version and adapter support.                             *
# * Copyright (C) 2003-2005 Emulex.  All rights reserved.           *
# * www.emulex.com                                                  *
# *                                                                 *
# * This program is free software; you can redistribute it and/or   *
# * modify it under the terms of the GNU General Public License     *
# * as published by the Free Software Foundation; either version 2  *
# * of the License, or (at your option) any later version.          *
# *                                                                 *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of  *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *
# * GNU General Public License for more details, a copy of which    *
# * can be found in the file COPYING included with this package.    *
# *******************************************************************/
# This Makefile builds the lpfc driver for 2.4 Linux kernels.
######################################################################

# $Id: Makefile-2.4.mk 1.5 2005/05/03 11:20:34EDT sf_support Exp  $

# Driver name
LPFC = lpfcdd_732

ifeq (,$(KERNELVERSION))
   KERNELVERSION := $(shell $(TC_UNAME) -r)
endif

ifeq (,$(BASEINCLUDE))
   BASEINCLUDE := $(TOPDIR)
endif

CROSS_COMPILE_PREFIX=
ifeq ($(shell $(TC_UNAME) -m),ppc64)
ifeq (,$(CROSS_COMPILE))
CROSS_COMPILE_PREFIX := $(shell if [ -e /usr/local/ppc64-current3.0/bin/powerpc64-linux-gcc ]; then \
    echo /usr/local/ppc64-current3.0/bin/powerpc64-linux-; \
    else if [ -e /opt/cross/bin/powerpc64-linux-gcc ]; then \
    echo /opt/cross/bin/powerpc64-linux- ; fi fi)
endif
endif

lpfc-objs := lpfc_clock.o lpfc_logmsg.o lpfc_mem.o lpfc_sli.o		\
lpfc_fcp.o lpfc_ct.o lpfc_els.o lpfc_hbadisc.o lpfc_init.o		\
lpfc_mbox.o lpfc_nportdisc.o lpfc_scsiport.o lpfc_sched.o

ifeq ($(CONFIG_SCSI_LPFC_732),)

build: $(LPFC).o

%.o : %.c lpfc.conf
	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $<

install: bkcompat
	@$(TC_INSTALL) -d $(MODLIB)/kernel/drivers/scsi/lpfc;
	@$(TC_INSTALL) -c ../$(LPFC).o $(MODLIB)/kernel/drivers/scsi/lpfc;
	$(TC_DEPMOD) -a

endif


RH := $(shell if [ -e $(TC_RHEL3ROOT)/usr/src/packages ]; then echo $(TC_RHEL3ROOT)/usr/src/packages; \
   else echo $(TC_RHEL3ROOT)/usr/src/redhat; fi)
USE_HIGHMEM_IO = 0
ifeq ($(RH),$(TC_RHEL3ROOT)/usr/src/redhat)
BASERH = redhat
else
BASERH = packages
USE_HIGHMEM_IO = 3
endif

# Change  the value to 20 in the following line if varyio is desired in SLES 8.
SLES_VARYIO = 1
# The following variable controls VARYIO support:
# If
# VARYIO=1, the system will attempt to configure VARYIO support automatically
# VARYIO=20, we set ".can_do_vary = 1" in the Scsi_Host_Template (Ex: SLES, AS2.1/IA64)
# VARYIO=21, we use SCSI_HOST_VARYIO macro (Ex: AS2.1/x86)
# VARYIO=3, we set ".vary_io = 1" in the Scsi_Host_Template (Ex: AS3.0)
# any other value of VARYIO will disable VARYIO support (Ex: RH 9.0)

VARYIO = $(SLES_VARYIO)
ifeq ($(VARYIO),1)
  VARYIO = 0 
  ifeq ($(findstring release 2,$(shell $(TC_CAT) $(TC_RHEL3ROOT)/etc/redhat-release  2>/dev/null)),release 2)
     ifeq ($(ARCH),i386)
             VARYIO = 21
             USE_HIGHMEM_IO = 2
     else
             USE_HIGHMEM_IO = 3
             VARYIO = 20
     endif
  else
    ifeq ($(findstring release 3,$(shell $(TC_CAT) $(TC_RHEL3ROOT)/etc/redhat-release  2>/dev/null)),release 3)
       VARYIO = 3
       USE_HIGHMEM_IO = 3
    endif
  endif
endif


EXTRA_CFLAGS +=  -I.
EXTRA_CFLAGS += -DVARYIO=$(VARYIO) -DUSE_HIGHMEM_IO=$(USE_HIGHMEM_IO)
EXTRA_CFLAGS += -DUSE_SCHEDULER

ifneq ($(CONFIG_SCSI_LPFC_732),)
 EXTRA_CFLAGS += -I..
else
 EXTRA_CFLAGS += -I$(BASEINCLUDE)/drivers/scsi
 EXTRA_CFLAGS += $(MODFLAGS)
endif

$(LPFC).o: $(lpfc-objs)
	$(LD) -r -o ../$(LPFC).o $(lpfc-objs)

modules_install: bkcompat
#	@$(TC_MKDIR) -p $(MODLIB)/kernel/$(MOD_DESTDIR)/../net;
#	@$(TC_MV) $(MODLIB)/kernel/$(MOD_DESTDIR)/lpfn.o $(MODLIB)/kernel/$(MOD_DESTDIR)/../net

bkcompat:
	@$(TC_RM) -f $(MODLIB)/kernel/drivers/scsi/$(LPFC).o

ifneq ($(CONFIG_SCSI_LPFC_732),)
 obj-$(CONFIG_SCSI_LPFC_732) += $(LPFC).o
 include $(TOPDIR)/Rules.make
endif

clean:
	$(TC_RM) -f *.o
	../$(LPFC).o
