#/*******************************************************************
# * 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 lpfcdfc module for 2.4 Linux kernels.
######################################################################

# $Id: Makefile-2.4.mk 328 2005-05-03 15:20:43Z sf_support $

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

ifeq (,$(BASEINCLUDE))
   BASEINCLUDE := /lib/modules/$(KERNELVERSION)/build
endif

ifeq ($(shell uname -m),ppc64)
ifndef ($(CROSS_COMPILE))
CROSS_COMPILE := $(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

lpfcdfc-objs := lpfc_cdev.o lpfc_util_ioctl.o lpfc_hbaapi_ioctl.o lpfc_debug_ioctl.o ../lpfc_logmsg.o

ifeq ($(CONFIG_SCSI_LPFC_IOCTLS),)
 CFLAGS := $(shell make -C $(BASEINCLUDE) -s script "SCRIPT=echo \$$(CFLAGS)")
 ARCH := $(shell make -C $(BASEINCLUDE) -s script "SCRIPT=echo \$$(ARCH)")
 MODFLAGS := $(shell make CONFIG_MODULES=1 CONFIG_MODVERSIONS=1 -C $(BASEINCLUDE) -s script "SCRIPT=echo \$$(MODFLAGS)")
 CC := $(CROSS_COMPILE)$(shell make -C $(BASEINCLUDE) -s script "SCRIPT=echo \$$(CC)")
 MODLIB := /lib/modules/${KERNELVERSION}
 LD := $(CROSS_COMPILE)$(shell make -C $(BASEINCLUDE) -s script "SCRIPT=echo \$$(LD)")

build: lpfcdfc.o

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

install:
	@install -d $(MODLIB)/kernel/drivers/scsi/lpfc;
	@install -c lpfcdfc.o $(MODLIB)/kernel/drivers/scsi/lpfc;
	depmod -a

remove:
	if [ -e $(MODLIB)/kernel/drivers/scsi/lpfc/lpfcdfc.o ] ; then \
	    rm -f $(MODLIB)/kernel/drivers/scsi/lpfc/lpfcdfc.o ; \
	fi
	if [ -e $(MODLIB)/kernel/drivers/scsi/lpfcdfc.o ] ; then \
	    rm -f $(MODLIB)/kernel/drivers/scsi/lpfcdfc.o ; \
	fi
	depmod -a
endif

EXTRA_CFLAGS +=  -I.
EXTRA_CFLAGS += $(MODFLAGS)
EXTRA_CFLAGS += -DUSE_SCHEDULER

ifeq ($(CONFIG_SCSI_LPFC_IOCTLS),)
 EXTRA_CFLAGS += -I$(BASEINCLUDE)/drivers/scsi
endif

ifdef INC_TOP
 EXTRA_CFLAGS += -I$(INC_TOP)
else
ifdef STANDALONE
 EXTRA_CFLAGS += -I/lib/modules/$(KERNELVERSION)/build/drivers/addon/lpfc/
else
 EXTRA_CFLAGS += -I../
endif
endif

ifneq ($(CONFIG_SCSI_LPFC_IOCTLS),)
 obj-$(CONFIG_SCSI_LPFC_IOCTLS) += lpfcdfc.o
 MOD_DESTDIR = $(shell cd .. && $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh)
 include $(TOPDIR)/Rules.make
endif

lpfcdfc.o: $(lpfcdfc-objs)
	$(LD) -r -o $@ $(lpfcdfc-objs)

clean:
	rm -f *.o
